aboutsummaryrefslogtreecommitdiff
path: root/backends/fs
diff options
context:
space:
mode:
Diffstat (limited to 'backends/fs')
-rw-r--r--backends/fs/amigaos4/amigaos4-fs.cpp5
-rw-r--r--backends/fs/fs.cpp28
-rw-r--r--backends/fs/fs.h57
-rw-r--r--backends/fs/morphos/abox-fs.cpp5
-rw-r--r--backends/fs/palmos/palmos-fs.cpp6
-rw-r--r--backends/fs/posix/posix-fs.cpp32
-rw-r--r--backends/fs/ps2/ps2-fs.cpp6
-rw-r--r--backends/fs/symbian/symbian-fs.cpp5
-rw-r--r--backends/fs/windows/windows-fs.cpp5
9 files changed, 131 insertions, 18 deletions
diff --git a/backends/fs/amigaos4/amigaos4-fs.cpp b/backends/fs/amigaos4/amigaos4-fs.cpp
index f90e6ea6a9..d98b64f381 100644
--- a/backends/fs/amigaos4/amigaos4-fs.cpp
+++ b/backends/fs/amigaos4/amigaos4-fs.cpp
@@ -71,6 +71,7 @@ class AmigaOSFilesystemNode : public AbstractFilesystemNode {
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
virtual FSList listVolumes(void) const;
virtual AbstractFilesystemNode *parent() const;
+ virtual AbstractFilesystemNode *child(const String &name) const;
};
AbstractFilesystemNode *FilesystemNode::getRoot() {
@@ -323,6 +324,10 @@ AbstractFilesystemNode *AmigaOSFilesystemNode::parent() const {
return node;
}
+AbstractFilesystemNode *AmigaOSFilesystemNode::child(const String &name) const {
+ TODO
+}
+
FSList AmigaOSFilesystemNode::listVolumes(void) const {
ENTER();
diff --git a/backends/fs/fs.cpp b/backends/fs/fs.cpp
index 445bea8efe..4907e78ee6 100644
--- a/backends/fs/fs.cpp
+++ b/backends/fs/fs.cpp
@@ -84,6 +84,9 @@ FilesystemNode &FilesystemNode::operator =(const FilesystemNode &node) {
}
FilesystemNode FilesystemNode::getParent() const {
+ if (_realNode == 0)
+ return *this;
+
AbstractFilesystemNode *node = _realNode->parent();
if (node == 0) {
return *this;
@@ -92,22 +95,39 @@ FilesystemNode FilesystemNode::getParent() const {
}
}
+FilesystemNode FilesystemNode::getChild(const String &name) const {
+ if (_realNode == 0)
+ return *this;
+
+ assert(_realNode->isDirectory());
+ AbstractFilesystemNode *node = _realNode->child(name);
+ return AbstractFilesystemNode::wrap(node);
+}
+
+FSList FilesystemNode::listDir(ListMode mode) const {
+ assert(_realNode);
+ assert(_realNode->isDirectory());
+ return _realNode->listDir(mode);
+}
+
Common::String FilesystemNode::displayName() const {
+ assert(_realNode);
return _realNode->displayName();
}
bool FilesystemNode::isValid() const {
+ if (_realNode == 0)
+ return false;
return _realNode->isValid();
}
bool FilesystemNode::isDirectory() const {
+ if (_realNode == 0)
+ return false;
return _realNode->isDirectory();
}
Common::String FilesystemNode::path() const {
+ assert(_realNode);
return _realNode->path();
}
-
-FSList FilesystemNode::listDir(ListMode mode) const {
- return _realNode->listDir(mode);
-}
diff --git a/backends/fs/fs.h b/backends/fs/fs.h
index 0c9d94e782..1e3696696e 100644
--- a/backends/fs/fs.h
+++ b/backends/fs/fs.h
@@ -81,6 +81,13 @@ protected:
virtual AbstractFilesystemNode *parent() const = 0;
/**
+ * The child node with the given name. If no child with this name
+ * exists, returns 0. Will never be called on a node which is not
+ * a directory node.
+ */
+ virtual AbstractFilesystemNode *child(const String &name) const = 0;
+
+ /**
* This method is a rather ugly hack which is used internally by the
* actual node implementions to wrap up raw nodes inside FilesystemNode
* objects. We probably want to get rid of this eventually and replace it
@@ -104,29 +111,45 @@ public:
virtual ~AbstractFilesystemNode() {}
/**
- * Return display name, used by e.g. the GUI to present the file in the file browser.
+ * Return a human readable string for this node, usable for display (e.g.
+ * in the GUI code). Do *not* rely on it being usable for anything else,
+ * like constructing paths!
* @return the display name
*/
virtual String displayName() const = 0;
/**
- * Is this node valid (i.e. referring to an actual FS object)?
+ * Is this node valid? Returns true if the file/directory pointed
+ * to by this node exists, false otherwise.
+ *
+ * @todo Maybe rename this to exists() ? Or maybe even distinguish between
+ * the two? E.g. a path may be non-existant but valid, while another might
+ * be completely invalid). But do we ever need to make that distinction?
*/
virtual bool isValid() const = 0;
/**
- * Is this node a directory or not?
+ * Is this node pointing to a directory?
+ * @todo Currently we assume that a valid node that is not a directory
+ * automatically is a file (ignoring things like symlinks). That might
+ * actually be OK... but we could still add an isFile method. Or even replace
+ * isValid and isDirectory by a getType() method that can return values like
+ * kDirNodeType, kFileNodeType, kInvalidNodeType.
*/
virtual bool isDirectory() const = 0;
/**
- * A path representation suitable for use with fopen()
+ * Return a string representation of the file which can be passed to fopen(),
+ * and is suitable for archiving (i.e. writing to the config file).
+ * This will usually be a 'path' (hence the name of the method), but can
+ * be anything that fulfilly the above criterions.
*/
virtual String path() const = 0;
/**
- * List the content of this directory node.
- * If this node is not a directory, throw an exception or call error().
+ * Return a list of child nodes of this directory node. If called
+ * on a node that does not represent a directory, an error is triggered.
+ * @todo Rename this to listChildren.
*/
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const = 0;
@@ -189,27 +212,43 @@ private:
public:
+ /**
+ * Create a new FilesystemNode refering to the specified path. This is
+ * the counterpart to the path() method.
+ */
+ FilesystemNode(const String &path);
+
+
FilesystemNode();
FilesystemNode(const FilesystemNode &node);
- FilesystemNode(const String &path);
~FilesystemNode();
FilesystemNode &operator =(const FilesystemNode &node);
+ /**
+ * Get the parent node of this node. If this node has no parent node,
+ * then it returns a duplicate of this node.
+ */
FilesystemNode getParent() const;
+ /**
+ * Fetch a child node of this node, with the given name. Only valid for
+ * directory nodes (an assertion is triggered otherwise). If no no child
+ * node with the given name exists, an invalid node is returned.
+ */
+ FilesystemNode getChild(const String &name) const;
+ virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
virtual String displayName() const;
virtual bool isValid() const;
virtual bool isDirectory() const;
virtual String path() const;
- virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
-
protected:
void decRefCount();
virtual AbstractFilesystemNode *parent() const { return 0; }
+ virtual AbstractFilesystemNode *child(const String &name) const { return 0; }
};
diff --git a/backends/fs/morphos/abox-fs.cpp b/backends/fs/morphos/abox-fs.cpp
index d3954cebe6..c4cd89d438 100644
--- a/backends/fs/morphos/abox-fs.cpp
+++ b/backends/fs/morphos/abox-fs.cpp
@@ -53,6 +53,7 @@ class ABoxFilesystemNode : public AbstractFilesystemNode {
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
static FSList listRoot();
virtual AbstractFilesystemNode *parent() const;
+ virtual AbstractFilesystemNode *child(const String &name) const;
};
@@ -212,6 +213,10 @@ AbstractFilesystemNode *ABoxFilesystemNode::parent() const
return node;
}
+AbstractFilesystemNode *ABoxFilesystemNode::child(const String &name) const {
+ TODO
+}
+
FSList ABoxFilesystemNode::listRoot()
{
FSList myList;
diff --git a/backends/fs/palmos/palmos-fs.cpp b/backends/fs/palmos/palmos-fs.cpp
index 2cd2b283aa..144165e903 100644
--- a/backends/fs/palmos/palmos-fs.cpp
+++ b/backends/fs/palmos/palmos-fs.cpp
@@ -50,6 +50,7 @@ public:
virtual FSList listDir(ListMode) const;
virtual AbstractFilesystemNode *parent() const;
+ virtual AbstractFilesystemNode *child(const String &name) const;
private:
static void addFile (FSList &list, ListMode mode, const Char *base, FileInfoType* find_data);
@@ -170,4 +171,9 @@ AbstractFilesystemNode *PalmOSFilesystemNode::parent() const {
return p;
}
+
+AbstractFilesystemNode *PalmOSFilesystemNode::child(const String &name) const {
+ TODO
+}
+
#endif // PALMOS_MODE
diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp
index 081325beba..e4b6b9ffa1 100644
--- a/backends/fs/posix/posix-fs.cpp
+++ b/backends/fs/posix/posix-fs.cpp
@@ -49,7 +49,7 @@ protected:
public:
POSIXFilesystemNode();
- POSIXFilesystemNode(const String &path, bool useStat = false);
+ POSIXFilesystemNode(const String &path, bool verify = false);
virtual String displayName() const { return _displayName; }
virtual bool isValid() const { return _isValid; }
@@ -58,6 +58,7 @@ public:
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
virtual AbstractFilesystemNode *parent() const;
+ virtual AbstractFilesystemNode *child(const String &name) const;
};
@@ -103,7 +104,7 @@ POSIXFilesystemNode::POSIXFilesystemNode() {
_isDirectory = true;
}
-POSIXFilesystemNode::POSIXFilesystemNode(const String &p, bool useStat) {
+POSIXFilesystemNode::POSIXFilesystemNode(const String &p, bool verify) {
assert(p.size() > 0);
_path = p;
@@ -111,13 +112,21 @@ POSIXFilesystemNode::POSIXFilesystemNode(const String &p, bool useStat) {
_isValid = true;
_isDirectory = true;
-#ifndef __DC__
- if (useStat) {
+ if (verify) {
+#ifdef __DC__
+ FIXME;
+ /*
+ FIXME: Is there really no way to at least verify the path is valid?
+ Or is it too slow, or what? Please clarify with a comment here.
+ (Of course we could just fopen here, but that wouldn't be able to deal
+ with directories...
+ */
+#else
struct stat st;
_isValid = (0 == stat(_path.c_str(), &st));
_isDirectory = S_ISDIR(st.st_mode);
- }
#endif
+ }
}
FSList POSIXFilesystemNode::listDir(ListMode mode) const {
@@ -200,4 +209,17 @@ AbstractFilesystemNode *POSIXFilesystemNode::parent() const {
return p;
}
+AbstractFilesystemNode *POSIXFilesystemNode::child(const String &name) const {
+ // FIXME: Pretty lame implementation! We do no error checking to speak
+ // of, do not check if this is a special node, etc.
+ assert(_isDirectory);
+ String newPath(_path);
+ if (_path.lastChar() != '/')
+ newPath += '/';
+ newPath += name;
+ POSIXFilesystemNode *p = new POSIXFilesystemNode(newPath, true);
+
+ return p;
+}
+
#endif // defined(UNIX)
diff --git a/backends/fs/ps2/ps2-fs.cpp b/backends/fs/ps2/ps2-fs.cpp
index a12fd99664..7630dec653 100644
--- a/backends/fs/ps2/ps2-fs.cpp
+++ b/backends/fs/ps2/ps2-fs.cpp
@@ -45,6 +45,8 @@ public:
virtual FSList listDir(ListMode) const;
virtual AbstractFilesystemNode *parent() const;
+ virtual AbstractFilesystemNode *child(const String &name) const;
+
virtual AbstractFilesystemNode *clone() const { return new Ps2FilesystemNode(this); }
};
@@ -135,3 +137,7 @@ AbstractFilesystemNode *Ps2FilesystemNode::parent() const {
return p;
}
+
+AbstractFilesystemNode *Ps2FilesystemNode::child(const String &name) const {
+ TODO
+}
diff --git a/backends/fs/symbian/symbian-fs.cpp b/backends/fs/symbian/symbian-fs.cpp
index 30439e0cdc..a236e10ca6 100644
--- a/backends/fs/symbian/symbian-fs.cpp
+++ b/backends/fs/symbian/symbian-fs.cpp
@@ -52,6 +52,7 @@ public:
virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
virtual AbstractFilesystemNode *parent() const;
+ virtual AbstractFilesystemNode *child(const String &name) const;
};
@@ -198,4 +199,8 @@ AbstractFilesystemNode *SymbianFilesystemNode::parent() const {
return p;
}
+AbstractFilesystemNode *SymbianFilesystemNode::child(const String &name) const {
+ TODO
+}
+
#endif // defined(__SYMBIAN32__)
diff --git a/backends/fs/windows/windows-fs.cpp b/backends/fs/windows/windows-fs.cpp
index d179ad0708..dc9be3667b 100644
--- a/backends/fs/windows/windows-fs.cpp
+++ b/backends/fs/windows/windows-fs.cpp
@@ -51,6 +51,7 @@ public:
virtual FSList listDir(ListMode) const;
virtual AbstractFilesystemNode *parent() const;
+ virtual AbstractFilesystemNode *child(const String &name) const;
private:
static char *toAscii(TCHAR *x);
@@ -228,4 +229,8 @@ AbstractFilesystemNode *WindowsFilesystemNode::parent() const {
return p;
}
+AbstractFilesystemNode *WindowsFilesystemNode::child(const String &name) const {
+ TODO
+}
+
#endif // WIN32