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:
Axel Dörfler
2007-02-24 05:43:16 +00:00
parent 36fbdbb149
commit d8de23cd1e
+12 -7
View File
@@ -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,12 +482,13 @@ 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();
@@ -498,14 +501,15 @@ BDirectory::Contains(const BEntry *entry, int32 nodeFlags) const
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;
} }