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:
@@ -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.
|
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
|
Only entries that match the node flavor specified by \a nodeFlags are
|
||||||
considered.
|
considered.
|
||||||
If the BDirectory is not properly initialized, the method returns \c true,
|
If the BDirectory is not properly initialized, the method returns \c false.
|
||||||
if the entry exists and its kind does match. A non-absolute path is
|
A non-absolute path is considered relative to the current directory.
|
||||||
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
|
\param path the entry's path name. May be relative to this directory or
|
||||||
absolute.
|
absolute.
|
||||||
\param nodeFlags Any of the following:
|
\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.
|
- \c B_ANY_NODE: The entry may be of any kind.
|
||||||
\return
|
\return
|
||||||
- \c true, if the entry exists, its kind does match \nodeFlags and the
|
- \c true, if the entry exists, its kind does match \nodeFlags and the
|
||||||
BDirectory is either not properly initialized or it does contain the
|
BDirectory is properly initialized and does contain the entry at any
|
||||||
entry at any level,
|
level,
|
||||||
- \c false, otherwise
|
- \c false, otherwise
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
BDirectory::Contains(const char *path, int32 nodeFlags) const
|
BDirectory::Contains(const char *path, int32 nodeFlags) const
|
||||||
{
|
{
|
||||||
bool result = true;
|
// check initialization and parameters
|
||||||
if (path) {
|
if (InitCheck() != B_OK)
|
||||||
BEntry entry;
|
return false;
|
||||||
if (InitCheck() == B_OK && !BPrivate::Storage::is_absolute_path(path))
|
if (!path)
|
||||||
entry.SetTo(this, path);
|
return true; // mimic R5 behavior
|
||||||
else
|
// turn the path into a BEntry and let the other version do the work
|
||||||
entry.SetTo(path);
|
BEntry entry;
|
||||||
result = Contains(&entry, nodeFlags);
|
if (BPrivate::Storage::is_absolute_path(path))
|
||||||
} else {
|
entry.SetTo(path);
|
||||||
// R5 behavior
|
else
|
||||||
result = (InitCheck() == B_OK);
|
entry.SetTo(this, path);
|
||||||
}
|
return Contains(&entry, nodeFlags);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contains
|
// Contains
|
||||||
|
|||||||
@@ -807,10 +807,14 @@ DirectoryTest::ContainsTest()
|
|||||||
CPPUNIT_ASSERT( dir.Contains(existingSub) == true );
|
CPPUNIT_ASSERT( dir.Contains(existingSub) == true );
|
||||||
dir.Unset();
|
dir.Unset();
|
||||||
// existing entry, uninitialized BDirectory
|
// existing entry, uninitialized BDirectory
|
||||||
// R5 returns true!
|
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
|
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
|
||||||
|
// R5 returns true!
|
||||||
|
#if TEST_R5
|
||||||
CPPUNIT_ASSERT( dir.Contains(existing) == true );
|
CPPUNIT_ASSERT( dir.Contains(existing) == true );
|
||||||
|
#else
|
||||||
|
CPPUNIT_ASSERT( dir.Contains(existing) == false );
|
||||||
|
#endif
|
||||||
dir.Unset();
|
dir.Unset();
|
||||||
// non-existing entry, uninitialized BDirectory
|
// non-existing entry, uninitialized BDirectory
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
@@ -821,7 +825,12 @@ DirectoryTest::ContainsTest()
|
|||||||
NextSubTest();
|
NextSubTest();
|
||||||
CPPUNIT_ASSERT( dir.SetTo(nonExisting) == B_ENTRY_NOT_FOUND );
|
CPPUNIT_ASSERT( dir.SetTo(nonExisting) == B_ENTRY_NOT_FOUND );
|
||||||
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
|
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
|
||||||
|
// R5 returns true!
|
||||||
|
#if TEST_R5
|
||||||
CPPUNIT_ASSERT( dir.Contains(existing) == true );
|
CPPUNIT_ASSERT( dir.Contains(existing) == true );
|
||||||
|
#else
|
||||||
|
CPPUNIT_ASSERT( dir.Contains(existing) == false );
|
||||||
|
#endif
|
||||||
dir.Unset();
|
dir.Unset();
|
||||||
// non-existing entry, badly initialized BDirectory
|
// non-existing entry, badly initialized BDirectory
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
|
|||||||
Reference in New Issue
Block a user