-
-
Notifications
You must be signed in to change notification settings - Fork 120
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
Access Denied exception in BitOutputArchive::compressToFile #231
Comments
Hi! BitArchiveReader reader(lib, archivePath, archiveFormat);
// do something with reader...
BitArchiveEditor editor(lib, archivePath, archiveFormat);
// do something with editor
editor.applyChanges(); // ERROR (cannot update the archive, as it is still opened by the reader).
{
BitArchiveReader reader(lib, archivePath, archiveFormat);
// do something with reader...
} // The reader goes out of scope, releasing the archive and allowing the editor to modify it.
BitArchiveEditor editor(lib, archivePath, archiveFormat);
// do something with editor
editor.applyChanges(); // OK. If this is not your case, I'll have to investigate it further. |
Many thanks for your reply. In my workflow I make 3 calls to the archive one after the other in succession.
if (createNewArchive)
{
if (fileExists(archivePath))
{
std::filesystem::remove(archivePath);
}
BitFileCompressor compressor(lib, archiveFormat);
if (!password.empty())
{
compressor.setPassword(password);
}
compressor.compress(fileMap, archivePath);
} Is there a way to simplify this logic - say only using one class i.e. either Thanks for your help 🙏 |
No problem!
In this particular case, you can just use Both classes have constructors for opening already existing archives. The only difference is that
In other words, your code can be simplified as follows: Bit7zLibrary lib(this->m_7ZipDllPath);
if (!fileExists(archivePath) && !createNewArchive)
{
createNewArchive = true;
}
const BitInOutFormat& archiveFormat = convertToBit7zArchiveFormat(this->m_ArchiveFormat);
if (createNewArchive && fileExists(archivePath)) // during project creation
{
std::filesystem::remove(archivePath);
}
BitArchiveWriter writer(lib, archivePath, archiveFormat);
if (!password.empty())
{
writer.setPassword(password);
}
writer.setUpdateMode(UpdateMode::Update);
writer.addFile(bytesInStreamToArchive, nameOfTheEntryInTheArchive);
writer.compressTo(archivePath); As for the random exceptions, I cannot find a possible explanation, at least reading your code. |
🙏 Many Thanks! I will adapt my code as per your suggestions. |
I have whole bunch of automated test for my application and some of them randomly throw this error.
If I try again e.g. via debugger, it works.
here is my calling code:
I don't see this error in my application (user actions), but only in the automated tests.
As a work around, I have introduced a 'retry' attempt in my application, where I call the same function again and it works.
Under what circumstances would the
rename()
fail?is the
out_stream.Release();
still 'holding on' to the handle somehow?Could there be another way of adding a 'stream' of bytes into the archive that might not exhibit this issue?
The text was updated successfully, but these errors were encountered: