[Scummvm-git-logs] scummvm master -> 8150c720d3b24fbc5b69fc87d8642a8b9586723d

sev- noreply at scummvm.org
Wed Aug 9 16:15:47 UTC 2023


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
b90efbe47c COMMON: Handle writing failed in dumpArchive when not enough storage
8150c720d3 COMMON: DumpArchive(): add check to skip directory, return error if a file cannot be opened


Commit: b90efbe47c4505f69ee69e53d6dd45bf3b13dd83
    https://github.com/scummvm/scummvm/commit/b90efbe47c4505f69ee69e53d6dd45bf3b13dd83
Author: Ankush Dutt (ankushd100 at gmail.com)
Date: 2023-08-09T18:15:43+02:00

Commit Message:
COMMON: Handle writing failed in dumpArchive when not enough storage

Changed paths:
    common/archive.cpp
    common/archive.h


diff --git a/common/archive.cpp b/common/archive.cpp
index 227ca060ca0..c0f64ec7702 100644
--- a/common/archive.cpp
+++ b/common/archive.cpp
@@ -80,7 +80,7 @@ int Archive::listMatchingMembers(ArchiveMemberList &list, const Path &pattern, b
 	return matches;
 }
 
-void Archive::dumpArchive(String destPath) {
+Common::Error Archive::dumpArchive(String destPath) {
 	Common::ArchiveMemberList files;
 
 	listMembers(files);
@@ -91,6 +91,7 @@ void Archive::dumpArchive(String destPath) {
 	for (auto &f : files) {
 		Common::Path filePath = f->getPathInArchive().punycodeEncode();
 		debug(1, "File: %s", filePath.toString().c_str());
+
 		Common::SeekableReadStream *stream = f->createReadStream();
 
 		uint32 len = stream->size();
@@ -107,7 +108,14 @@ void Archive::dumpArchive(String destPath) {
 		if (!out.open(outPath.toString(), true)) {
 			warning("Archive::dumpArchive(): Can not open dump file %s", outPath.toString().c_str());
 		} else {
-			out.write(data, len);
+			uint32 writtenBytes = out.write(data, len);
+			if (writtenBytes < len) {
+				// Not all data was written
+				out.close();
+				delete stream;
+				free(data);
+				return Common::Error(Common::kWritingFailed, "Not enough storage space! Please free up some storage and try again");
+			}
 			out.flush();
 			out.close();
 		}
@@ -116,6 +124,7 @@ void Archive::dumpArchive(String destPath) {
 	}
 
 	free(data);
+	return Common::kNoError;
 }
 
 char Archive::getPathSeparator() const {
diff --git a/common/archive.h b/common/archive.h
index 868a9d029c0..6e6e1ab0bbd 100644
--- a/common/archive.h
+++ b/common/archive.h
@@ -29,6 +29,7 @@
 #include "common/hashmap.h"
 #include "common/hash-str.h"
 #include "common/singleton.h"
+#include "common/error.h"
 
 namespace Common {
 
@@ -168,7 +169,7 @@ public:
 	/**
 	 * Dump all files from the archive to the given directory
 	 */
-	void dumpArchive(String destPath);
+	Common::Error dumpArchive(String destPath);
 
 	/**
 	 * Returns the separator used by internal paths in the archive


Commit: 8150c720d3b24fbc5b69fc87d8642a8b9586723d
    https://github.com/scummvm/scummvm/commit/8150c720d3b24fbc5b69fc87d8642a8b9586723d
Author: Ankush Dutt (ankushd100 at gmail.com)
Date: 2023-08-09T18:15:43+02:00

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

Changed paths:
    common/archive.cpp


diff --git a/common/archive.cpp b/common/archive.cpp
index c0f64ec7702..79b935180f6 100644
--- a/common/archive.cpp
+++ b/common/archive.cpp
@@ -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) {




More information about the Scummvm-git-logs mailing list