Changed the behavior of Contains(const char*, int32): It does not longer

return true, if the directory is not initialized, or if the directory
does not contain the entry, but the given path is absolute. This change
makes it less compatible with R5, but more consistent with the BEntry*
version and undoubtfully more compatible with common sense.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5884 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2004-01-03 16:27:39 +00:00
parent dccf026397
commit 5abde301c1
2 changed files with 32 additions and 19 deletions
+22 -18
View File
@@ -409,9 +409,14 @@ BDirectory::FindEntry(const char *path, BEntry *entry, bool traverse) const
at any level contain the entry referred to by the supplied path name.
Only entries that match the node flavor specified by \a nodeFlags are
considered.
If the BDirectory is not properly initialized, the method returns \c true,
if the entry exists and its kind does match. A non-absolute path is
considered relative to the current directory.
If the BDirectory is not properly initialized, the method returns \c false.
A non-absolute path is considered relative to the current directory.
\note R5's implementation always returns \c true given an absolute path or
an unitialized directory. This implementation is not compatible with that
behavior. Instead it converts the path into a BEntry and passes it to the
other version of Contains().
\param path the entry's path name. May be relative to this directory or
absolute.
\param nodeFlags Any of the following:
@@ -421,26 +426,25 @@ BDirectory::FindEntry(const char *path, BEntry *entry, bool traverse) const
- \c B_ANY_NODE: The entry may be of any kind.
\return
- \c true, if the entry exists, its kind does match \nodeFlags and the
BDirectory is either not properly initialized or it does contain the
entry at any level,
BDirectory is properly initialized and does contain the entry at any
level,
- \c false, otherwise
*/
bool
BDirectory::Contains(const char *path, int32 nodeFlags) const
{
bool result = true;
if (path) {
BEntry entry;
if (InitCheck() == B_OK && !BPrivate::Storage::is_absolute_path(path))
entry.SetTo(this, path);
else
entry.SetTo(path);
result = Contains(&entry, nodeFlags);
} else {
// R5 behavior
result = (InitCheck() == B_OK);
}
return result;
// check initialization and parameters
if (InitCheck() != B_OK)
return false;
if (!path)
return true; // mimic R5 behavior
// turn the path into a BEntry and let the other version do the work
BEntry entry;
if (BPrivate::Storage::is_absolute_path(path))
entry.SetTo(path);
else
entry.SetTo(this, path);
return Contains(&entry, nodeFlags);
}
// Contains
+10 -1
View File
@@ -807,10 +807,14 @@ DirectoryTest::ContainsTest()
CPPUNIT_ASSERT( dir.Contains(existingSub) == true );
dir.Unset();
// existing entry, uninitialized BDirectory
// R5 returns true!
NextSubTest();
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
// R5 returns true!
#if TEST_R5
CPPUNIT_ASSERT( dir.Contains(existing) == true );
#else
CPPUNIT_ASSERT( dir.Contains(existing) == false );
#endif
dir.Unset();
// non-existing entry, uninitialized BDirectory
NextSubTest();
@@ -821,7 +825,12 @@ DirectoryTest::ContainsTest()
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(nonExisting) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
// R5 returns true!
#if TEST_R5
CPPUNIT_ASSERT( dir.Contains(existing) == true );
#else
CPPUNIT_ASSERT( dir.Contains(existing) == false );
#endif
dir.Unset();
// non-existing entry, badly initialized BDirectory
NextSubTest();