diff options
author | Alexander Tkachev | 2016-05-25 16:32:22 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | ae8e7f39f5b3e4f647a29d39d19cce7626528bb1 (patch) | |
tree | bf1031fbf6bedd96056b8a427f2bf647499b44e6 /backends/fs/posix | |
parent | d014b5bf3826d78de269891ccf6722e58d7a5bcd (diff) | |
download | scummvm-rg350-ae8e7f39f5b3e4f647a29d39d19cce7626528bb1.tar.gz scummvm-rg350-ae8e7f39f5b3e4f647a29d39d19cce7626528bb1.tar.bz2 scummvm-rg350-ae8e7f39f5b3e4f647a29d39d19cce7626528bb1.zip |
CLOUD: Make download() create necessary directories
DumpFile::open() with createPath=true create would create the missing
directories from the path before opening a file. Thus, one can easily
create a file and avoid "can't open a file" error.
Diffstat (limited to 'backends/fs/posix')
-rw-r--r-- | backends/fs/posix/posix-fs.cpp | 24 | ||||
-rw-r--r-- | backends/fs/posix/posix-fs.h | 1 |
2 files changed, 25 insertions, 0 deletions
diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 1a6c4e40a5..d388f306fd 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -252,6 +252,30 @@ Common::WriteStream *POSIXFilesystemNode::createWriteStream() { return StdioStream::makeFromPath(getPath(), true); } +bool POSIXFilesystemNode::create(bool isDirectory) { + bool success; + + if (isDirectory) { + success = mkdir(_path.c_str(), 0755) == 0; + } else { + success = creat(_path.c_str(), 0755) != -1; + } + + if (success) { + setFlags(); + if (_isValid) { + if (_isDirectory != isDirectory) warning("failed to create %s: got %s", isDirectory ? "directory" : "file", _isDirectory ? "directory" : "file"); + return _isDirectory == isDirectory; + } + + warning("POSIXFilesystemNode: %s() was a success, but stat indicates there is no such %s", + isDirectory ? "mkdir" : "creat", isDirectory ? "directory" : "file"); + return false; + } + + return false; +} + namespace Posix { bool assureDirectoryExists(const Common::String &dir, const char *prefix) { diff --git a/backends/fs/posix/posix-fs.h b/backends/fs/posix/posix-fs.h index 0703ac5bf5..4ebce7e9d9 100644 --- a/backends/fs/posix/posix-fs.h +++ b/backends/fs/posix/posix-fs.h @@ -73,6 +73,7 @@ public: virtual Common::SeekableReadStream *createReadStream(); virtual Common::WriteStream *createWriteStream(); + virtual bool create(bool isDirectory); private: /** |