BDirectory::Contains() would return "true" if the entry being tested for existed,
but the BDirectory was not initialized correctly. Thanks to Jonas who also provided a patch for this (which I didn't use directly, though, for some minor reasons). This fixes bug #1034. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20221 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2006, Haiku Inc.
|
* Copyright 2002-2007, Haiku Inc.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -452,12 +452,14 @@ BDirectory::Contains(const char *path, int32 nodeFlags) const
|
|||||||
return false;
|
return false;
|
||||||
if (!path)
|
if (!path)
|
||||||
return true; // mimic R5 behavior
|
return true; // mimic R5 behavior
|
||||||
|
|
||||||
// turn the path into a BEntry and let the other version do the work
|
// turn the path into a BEntry and let the other version do the work
|
||||||
BEntry entry;
|
BEntry entry;
|
||||||
if (BPrivate::Storage::is_absolute_path(path))
|
if (BPrivate::Storage::is_absolute_path(path))
|
||||||
entry.SetTo(path);
|
entry.SetTo(path);
|
||||||
else
|
else
|
||||||
entry.SetTo(this, path);
|
entry.SetTo(this, path);
|
||||||
|
|
||||||
return Contains(&entry, nodeFlags);
|
return Contains(&entry, nodeFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -480,32 +482,34 @@ BDirectory::Contains(const char *path, int32 nodeFlags) const
|
|||||||
bool
|
bool
|
||||||
BDirectory::Contains(const BEntry *entry, int32 nodeFlags) const
|
BDirectory::Contains(const BEntry *entry, int32 nodeFlags) const
|
||||||
{
|
{
|
||||||
bool result = (entry);
|
|
||||||
// check, if the entry exists at all
|
// check, if the entry exists at all
|
||||||
if (result)
|
if (entry == NULL || !entry->Exists() || InitCheck() != B_OK)
|
||||||
result = entry->Exists();
|
return false;
|
||||||
|
|
||||||
|
bool result = true;
|
||||||
|
|
||||||
// test the node kind
|
// test the node kind
|
||||||
if (result) {
|
switch (nodeFlags) {
|
||||||
switch (nodeFlags) {
|
case B_FILE_NODE:
|
||||||
case B_FILE_NODE:
|
result = entry->IsFile();
|
||||||
result = entry->IsFile();
|
break;
|
||||||
break;
|
case B_DIRECTORY_NODE:
|
||||||
case B_DIRECTORY_NODE:
|
result = entry->IsDirectory();
|
||||||
result = entry->IsDirectory();
|
break;
|
||||||
break;
|
case B_SYMLINK_NODE:
|
||||||
case B_SYMLINK_NODE:
|
result = entry->IsSymLink();
|
||||||
result = entry->IsSymLink();
|
break;
|
||||||
break;
|
case B_ANY_NODE:
|
||||||
case B_ANY_NODE:
|
break;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the directory is initialized, get the canonical paths of the dir and
|
// If the directory is initialized, get the canonical paths of the dir and
|
||||||
// the entry and check, if the latter is a prefix of the first one.
|
// the entry and check, if the latter is a prefix of the first one.
|
||||||
if (result && InitCheck() == B_OK) {
|
if (result) {
|
||||||
BPath dirPath(this, ".", true);
|
BPath dirPath(this, ".", true);
|
||||||
BPath entryPath(entry);
|
BPath entryPath(entry);
|
||||||
if (dirPath.InitCheck() == B_OK && entryPath.InitCheck() == B_OK) {
|
if (dirPath.InitCheck() == B_OK && entryPath.InitCheck() == B_OK) {
|
||||||
@@ -514,6 +518,7 @@ BDirectory::Contains(const BEntry *entry, int32 nodeFlags) const
|
|||||||
} else
|
} else
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user