Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: provide an overwrite mode when decompressing the file #116

Closed
1 task done
xiaohuohumax opened this issue Dec 15, 2022 · 1 comment
Closed
1 task done
Assignees
Milestone

Comments

@xiaohuohumax
Copy link

Feature description

Hi !

english is not good. excuse me 😅.

bit7z version:

v4.0.0-beta

my code:

Bit7zLibrary lib{ "./7z.dll" };
BitFileExtractor ext{ lib, BitFormat::Auto };
// close RetainDirectories
ext.setRetainDirectories(false);

ext.extract("test.zip", "d:/test");

my zip structure

// test.zip
test
 ├── 1.txt
 └── 1f
     ├── 1.txt
     └── 2f
         └── 1.txt

unzip result (files with the same name will be overwritten)

1.txt

i find in resource code (fileextractcallback.cpp => getOutStream)

// ...
if (fs::exists(mFilePathOnDisk, ec) && !fs::remove(mFilePathOnDisk, ec)) {
  mErrorMessage = kCannotDeleteOutput;
  return E_ABORT;
 }
// ...

7zip commands (7z.exe e -ao[a | s | t | u ])

when I use this library, I can't find a way to set the override mode. Is there any way?

Thanks! 👍💕

Additional context

enum struct OverwriteMode {
    Overwrite = 0,
    Skip,
    RenameExtract,
    RenameExist
};

BitFileExtractor ext{ lib, BitFormat::Auto };
ext.setOverwriteMode(OverwriteMode::Overwrite);

Code of Conduct

@rikyoz
Copy link
Owner

rikyoz commented Dec 15, 2022

Hi!

english is not good. excuse me 😅.

Mine too, no problem! :D

I can't find a way to set the override mode. Is there any way?

Unfortunately, there's no direct way to set it, at least for now.

I think that OverwriteMode::RenameExist might be achievable by using BitFileExtractor's fileCallback:

ext.setFileCallback( []( const string& path ) {
   auto full_path = output_path + "/" + path;
   // You might emulate OverwriteMode::RenameExist by checking if full_path exists,
   // and in case, rename it.
   // The file callback is called before the overwrite code.
}

I will definitely implement such a feature as soon as possible, but it will require quite a bit of refactoring of the library's internal code, so I'm not sure it will make it into the stable v4.0.
Anyway, thank you for your suggestion!

rikyoz added a commit that referenced this issue Dec 20, 2022
@rikyoz rikyoz added this to the v4.0 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants