From f59950d8524d59fce2823dde3c54738589a2bef8 Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Thu, 8 Jun 2023 12:11:00 +0200 Subject: [PATCH] even more hacky but show all the archives --- src/fuse/includes/RepoFS.h | 2 ++ src/fuse/srcs/RepoFS.cpp | 26 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/fuse/includes/RepoFS.h b/src/fuse/includes/RepoFS.h index 8e764aa..75ae04c 100644 --- a/src/fuse/includes/RepoFS.h +++ b/src/fuse/includes/RepoFS.h @@ -14,6 +14,8 @@ struct DirEntry { std::unordered_map children; std::optional file; + std::string name; + bool isFakeDir = false; }; class RepoFS { diff --git a/src/fuse/srcs/RepoFS.cpp b/src/fuse/srcs/RepoFS.cpp index f6163ea..7d08a75 100644 --- a/src/fuse/srcs/RepoFS.cpp +++ b/src/fuse/srcs/RepoFS.cpp @@ -18,15 +18,23 @@ RepoFS::RepoFS(Repository *repon, Object::idType archiveId, std::string path) : archive(Serialize::deserialize(repon->getObject(archiveId))), path(std::move(path)) { RepoFS::repo = repon; - for (auto const &f: archive.files) { - auto file = Serialize::deserialize(repo->getObject(f)); - auto path = std::filesystem::u8path(file.name); - DirEntry *entry = &root; - for (auto const &subp: path) { - entry = &entry->children[subp]; + auto ars = repo->getObjects(Object::ObjectType::Archive); + for (auto const &r: ars) { + auto a = Serialize::deserialize(repon->getObject(r.second)); + for (auto const &f: a.files) { + auto file = Serialize::deserialize(repo->getObject(f)); + auto path = std::filesystem::u8path(file.name); + DirEntry *entry = &(root.children[r.first]); + entry->isFakeDir = true; + entry->name = a.name; + for (auto const &subp: path) { + entry = &entry->children[subp]; + } + entry->file.emplace(file); + entry->name = std::filesystem::u8path(file.name).filename().u8string(); } - entry->file.emplace(file); } + // thread = std::thread(&RepoFS::workerFn, this); } @@ -60,7 +68,7 @@ static int rfsGetattr(const char *path, struct stat *stbuf) { DirEntry *e; try { e = getf(path); - if (e->file->fileType == File::Type::Directory) { + if (e->isFakeDir || e->file->fileType == File::Type::Directory) { stbuf->st_mode = S_IFDIR | 0755; stbuf->st_nlink = 1; } else if (e->file->fileType == File::Type::Normal) { @@ -88,7 +96,7 @@ static int rfsReaddir(const char *path, void *buf, fuse_fill_dir_t filler, filler(buf, "..", NULL, 0); for (auto const &e: entry->children) { - auto pstr = std::filesystem::u8path(e.second.file->name).filename().u8string(); + auto pstr = e.second.name; std::cout << pstr << std::endl; filler(buf, pstr.c_str(), NULL, 0); }