A CryDir returns . and .. as children

This commit is contained in:
Sebastian Meßmer 2015-03-19 03:53:21 +01:00
parent 56928e68a8
commit f1a992d187
3 changed files with 11 additions and 10 deletions

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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);