Skip to content
Permalink
Browse files

POSIX: Remove POSIX-specific checkPath function

  • Loading branch information...
ccawley2011 authored and bluegr committed Aug 11, 2019
1 parent 0069281 commit 7311252d8abbb736abcf1d01019d9ad572c95e2c
Showing with 0 additions and 76 deletions.
  1. +0 −68 backends/saves/posix/posix-saves.cpp
  2. +0 −8 backends/saves/posix/posix-saves.h
@@ -38,9 +38,6 @@
#include "common/savefile.h"
#include "common/textconsole.h"

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>

POSIXSaveFileManager::POSIXSaveFileManager() {
@@ -133,69 +130,4 @@ POSIXSaveFileManager::POSIXSaveFileManager() {
#endif
}

void POSIXSaveFileManager::checkPath(const Common::FSNode &dir) {
const Common::String path = dir.getPath();
clearError();

struct stat sb;

// Check whether the dir exists
if (stat(path.c_str(), &sb) == -1) {
// The dir does not exist, or stat failed for some other reason.
// If the problem was that the path pointed to nothing, try
// to create the dir (ENOENT case).
switch (errno) {
case EACCES:
setError(Common::kWritePermissionDenied, "Search or write permission denied: "+path);
break;
case ELOOP:
setError(Common::kUnknownError, "Too many symbolic links encountered while traversing the path: "+path);
break;
case ENAMETOOLONG:
setError(Common::kUnknownError, "The path name is too long: "+path);
break;
case ENOENT:
if (mkdir(path.c_str(), 0755) != 0) {
// mkdir could fail for various reasons: The parent dir doesn't exist,
// or is not writeable, the path could be completly bogus, etc.
warning("mkdir for '%s' failed", path.c_str());
perror("mkdir");

switch (errno) {
case EACCES:
setError(Common::kWritePermissionDenied, "Search or write permission denied: "+path);
break;
case EMLINK:
setError(Common::kUnknownError, "The link count of the parent directory would exceed {LINK_MAX}: "+path);
break;
case ELOOP:
setError(Common::kUnknownError, "Too many symbolic links encountered while traversing the path: "+path);
break;
case ENAMETOOLONG:
setError(Common::kUnknownError, "The path name is too long: "+path);
break;
case ENOENT:
setError(Common::kPathDoesNotExist, "A component of the path does not exist, or the path is an empty string: "+path);
break;
case ENOTDIR:
setError(Common::kPathDoesNotExist, "A component of the path prefix is not a directory: "+path);
break;
case EROFS:
setError(Common::kWritePermissionDenied, "The parent directory resides on a read-only file system:"+path);
break;
}
}
break;
case ENOTDIR:
setError(Common::kPathDoesNotExist, "A component of the path prefix is not a directory: "+path);
break;
}
} else {
// So stat() succeeded. But is the path actually pointing to a directory?
if (!S_ISDIR(sb.st_mode)) {
setError(Common::kPathDoesNotExist, "The given savepath is not a directory: "+path);
}
}
}

#endif
@@ -35,14 +35,6 @@
class POSIXSaveFileManager : public DefaultSaveFileManager {
public:
POSIXSaveFileManager();

protected:
/**
* Checks the given path for read access, existence, etc.
* In addition, tries to create a missing savedir, if possible.
* Sets the internal error and error message accordingly.
*/
virtual void checkPath(const Common::FSNode &dir);
};
#endif

0 comments on commit 7311252

Please sign in to comment.
You can’t perform that action at this time.