From 1dc13a641dd82825334e81bb3eb3b4ebd69d2552 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sat, 18 Aug 2007 05:24:18 +0000 Subject: Merged some of the changes from the trunk patch back in to the GSoC fsnode branch. svn-id: r28649 --- backends/fs/abstract-fs.h | 36 ++++++++++++++++++++++++++++++++---- backends/fs/dc/dc-fs.cpp | 2 +- backends/fs/posix/posix-fs.cpp | 37 ++++++++++++++----------------------- 3 files changed, 47 insertions(+), 28 deletions(-) (limited to 'backends/fs') diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h index 85fcbcdebb..e506d96a0b 100644 --- a/backends/fs/abstract-fs.h +++ b/backends/fs/abstract-fs.h @@ -79,7 +79,7 @@ public: virtual ~AbstractFilesystemNode() {} /* - * Indicates whether the object refered by this path exists in the filesystem or not. + * Indicates whether the object referred by this path exists in the filesystem or not. */ virtual bool exists() const = 0; @@ -102,6 +102,18 @@ public: */ virtual String getDisplayName() const { return getName(); } + /** + * Returns the last component of a given path. + * + * Examples: + * /foo/bar.txt would return /bar.txt + * /foo/bar/ would return /bar/ + * + * @param str String containing the path. + * @return Pointer to the first char of the last component inside str. + */ + virtual const char *getLastPathComponent(const Common::String &str) const = 0; + /** * Returns a string with an architecture dependent path description. */ @@ -118,12 +130,28 @@ public: virtual bool isDirectory() const = 0; /** - * Indicates whether this path can be read from or not. + * Indicates whether the object referred by this path can be read from or not. + * + * If the path refers to a directory, readability implies being able to read + * and list the directory entries. + * + * If the path refers to a file, readability implies being able to read the + * contents of the file. + * + * @return bool true if the object can be read, false otherwise. */ virtual bool isReadable() const = 0; /** - * Indicates whether this path can be written to or not. + * Indicates whether the object referred by this path can be written to or not. + * + * If the path refers to a directory, writability implies being able to modify + * the directory entry (i.e. rename the directory, remove it or write files inside of it). + * + * If the path refers to a file, writability implies being able to write data + * to the file. + * + * @return bool true if the object can be written to, false otherwise. */ virtual bool isWritable() const = 0; @@ -132,4 +160,4 @@ public: */ }; -#endif +#endif //BACKENDS_ABSTRACT_FS_H diff --git a/backends/fs/dc/dc-fs.cpp b/backends/fs/dc/dc-fs.cpp index e1228c7ff2..6554544c7f 100644 --- a/backends/fs/dc/dc-fs.cpp +++ b/backends/fs/dc/dc-fs.cpp @@ -32,7 +32,7 @@ #include /** - * Implementation of the ScummVM file system API based on POSIX. + * Implementation of the ScummVM file system API based on Ronin. * * Parts of this class are documented in the base interface class, AbstractFilesystemNode. */ diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index 3708acd2a8..9fd5b8a185 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -64,6 +64,7 @@ public: virtual bool exists() const { return access(_path.c_str(), F_OK) == 0; } virtual String getDisplayName() const { return _displayName; } + virtual const char *getLastPathComponent(const Common::String &str) const; virtual String getName() const { return _displayName; } virtual String getPath() const { return _path; } virtual bool isDirectory() const { return _isDirectory; } @@ -81,27 +82,6 @@ private: virtual void setFlags(); }; -/** - * Returns the last component of a given path. - * - * Examples: - * /foo/bar.txt would return /bar.txt - * /foo/bar/ would return /bar/ - * - * @param str String containing the path. - * @return Pointer to the first char of the last component inside str. - */ -static const char *lastPathComponent(const Common::String &str) { - const char *start = str.c_str(); - const char *cur = start + str.size() - 2; - - while (cur >= start && *cur != '/') { - --cur; - } - - return cur + 1; -} - void POSIXFilesystemNode::setFlags() { struct stat st; @@ -142,7 +122,7 @@ POSIXFilesystemNode::POSIXFilesystemNode(const String &p, bool verify) { assert(p.size() > 0); _path = p; - _displayName = lastPathComponent(_path); + _displayName = getLastPathComponent(_path); if (verify) { setFlags(); @@ -236,12 +216,23 @@ bool POSIXFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, boo return true; } +const char *POSIXFilesystemNode::getLastPathComponent(const Common::String &str) const { + const char *start = str.c_str(); + const char *cur = start + str.size() - 2; + + while (cur >= start && *cur != '/') { + --cur; + } + + return cur + 1; +} + AbstractFilesystemNode *POSIXFilesystemNode::getParent() const { if (_path == "/") return 0; const char *start = _path.c_str(); - const char *end = lastPathComponent(_path); + const char *end = getLastPathComponent(_path); return new POSIXFilesystemNode(String(start, end - start), true); } -- cgit v1.2.3