A CryDir returns . and .. as children
This commit is contained in:
parent
56928e68a8
commit
f1a992d187
@ -65,7 +65,11 @@ void CryDir::rmdir() {
|
||||
}
|
||||
|
||||
unique_ptr<vector<fspp::Dir::Entry>> CryDir::children() const {
|
||||
return LoadBlob()->GetChildren();
|
||||
auto children = make_unique<vector<fspp::Dir::Entry>>();
|
||||
children->push_back(fspp::Dir::Entry(fspp::Dir::EntryType::DIR, "."));
|
||||
children->push_back(fspp::Dir::Entry(fspp::Dir::EntryType::DIR, ".."));
|
||||
LoadBlob()->AppendChildrenTo(children.get());
|
||||
return children;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,24 +43,21 @@ unsigned char DirBlob::magicNumber() const {
|
||||
return number;
|
||||
}
|
||||
|
||||
unique_ptr<vector<fspp::Dir::Entry>> DirBlob::GetChildren() const {
|
||||
void DirBlob::AppendChildrenTo(vector<fspp::Dir::Entry> *result) const {
|
||||
Data entries(_blob->size()-1);
|
||||
_blob->read(entries.data(), 1, _blob->size()-1);
|
||||
|
||||
auto result = make_unique<vector<fspp::Dir::Entry>>();
|
||||
|
||||
const char *pos = (const char*)entries.data();
|
||||
while(pos < (const char*)entries.data()+entries.size()) {
|
||||
pos = readAndAddNextChild(pos, result.get());
|
||||
pos = readAndAddNextChild(pos, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DirBlob::hasChild(const string &name) const {
|
||||
//TODO Faster implementation without creating children array possible
|
||||
auto children = GetChildren();
|
||||
for (const auto &child : *children) {
|
||||
vector<fspp::Dir::Entry> children;
|
||||
AppendChildrenTo(&children);
|
||||
for (const auto &child : children) {
|
||||
if (child.name == name) {
|
||||
return true;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public:
|
||||
DirBlob(std::unique_ptr<blobstore::Blob> blob);
|
||||
virtual ~DirBlob();
|
||||
|
||||
std::unique_ptr<std::vector<fspp::Dir::Entry>> GetChildren() const;
|
||||
void AppendChildrenTo(std::vector<fspp::Dir::Entry> *result) const;
|
||||
//TODO Use struct instead of pair
|
||||
std::pair<fspp::Dir::EntryType, blockstore::Key> GetChild(const std::string &name) const;
|
||||
void AddChildDir(const std::string &name, const blockstore::Key &blobKey);
|
||||
|
Loading…
Reference in New Issue
Block a user