Implemented new Directory::IsEmpty() method.

Amiga-FFS Directory::Lookup() now only creates a HashIterator if needed.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4887 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2003-10-01 01:25:06 +00:00
parent 3c3cc60956
commit d178a0d7e4
4 changed files with 38 additions and 4 deletions

View File

@ -80,15 +80,15 @@ Directory::Close(void *cookie)
Node *
Directory::Lookup(const char *name, bool traverseLinks)
{
HashIterator iterator(fVolume.Device(), fNode);
if (iterator.InitCheck() != B_OK)
return NULL;
if (!strcmp(name, ".")) {
Acquire();
return this;
}
HashIterator iterator(fVolume.Device(), fNode);
if (iterator.InitCheck() != B_OK)
return NULL;
iterator.Goto(fNode.HashIndexFor(fVolume.Type(), name));
NodeBlock *node;
@ -140,6 +140,14 @@ Directory::Rewind(void *cookie)
}
bool
Directory::IsEmpty()
{
int32 index;
return fNode.FirstHashValue(index) == -1;
}
status_t
Directory::GetName(char *name, size_t size) const
{

View File

@ -32,6 +32,7 @@ class Directory : public ::Directory {
virtual status_t GetNextEntry(void *cookie, char *nameBuffer, size_t bufferSize);
virtual status_t GetNextNode(void *cookie, Node **_node);
virtual status_t Rewind(void *cookie);
virtual bool IsEmpty();
virtual status_t GetName(char *name, size_t size) const;

View File

@ -128,6 +128,30 @@ Directory::Rewind(void *cookie)
}
bool
Directory::IsEmpty()
{
TreeIterator iterator(&fTree);
// index and attribute directories are really empty when they are
// empty - directories for standard files always contain ".", and
// "..", so we need to ignore those two
uint32 count = 0;
char name[BPLUSTREE_MAX_KEY_LENGTH];
uint16 length;
off_t id;
while (iterator.GetNextEntry(name, &length, B_FILE_NAME_LENGTH, &id) == B_OK) {
if (fStream.Mode() & (S_ATTR_DIR | S_INDEX_DIR))
return false;
if (++count > 2 || strcmp(".", name) && strcmp("..", name))
return false;
}
return true;
}
status_t
Directory::GetName(char *name, size_t size) const
{

View File

@ -32,6 +32,7 @@ class Directory : public ::Directory {
virtual status_t GetNextEntry(void *cookie, char *nameBuffer, size_t bufferSize);
virtual status_t GetNextNode(void *cookie, Node **_node);
virtual status_t Rewind(void *cookie);
virtual bool IsEmpty();
virtual status_t GetName(char *name, size_t size) const;