BACKENDS: Add overloadable removeFile in DefaultSaveFileManager

This allows using the DefaultSaveFileManager on system where
remove() does not exist. See bug #12975.
This commit is contained in:
Thierry Crozat 2021-10-04 21:12:01 +01:00 committed by Filippos Karapetis
parent 08f29237ed
commit aac0f40d2c
2 changed files with 21 additions and 13 deletions

View File

@ -205,23 +205,25 @@ bool DefaultSaveFileManager::removeSavefile(const Common::String &filename) {
_saveFileCache.erase(file);
file = _saveFileCache.end();
// FIXME: remove does not exist on all systems. If your port fails to
// compile because of this, please let us know (scummvm-devel).
// There is a nicely portable workaround, too: Make this method overloadable.
if (remove(fileNode.getPath().c_str()) != 0) {
if (errno == EACCES)
setError(Common::kWritePermissionDenied, "Search or write permission denied: "+fileNode.getName());
if (errno == ENOENT)
setError(Common::kPathDoesNotExist, "removeSavefile: '"+fileNode.getName()+"' does not exist or path is invalid");
return false;
} else {
Common::ErrorCode result = removeFile(fileNode.getPath());
if (result == Common::kNoError)
return true;
}
Common::Error error(result);
setError(error, "Failed to remove savefile '" + fileNode.getName() + "': " + error.getDesc());
return false;
}
}
Common::ErrorCode DefaultSaveFileManager::removeFile(const Common::String &filepath) {
if (remove(filepath.c_str()) == 0)
return Common::kNoError;
if (errno == EACCES)
return Common::kWritePermissionDenied;
if (errno == ENOENT)
return Common::kPathDoesNotExist;
return Common::kUnknownError;
}
bool DefaultSaveFileManager::exists(const Common::String &filename) {
// Assure the savefile name cache is up-to-date.
assureCached(getSavePath());

View File

@ -71,6 +71,12 @@ protected:
*/
virtual void checkPath(const Common::FSNode &dir);
/**
* Removes the given file.
* This is called from removeSavefile() with the full file path.
*/
virtual Common::ErrorCode removeFile(const Common::String &filepath);
/**
* Assure that the given save path is cached.
*