Skip to content

Commit

Permalink
AMIGAOS4: Fix getParent() for non-directories
Browse files Browse the repository at this point in the history
The previous attempt in d32816c was broken because it failed
to realize that _pFileLock is only set for directories.

This patch also tries to clarify this by making the root node logic
explicit in isRootNode().
  • Loading branch information
wjp committed Oct 11, 2014
1 parent f76e02e commit 4b09957
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
26 changes: 19 additions & 7 deletions backends/fs/amigaos4/amigaos4-fs.cpp
Expand Up @@ -252,7 +252,7 @@ bool AmigaOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, b
return false; // Empty list
}

if (_pFileLock == 0) {
if (isRootNode()) {
debug(6, "Root node");
LEAVE();
myList = listVolumes();
Expand Down Expand Up @@ -307,21 +307,33 @@ bool AmigaOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, b
AbstractFSNode *AmigaOSFilesystemNode::getParent() const {
ENTER();

if (_pFileLock == 0) {
if (isRootNode()) {
debug(6, "Root node");
LEAVE();
return new AmigaOSFilesystemNode(*this);
}

BPTR pLock = _pFileLock;

if (!_bIsDirectory) {
assert(!pLock);
pLock = IDOS->Lock((CONST_STRPTR)_sPath.c_str(), SHARED_LOCK);
assert(pLock);
}

AmigaOSFilesystemNode *node;

BPTR parentDir = IDOS->ParentDir( _pFileLock );
BPTR parentDir = IDOS->ParentDir( pLock );
if (parentDir) {
node = new AmigaOSFilesystemNode(parentDir);
IDOS->UnLock(parentDir);
} else
node = new AmigaOSFilesystemNode();

if (!_bIsDirectory) {
IDOS->UnLock(pLock);
}

LEAVE();

return node;
Expand All @@ -332,9 +344,9 @@ bool AmigaOSFilesystemNode::isReadable() const {
return false;

// Regular RWED protection flags are low-active or inverted, thus the negation.
// Moreover, a pseudo root filesystem (null _pFileLock) is readable whatever the
// Moreover, a pseudo root filesystem is readable whatever the
// protection says.
bool readable = !(_nProt & EXDF_OTR_READ) || _pFileLock == 0;
bool readable = !(_nProt & EXDF_OTR_READ) || isRootNode();

return readable;
}
Expand All @@ -344,9 +356,9 @@ bool AmigaOSFilesystemNode::isWritable() const {
return false;

// Regular RWED protection flags are low-active or inverted, thus the negation.
// Moreover, a pseudo root filesystem (null _pFileLock) is never writable whatever
// Moreover, a pseudo root filesystem is never writable whatever
// the protection says (Because of it's pseudo nature).
bool writable = !(_nProt & EXDF_OTR_WRITE) && _pFileLock !=0;
bool writable = !(_nProt & EXDF_OTR_WRITE) && !isRootNode();

return writable;
}
Expand Down
5 changes: 5 additions & 0 deletions backends/fs/amigaos4/amigaos4-fs.h
Expand Up @@ -62,6 +62,11 @@ class AmigaOSFilesystemNode : public AbstractFSNode {
*/
virtual AbstractFSList listVolumes() const;

/**
* True if this is the pseudo root filesystem.
*/
bool isRootNode() const { return _bIsValid && _bIsDirectory && _pFileLock == 0; }

public:
/**
* Creates an AmigaOSFilesystemNode with the root node as path.
Expand Down

0 comments on commit 4b09957

Please sign in to comment.