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.
This commit is contained in:
Alexander Tkachev 2016-05-25 16:32:22 +06:00
parent d014b5bf38
commit ae8e7f39f5
8 changed files with 87 additions and 6 deletions

View file

@ -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) {