[Scummvm-git-logs] scummvm master -> aca627bec7b407790d78a64df984344ff454c15b
bluegr
bluegr at gmail.com
Sun Aug 11 21:16:00 CEST 2019
This automated email contains information about 5 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
f1250dbfcb COMMON: Implement createDirectory() method to Common::FSNode
7553940792 COMMON: Add warnings on failed FSNode::createDirectory()
43b4528552 TESTBED: Add createDirectory() test in FStests
04c57babbc BACKENDS: Create the default save directory if it doesn't exist
aca627bec7 COMMON: Implement FSNode::createDirectoryRecursive()
Commit: f1250dbfcb4fe0c7431c9b928e9f12c2d16aadd2
https://github.com/scummvm/scummvm/commit/f1250dbfcb4fe0c7431c9b928e9f12c2d16aadd2
Author: lolbot-iichan (lolbot_iichan at mail.ru)
Date: 2019-08-11T22:15:54+03:00
Commit Message:
COMMON: Implement createDirectory() method to Common::FSNode
Added a simple wrapper for AbstractFSNode::create(true) since there was
no way to create directories.
Changed paths:
common/fs.cpp
common/fs.h
diff --git a/common/fs.cpp b/common/fs.cpp
index 54fdf89..4b3ab21 100644
--- a/common/fs.cpp
+++ b/common/fs.cpp
@@ -152,6 +152,17 @@ WriteStream *FSNode::createWriteStream() const {
return _realNode->createWriteStream();
}
+bool FSNode::createDirectory() const {
+ if (_realNode == nullptr)
+ return false;
+
+ if (_realNode->exists()) {
+ return false;
+ }
+
+ return _realNode->createDirectory();
+}
+
FSDirectory::FSDirectory(const FSNode &node, int depth, bool flat)
: _node(node), _cached(false), _depth(depth), _flat(flat) {
}
diff --git a/common/fs.h b/common/fs.h
index 6ff5c6e..7041428 100644
--- a/common/fs.h
+++ b/common/fs.h
@@ -230,6 +230,15 @@ public:
* @return pointer to the stream object, 0 in case of a failure
*/
WriteStream *createWriteStream() const;
+
+ /**
+ * Creates a directory referred by this node. This assumes that this
+ * node refers to non-existing directory. If this is not the case,
+ * false is returned.
+ *
+ * @return true if the directory was created, false otherwise.
+ */
+ bool createDirectory() const;
};
/**
Commit: 75539407921c660f06b80ed2e242372bee76c5dd
https://github.com/scummvm/scummvm/commit/75539407921c660f06b80ed2e242372bee76c5dd
Author: lolbot-iichan (lolbot_iichan at mail.ru)
Date: 2019-08-11T22:15:54+03:00
Commit Message:
COMMON: Add warnings on failed FSNode::createDirectory()
Changed paths:
common/fs.cpp
diff --git a/common/fs.cpp b/common/fs.cpp
index 4b3ab21..d27de48 100644
--- a/common/fs.cpp
+++ b/common/fs.cpp
@@ -157,6 +157,11 @@ bool FSNode::createDirectory() const {
return false;
if (_realNode->exists()) {
+ if (_realNode->isDirectory()) {
+ warning("FSNode::createDirectory: '%s' already exists", getName().c_str());
+ } else {
+ warning("FSNode::createDirectory: '%s' is a file", getName().c_str());
+ }
return false;
}
Commit: 43b4528552dc7b2a04abd31f88e1e83a726fc98b
https://github.com/scummvm/scummvm/commit/43b4528552dc7b2a04abd31f88e1e83a726fc98b
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2019-08-11T22:15:54+03:00
Commit Message:
TESTBED: Add createDirectory() test in FStests
Changed paths:
engines/testbed/fs.cpp
engines/testbed/fs.h
diff --git a/engines/testbed/fs.cpp b/engines/testbed/fs.cpp
index 07b1c0f..012581a 100644
--- a/engines/testbed/fs.cpp
+++ b/engines/testbed/fs.cpp
@@ -172,6 +172,35 @@ TestExitStatus FStests::testWriteFile() {
}
+/**
+ * This test creates a directory testbed.dir, and confirms if the directory is created successfully
+ */
+TestExitStatus FStests::testCreateDir() {
+ const Common::String &path = ConfMan.get("path");
+ Common::FSNode gameRoot(path);
+ if (!gameRoot.exists()) {
+ Testsuite::logPrintf("Couldn't open the game data directory %s", path.c_str());
+ return kTestFailed;
+ }
+
+ Common::FSNode dirToCreate = gameRoot.getChild("testbed.dir");
+
+ // TODO: Delete the directory after creating it
+ if (dirToCreate.exists()) {
+ Testsuite::logDetailedPrintf("Directory already exists in game data dir\n");
+ return kTestSkipped;
+ }
+
+ if (!dirToCreate.createDirectory()) {
+ Testsuite::logDetailedPrintf("Can't create directory in game data dir\n");
+ return kTestFailed;
+ }
+
+ Testsuite::logDetailedPrintf("Directory created successfully\n");
+ return kTestPassed;
+}
+
+
FSTestSuite::FSTestSuite() {
// FS tests depend on Game Data files.
@@ -187,6 +216,7 @@ FSTestSuite::FSTestSuite() {
}
addTest("ReadingFile", &FStests::testReadFile, false);
addTest("WritingFile", &FStests::testWriteFile, false);
+ addTest("CreateDir", &FStests::testCreateDir, false);
}
void FSTestSuite::enable(bool flag) {
diff --git a/engines/testbed/fs.h b/engines/testbed/fs.h
index 966f138..690e601 100644
--- a/engines/testbed/fs.h
+++ b/engines/testbed/fs.h
@@ -41,6 +41,7 @@ bool readDataFromFile(Common::FSDirectory *directory, const char *file);
// will contain function declarations for FS tests
TestExitStatus testReadFile();
TestExitStatus testWriteFile();
+TestExitStatus testCreateDir();
TestExitStatus testOpeningSaveFile();
// add more here
Commit: 04c57babbc06dfba33a5597a83e80c27c1ba6be9
https://github.com/scummvm/scummvm/commit/04c57babbc06dfba33a5597a83e80c27c1ba6be9
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2019-08-11T22:15:54+03:00
Commit Message:
BACKENDS: Create the default save directory if it doesn't exist
Changed paths:
backends/saves/default/default-saves.cpp
diff --git a/backends/saves/default/default-saves.cpp b/backends/saves/default/default-saves.cpp
index e9a4165..17e8881 100644
--- a/backends/saves/default/default-saves.cpp
+++ b/backends/saves/default/default-saves.cpp
@@ -63,7 +63,9 @@ DefaultSaveFileManager::DefaultSaveFileManager(const Common::String &defaultSave
void DefaultSaveFileManager::checkPath(const Common::FSNode &dir) {
clearError();
if (!dir.exists()) {
- setError(Common::kPathDoesNotExist, "The savepath '"+dir.getPath()+"' does not exist");
+ if (!dir.createDirectory()) {
+ setError(Common::kPathDoesNotExist, "Failed to create directory '"+dir.getPath()+"'");
+ }
} else if (!dir.isDirectory()) {
setError(Common::kPathNotDirectory, "The savepath '"+dir.getPath()+"' is not a directory");
}
Commit: aca627bec7b407790d78a64df984344ff454c15b
https://github.com/scummvm/scummvm/commit/aca627bec7b407790d78a64df984344ff454c15b
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2019-08-11T22:15:54+03:00
Commit Message:
COMMON: Implement FSNode::createDirectoryRecursive()
Changed paths:
backends/saves/default/default-saves.cpp
common/file.cpp
common/fs.cpp
common/fs.h
diff --git a/backends/saves/default/default-saves.cpp b/backends/saves/default/default-saves.cpp
index 17e8881..ee54557 100644
--- a/backends/saves/default/default-saves.cpp
+++ b/backends/saves/default/default-saves.cpp
@@ -63,7 +63,7 @@ DefaultSaveFileManager::DefaultSaveFileManager(const Common::String &defaultSave
void DefaultSaveFileManager::checkPath(const Common::FSNode &dir) {
clearError();
if (!dir.exists()) {
- if (!dir.createDirectory()) {
+ if (!dir.createDirectoryRecursive()) {
setError(Common::kPathDoesNotExist, "Failed to create directory '"+dir.getPath()+"'");
}
} else if (!dir.isDirectory()) {
diff --git a/common/file.cpp b/common/file.cpp
index 6228c66..12461b7 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -155,24 +155,10 @@ bool DumpFile::open(const String &filename, bool createPath) {
assert(!filename.empty());
assert(!_handle);
- if (createPath) {
- for (uint32 i = 0; i < filename.size(); ++i) {
- if (filename[i] == '/' || filename[i] == '\\') {
- Common::String subpath = filename;
- subpath.erase(i);
- if (subpath.empty()) continue;
- AbstractFSNode *node = g_system->getFilesystemFactory()->makeFileNodePath(subpath);
- if (node->exists()) {
- delete node;
- continue;
- }
- if (!node->createDirectory()) warning("DumpFile: unable to create directories from path prefix");
- delete node;
- }
- }
- }
-
FSNode node(filename);
+ if (createPath)
+ node.getParent().createDirectoryRecursive();
+
return open(node);
}
diff --git a/common/fs.cpp b/common/fs.cpp
index d27de48..2ba6409 100644
--- a/common/fs.cpp
+++ b/common/fs.cpp
@@ -168,6 +168,27 @@ bool FSNode::createDirectory() const {
return _realNode->createDirectory();
}
+bool FSNode::createDirectoryRecursive() const {
+ if (_realNode == nullptr)
+ return false;
+
+ if (_realNode->exists()) {
+ if (!_realNode->isDirectory()) {
+ warning("FSNode::createDirectoryRecursive: '%s' is a file", _realNode->getName().c_str());
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ FSNode parent = getParent();
+ assert(parent.getPath() != _realNode->getPath());
+ if (!parent.createDirectoryRecursive())
+ return false;
+
+ return _realNode->createDirectory();
+}
+
FSDirectory::FSDirectory(const FSNode &node, int depth, bool flat)
: _node(node), _cached(false), _depth(depth), _flat(flat) {
}
diff --git a/common/fs.h b/common/fs.h
index 7041428..e8c23f8 100644
--- a/common/fs.h
+++ b/common/fs.h
@@ -239,6 +239,14 @@ public:
* @return true if the directory was created, false otherwise.
*/
bool createDirectory() const;
+
+ /**
+ * Creates a directory referred by this node. The parent directory
+ * will also be created if it doesn't exist.
+ *
+ * @return true if the directory was created, false otherwise.
+ */
+ bool createDirectoryRecursive() const;
};
/**
More information about the Scummvm-git-logs
mailing list