diff options
author | David Corrales | 2007-07-20 19:42:38 +0000 |
---|---|---|
committer | David Corrales | 2007-07-20 19:42:38 +0000 |
commit | f42108e63399f4329bb1cadfd2e21d808aea8a89 (patch) | |
tree | 9abb044b4b4762f7f0f457a9c55900c766085f6d /common | |
parent | b95b3fe4f39dee9f46a522c05791628d085b2704 (diff) | |
download | scummvm-rg350-f42108e63399f4329bb1cadfd2e21d808aea8a89.tar.gz scummvm-rg350-f42108e63399f4329bb1cadfd2e21d808aea8a89.tar.bz2 scummvm-rg350-f42108e63399f4329bb1cadfd2e21d808aea8a89.zip |
Added a remove() function to the Common::File class. Also changed the exists() function to account for new capabilities in the FSNode layer.
svn-id: r28150
Diffstat (limited to 'common')
-rw-r--r-- | common/file.cpp | 40 | ||||
-rw-r--r-- | common/file.h | 3 |
2 files changed, 37 insertions, 6 deletions
diff --git a/common/file.cpp b/common/file.cpp index 238c3a4bb3..30ac870f05 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -29,6 +29,10 @@ #include "common/util.h" #include "common/hash-str.h" +#if defined(UNIX) || defined(__SYMBIAN32__) +#include <errno.h> +#endif + #ifdef MACOSX #include "CoreFoundation/CoreFoundation.h" #endif @@ -408,16 +412,40 @@ bool File::open(const FilesystemNode &node, AccessMode mode) { return true; } +bool File::remove(const String &filename){ + if (remove(filename.c_str()) != 0) { + if(errno == EACCES) + ;//TODO: read-only file + if(errno == ENOENT) + ;//TODO: non-existent file + + return false; + } else { + return true; + } +} + +bool File::remove(const FilesystemNode &node){ + if (remove(node.getPath()) != 0) { + if(errno == EACCES) + ;//TODO: read-only file + if(errno == ENOENT) + ;//TODO: non-existent file + + return false; + } else { + return true; + } +} + bool File::exists(const String &filename) { // First try to find the file it via a FilesystemNode (in case an absolute // path was passed). But we only use this to filter out directories. FilesystemNode file(filename); - // FIXME: can't use isValid() here since at the time of writing - // FilesystemNode is to be unable to find for example files - // added in extrapath - if (file.isDirectory() || !file.exists()) - return false; - + + return (!file.isDirectory() && file.exists()); + + //***DEPRECATED COMMENTS BELOW, LEFT FOR DISCUSSION*** // Next, try to locate the file by *opening* it in read mode. This has // multiple effects: // 1) It takes _filesMap and _defaultDirectories into consideration -> good diff --git a/common/file.h b/common/file.h index 3d816a6104..4d519be475 100644 --- a/common/file.h +++ b/common/file.h @@ -86,6 +86,9 @@ public: virtual void close(); + virtual bool remove(const String &filename); + virtual bool remove(const FilesystemNode &node); + /** * Checks if the object opened a file successfully. * |