aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/fs/fs.cpp9
-rw-r--r--backends/fs/fs.h11
-rw-r--r--backends/fs/morphos/abox-fs.cpp17
-rw-r--r--backends/fs/palmos/palmos-fs.cpp12
-rw-r--r--backends/fs/posix/posix-fs.cpp21
-rw-r--r--backends/fs/windows/windows-fs.cpp3
6 files changed, 41 insertions, 32 deletions
diff --git a/backends/fs/fs.cpp b/backends/fs/fs.cpp
index 1c9b7efe5d..e051e46c9a 100644
--- a/backends/fs/fs.cpp
+++ b/backends/fs/fs.cpp
@@ -72,7 +72,10 @@ FilesystemNode &FilesystemNode::operator =(const FilesystemNode &node) {
}
FilesystemNode FilesystemNode::getParent() const {
- FilesystemNode wrapper;
- wrapper._realNode = _realNode->parent();
- return wrapper;
+ AbstractFilesystemNode *node = _realNode->parent();
+ if (node == 0)
+ return *this;
+ else {
+ return AbstractFilesystemNode::wrap(node);
+ }
}
diff --git a/backends/fs/fs.h b/backends/fs/fs.h
index bc72cccc79..438e8d6583 100644
--- a/backends/fs/fs.h
+++ b/backends/fs/fs.h
@@ -139,6 +139,17 @@ public:
{
return scumm_stricmp(displayName().c_str(), node.displayName().c_str()) < 0;
}
+
+
+ /* TODO:
+ bool exists();
+
+ bool isDirectory();
+ bool isFile();
+
+ bool isReadable();
+ bool isWriteable();
+ */
};
class FilesystemNode : public AbstractFilesystemNode {
diff --git a/backends/fs/morphos/abox-fs.cpp b/backends/fs/morphos/abox-fs.cpp
index 712427b8cc..d774fc6974 100644
--- a/backends/fs/morphos/abox-fs.cpp
+++ b/backends/fs/morphos/abox-fs.cpp
@@ -38,7 +38,7 @@ class ABoxFilesystemNode : public AbstractFilesystemNode {
bool _isDirectory;
bool _isValid;
String _path;
-
+
public:
ABoxFilesystemNode();
ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name = NULL);
@@ -140,7 +140,7 @@ ABoxFilesystemNode::~ABoxFilesystemNode()
FSList ABoxFilesystemNode::listDir(ListMode mode) const
{
FSList myList;
-
+
if (!_isValid)
error("listDir() called on invalid node");
@@ -207,18 +207,15 @@ AbstractFilesystemNode *ABoxFilesystemNode::parent() const
if (!_isDirectory)
error("parent() called on file node");
- if (_lock == NULL)
+ if (_lock == NULL) {
/* Parent of the root is the root itself */
- node = clone();
- else
- {
+ node = 0;
+ } else {
BPTR parent_lock = ParentDir(_lock);
- if (parent_lock)
- {
+ if (parent_lock) {
node = new ABoxFilesystemNode(parent_lock);
UnLock(parent_lock);
- }
- else
+ } else
node = new ABoxFilesystemNode();
}
diff --git a/backends/fs/palmos/palmos-fs.cpp b/backends/fs/palmos/palmos-fs.cpp
index aeecb38d43..b5669216bd 100644
--- a/backends/fs/palmos/palmos-fs.cpp
+++ b/backends/fs/palmos/palmos-fs.cpp
@@ -136,13 +136,13 @@ const char *lastPathComponent(const Common::String &str) {
}
AbstractFilesystemNode *PalmOSFilesystemNode::parent() const {
-
- PalmOSFilesystemNode *p = new PalmOSFilesystemNode();
-
+ PalmOSFilesystemNode *p = 0;
+
if (!_isPseudoRoot) {
- const char *start = _path.c_str();
- const char *end = lastPathComponent(_path);
-
+ const char *start = _path.c_str();
+ const char *end = lastPathComponent(_path);
+
+ p = new PalmOSFilesystemNode();
p->_path = String(start, end - start);
p->_isValid = true;
p->_isDirectory = true;
diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp
index a2f35ad108..5834736806 100644
--- a/backends/fs/posix/posix-fs.cpp
+++ b/backends/fs/posix/posix-fs.cpp
@@ -185,22 +185,19 @@ FSList POSIXFilesystemNode::listDir(ListMode mode) const {
}
AbstractFilesystemNode *POSIXFilesystemNode::parent() const {
+ if (_path == "/")
+ return 0;
+
POSIXFilesystemNode *p = new POSIXFilesystemNode();
+ const char *start = _path.c_str();
+ const char *end = lastPathComponent(_path);
+
+ p->_path = String(start, end - start);
+ p->_displayName = lastPathComponent(p->_path);
- // Root node is its own parent. Still we can't just return this
- // as the GUI code will call delete on the old node.
- if (_path != "/") {
- const char *start = _path.c_str();
- const char *end = lastPathComponent(_path);
-
- p->_path = String(start, end - start);
- p->_displayName = lastPathComponent(p->_path);
- } else {
- p->_path = _path;
- p->_displayName = _displayName;
- }
p->_isValid = true;
p->_isDirectory = true;
+
return p;
}
diff --git a/backends/fs/windows/windows-fs.cpp b/backends/fs/windows/windows-fs.cpp
index 96231b9a53..11bec1e2f6 100644
--- a/backends/fs/windows/windows-fs.cpp
+++ b/backends/fs/windows/windows-fs.cpp
@@ -197,11 +197,12 @@ const char *lastPathComponent(const Common::String &str) {
AbstractFilesystemNode *WindowsFilesystemNode::parent() const {
assert(_isValid || _isPseudoRoot);
- WindowsFilesystemNode *p = new WindowsFilesystemNode();
+ WindowsFilesystemNode *p = 0;
if (!_isPseudoRoot && _path.size() > 3) {
const char *start = _path.c_str();
const char *end = lastPathComponent(_path);
+ p = new WindowsFilesystemNode();
p->_path = String(start, end - start);
p->_isValid = true;
p->_isDirectory = true;