From 63aec29edb3e6065e5b167058247fa4cc39adef7 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 22 Jul 2006 17:01:50 +0000 Subject: Added isValid to FilesystemNode and AbstractFilesystemNode. See my mail to -devel for more information. svn-id: r23567 --- common/file.cpp | 14 ++++++++++++-- common/fs.cpp | 6 ++++++ common/fs.h | 5 +++++ 3 files changed, 23 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/file.cpp b/common/file.cpp index f8e131a80e..da682037e8 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -277,6 +277,15 @@ bool File::open(const String &filename, AccessMode mode) { bool File::open(const FilesystemNode &node, AccessMode mode) { assert(mode == kFileReadMode || mode == kFileWriteMode); + + if (!node.isValid()) { + warning("File::open: Trying to open an invalid FilesystemNode object"); + return false; + } else if (node.isDirectory()) { + warning("File::open: Trying to open a FilesystemNode which is a directory"); + return false; + } + String filename(node.name()); if (_handle) { @@ -288,10 +297,8 @@ bool File::open(const FilesystemNode &node, AccessMode mode) { const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb"; - _handle = fopen(node.path().c_str(), modeStr); - if (_handle == NULL) { if (mode == kFileReadMode) debug(2, "File %s not found", filename.c_str()); @@ -313,6 +320,9 @@ 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()) return false; diff --git a/common/fs.cpp b/common/fs.cpp index 56d7eab49b..11d580436f 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -77,6 +77,12 @@ FilesystemNode &FilesystemNode::operator =(const FilesystemNode &node) { return *this; } +bool FilesystemNode::isValid() const { + if (_realNode == 0) + return false; + return _realNode->isValid(); +} + FilesystemNode FilesystemNode::getParent() const { if (_realNode == 0) return *this; diff --git a/common/fs.h b/common/fs.h index d18793f015..5d35c2581b 100644 --- a/common/fs.h +++ b/common/fs.h @@ -113,6 +113,11 @@ public: */ FilesystemNode &operator =(const FilesystemNode &node); + /** + * Checks if the FilesystemNode is valid for any usage + */ + bool isValid() const; + /** * Get the parent node of this node. If this node has no parent node, * then it returns a duplicate of this node. -- cgit v1.2.3