2 * Copyright 2013, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold, ingo_weinhold@gmx.de
10 #include "VirtualDirectoryEntryList.h"
12 #include <AutoLocker.h>
13 #include <storage_support.h>
16 #include "VirtualDirectoryManager.h"
21 // #pragma mark - VirtualDirectoryEntryList
24 VirtualDirectoryEntryList::VirtualDirectoryEntryList(Model
* model
)
28 fMergedDirectory(BMergedDirectory::B_ALWAYS_FIRST
)
30 VirtualDirectoryManager
* manager
= VirtualDirectoryManager::Instance();
31 if (manager
== NULL
) {
32 fStatus
= B_NO_MEMORY
;
36 AutoLocker
<VirtualDirectoryManager
> managerLocker(manager
);
37 BStringList directoryPaths
;
38 fStatus
= manager
->ResolveDirectoryPaths(*model
->NodeRef(),
39 *model
->EntryRef(), directoryPaths
, &fDefinitionFileRef
);
43 fStatus
= _InitMergedDirectory(directoryPaths
);
47 VirtualDirectoryEntryList::VirtualDirectoryEntryList(
48 const node_ref
& definitionFileRef
, const BStringList
& directoryPaths
)
51 fDefinitionFileRef(definitionFileRef
),
52 fMergedDirectory(BMergedDirectory::B_ALWAYS_FIRST
)
54 fStatus
= _InitMergedDirectory(directoryPaths
);
58 VirtualDirectoryEntryList::~VirtualDirectoryEntryList()
64 VirtualDirectoryEntryList::InitCheck() const
66 return EntryListBase::InitCheck();
71 VirtualDirectoryEntryList::GetNextEntry(BEntry
* entry
, bool traverse
)
74 status_t error
= GetNextRef(&ref
);
78 return entry
->SetTo(&ref
, traverse
);
83 VirtualDirectoryEntryList::GetNextRef(entry_ref
* ref
)
85 BPrivate::Storage::LongDirEntry entry
;
86 int32 result
= GetNextDirents(&entry
, sizeof(entry
), 1);
90 return B_ENTRY_NOT_FOUND
;
92 ref
->device
= entry
.d_pdev
;
93 ref
->directory
= entry
.d_pino
;
94 return ref
->set_name(entry
.d_name
);
99 VirtualDirectoryEntryList::GetNextDirents(struct dirent
* buffer
, size_t length
,
105 int32 countRead
= fMergedDirectory
.GetNextDirents(buffer
, length
, count
);
109 // deal with directories
111 ref
.device
= buffer
->d_pdev
;
112 ref
.directory
= buffer
->d_pino
;
113 if (ref
.set_name(buffer
->d_name
) == B_OK
&& BEntry(&ref
).IsDirectory()) {
114 if (VirtualDirectoryManager
* manager
115 = VirtualDirectoryManager::Instance()) {
116 AutoLocker
<VirtualDirectoryManager
> managerLocker(manager
);
117 manager
->TranslateDirectoryEntry(fDefinitionFileRef
, buffer
);
126 VirtualDirectoryEntryList::Rewind()
128 return fMergedDirectory
.Rewind();
133 VirtualDirectoryEntryList::CountEntries()
140 VirtualDirectoryEntryList::_InitMergedDirectory(
141 const BStringList
& directoryPaths
)
143 status_t error
= fMergedDirectory
.Init();
147 int32 count
= directoryPaths
.CountStrings();
148 for (int32 i
= 0; i
< count
; i
++)
149 fMergedDirectory
.AddDirectory(directoryPaths
.StringAt(i
));
154 } // namespace BPrivate