1
0
forked from 0ad/0ad

safely handle the case where an archive required for populating a directory cannot be opened (e.g. because it is open within 7-zip, which apparently wants exclusive access)

fixes #1021

This was SVN commit r10631.
This commit is contained in:
janwas 2011-11-29 16:51:58 +00:00
parent b54ad51054
commit 24aa71b566
3 changed files with 27 additions and 3 deletions

View File

@ -568,7 +568,14 @@ private:
PIArchiveReader CreateArchiveReader_Zip(const OsPath& archivePathname)
{
return PIArchiveReader(new ArchiveReader_Zip(archivePathname));
try
{
return PIArchiveReader(new ArchiveReader_Zip(archivePathname));
}
catch(Status)
{
return PIArchiveReader();
}
}
@ -737,5 +744,12 @@ private:
PIArchiveWriter CreateArchiveWriter_Zip(const OsPath& archivePathname, bool noDeflate)
{
return PIArchiveWriter(new ArchiveWriter_Zip(archivePathname, noDeflate));
try
{
return PIArchiveWriter(new ArchiveWriter_Zip(archivePathname, noDeflate));
}
catch(Status)
{
return PIArchiveWriter();
}
}

View File

@ -29,7 +29,14 @@
#include "lib/file/archive/archive.h"
/**
* @return 0 if opening the archive failed (e.g. because an external program is holding on to it)
**/
LIB_API PIArchiveReader CreateArchiveReader_Zip(const OsPath& archivePathname);
/**
* @return 0 if opening the archive failed (e.g. because an external program is holding on to it)
**/
LIB_API PIArchiveWriter CreateArchiveWriter_Zip(const OsPath& archivePathname, bool noDeflate);
#endif // #ifndef INCLUDED_ARCHIVE_ZIP

View File

@ -141,7 +141,10 @@ private:
if(pathname.Extension() == L".zip")
{
PIArchiveReader archiveReader = CreateArchiveReader_Zip(pathname);
RETURN_STATUS_IF_ERR(archiveReader->ReadEntries(AddArchiveFile, (uintptr_t)this));
// archiveReader == nullptr if file could not be opened (e.g. because
// archive is currently open in another program)
if(archiveReader)
RETURN_STATUS_IF_ERR(archiveReader->ReadEntries(AddArchiveFile, (uintptr_t)this));
}
else // regular (non-archive) file
AddFile(files[i]);