BEntryOperationEngineBase::Entry: Add debug methods

Add GetPathOrName() and PathOrName() methods which try to get some kind
of usable path or at least a file name for the entry. Useful mainly for
debugging and error reporting cases.
This commit is contained in:
Ingo Weinhold
2014-06-15 17:21:00 +02:00
parent 9680cf0bce
commit 6077cad882
2 changed files with 72 additions and 2 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2013, Haiku, Inc. All Rights Reserved.
* Copyright 2013-2014, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -44,6 +44,12 @@ public:
const;
BString Path() const;
status_t GetPathOrName(BString& _path) const;
// Tries to return some kind of string
// representation. Useful only for debugging
// and error reporting.
BString PathOrName() const;
private:
const BDirectory* fDirectory;
const char* fPath;
+65 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2013, Ingo Weinhold, [email protected].
* Copyright 2013-2014, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
@@ -117,4 +117,68 @@ BEntryOperationEngineBase::Entry::Path() const
}
status_t
BEntryOperationEngineBase::Entry::GetPathOrName(BString& _path) const
{
_path.Truncate(0);
BPath buffer;
const char* path;
status_t error = GetPath(buffer, path);
if (error == B_NO_MEMORY)
return error;
if (error == B_OK) {
_path = path;
} else if (fEntry != NULL) {
// GetPath() apparently failed, so just return the entry name.
_path = fEntry->Name();
} else if (fDirectory != NULL || fDirectoryRef != NULL) {
if (fPath != NULL && fPath[0] == '/') {
// absolute path -- just return it
_path = fPath;
} else {
// get the directory path
BEntry entry;
if (fDirectory != NULL) {
error = fDirectory->GetEntry(&entry);
} else {
BDirectory directory;
error = directory.SetTo(fDirectoryRef);
if (error == B_OK)
error = directory.GetEntry(&entry);
}
if (error != B_OK || (error = entry.GetPath(&buffer)) != B_OK)
return error;
_path = buffer.Path();
// If we additionally have a relative path, append it.
if (!_path.IsEmpty() && fPath != NULL) {
int32 length = _path.Length();
_path << '/' << fPath;
if (_path.Length() < length + 2)
return B_NO_MEMORY;
}
}
} else if (fEntryRef != NULL) {
// Getting the actual path apparently failed, so just return the entry
// name.
_path = fEntryRef->name;
} else if (fPath != NULL)
_path = fPath;
return _path.IsEmpty() ? B_NO_MEMORY : B_OK;
}
BString
BEntryOperationEngineBase::Entry::PathOrName() const
{
BString path;
return GetPathOrName(path) == B_OK ? path : BString();
}
} // namespace BPrivate