COMMON: DumpArchive(): add check to skip directory, return error if a file cannot be opened

This commit is contained in:
Ankush Dutt 2023-08-09 16:15:43 +05:30 committed by Eugene Sandulenko
parent b90efbe47c
commit 8150c720d3

View File

@ -92,6 +92,9 @@ Common::Error Archive::dumpArchive(String destPath) {
Common::Path filePath = f->getPathInArchive().punycodeEncode();
debug(1, "File: %s", filePath.toString().c_str());
// skip if f represents a directory
if (filePath.toString().lastChar() == '/') continue;
Common::SeekableReadStream *stream = f->createReadStream();
uint32 len = stream->size();
@ -106,7 +109,7 @@ Common::Error Archive::dumpArchive(String destPath) {
Common::DumpFile out;
Common::Path outPath = Common::Path(destPath).join(filePath);
if (!out.open(outPath.toString(), true)) {
warning("Archive::dumpArchive(): Can not open dump file %s", outPath.toString().c_str());
return Common::Error(Common::kCreatingFileFailed, "Cannot open/create dump file " + outPath.toString());
} else {
uint32 writtenBytes = out.write(data, len);
if (writtenBytes < len) {