support/BPath: Flatten should work on empty BPath
BPath::Flatten() on an empty path returns B_OK in BeOS R5, just writing an empty entry_ref to the povided buffer. The Haiku implementation has some additional validation that causes B_NO_INIT to be returned instead. This patch attempts to recreate the same behavior of BeOS in this situation. * Don't check for initialization in BPath::Flatten(). Instead, just write an empty entry_ref to the provided buffer if the BPath is empty. * Fix estimation of expected size when testing the return value of BPath::FlattenedSize(). * Clean up warning by removing unecessary forward-declaration of CppUnit::Test. Change-Id: I88880cbb298bdcb594c9c8fef48314165c49e9e5 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2115 Reviewed-by: Adrien Destugues <[email protected]> Reviewed-by: Axel Dörfler <[email protected]>
This commit is contained in:
committed by
Axel Dörfler
parent
7037b5d9bc
commit
654135466f
@@ -431,18 +431,18 @@ BPath::Flatten(void* buffer, ssize_t size) const
|
|||||||
return flattenedSize;
|
return flattenedSize;
|
||||||
if (size < flattenedSize)
|
if (size < flattenedSize)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
status_t status = InitCheck();
|
|
||||||
if (status != B_OK)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
// convert the path to an entry_ref
|
// convert the path to an entry_ref
|
||||||
BEntry entry;
|
BEntry entry;
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
status = entry.SetTo(Path());
|
|
||||||
if (status == B_OK)
|
if (Path() != NULL) {
|
||||||
status = entry.GetRef(&ref);
|
status_t status = entry.SetTo(Path());
|
||||||
if (status != B_OK)
|
if (status == B_OK)
|
||||||
return status;
|
status = entry.GetRef(&ref);
|
||||||
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
// store the entry_ref in the buffer
|
// store the entry_ref in the buffer
|
||||||
flattened_entry_ref& fref = *(flattened_entry_ref*)buffer;
|
flattened_entry_ref& fref = *(flattened_entry_ref*)buffer;
|
||||||
|
|||||||
@@ -1352,8 +1352,8 @@ PathTest::FlattenableTest()
|
|||||||
// flatten the path
|
// flatten the path
|
||||||
struct flattened_ref { dev_t device; ino_t directory; char name[1]; };
|
struct flattened_ref { dev_t device; ino_t directory; char name[1]; };
|
||||||
size = path.FlattenedSize();
|
size = path.FlattenedSize();
|
||||||
ssize_t expectedSize // hehe, that's hacky ;-)
|
ssize_t expectedSize
|
||||||
= (ssize_t)((flattened_ref*)NULL)->name + strlen(ref.name) + 1;
|
= sizeof(dev_t) + sizeof(ino_t) + strlen(ref.name) + 1;
|
||||||
CPPUNIT_ASSERT( size == expectedSize);
|
CPPUNIT_ASSERT( size == expectedSize);
|
||||||
CPPUNIT_ASSERT( path.Flatten(buffer, sizeof(buffer)) == B_OK );
|
CPPUNIT_ASSERT( path.Flatten(buffer, sizeof(buffer)) == B_OK );
|
||||||
// check the flattened data
|
// check the flattened data
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
#include <StorageDefs.h>
|
#include <StorageDefs.h>
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
class CppUnit::Test;
|
|
||||||
|
|
||||||
class PathTest : public BasicTest
|
class PathTest : public BasicTest
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user