From f42108e63399f4329bb1cadfd2e21d808aea8a89 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Fri, 20 Jul 2007 19:42:38 +0000 Subject: 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 --- common/file.cpp | 40 ++++++++++++++++++++++++++++++++++------ common/file.h | 3 +++ 2 files changed, 37 insertions(+), 6 deletions(-) (limited to 'common') 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 +#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. * -- cgit v1.2.3