mirror of
https://github.com/usatiuk/backup.git
synced 2025-10-26 17:37:47 +01:00
fix repofs for gcc
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#define FUSE_USE_VERSION 26
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
@@ -16,9 +17,8 @@
|
||||
#include "objects/Archive.h"
|
||||
#include "objects/File.h"
|
||||
|
||||
// TODO: fix it so it compiles with something other than clang
|
||||
struct DirEntry {
|
||||
std::unordered_map<std::string, DirEntry> children;
|
||||
std::unordered_map<std::string, std::unique_ptr<DirEntry>> children;
|
||||
std::optional<File> file;
|
||||
std::string name;
|
||||
bool isFakeDir = false;
|
||||
@@ -28,7 +28,7 @@ class RepoFS {
|
||||
public:
|
||||
static void start(Repository *repo, std::string path);
|
||||
|
||||
static inline DirEntry root;
|
||||
static inline std::unique_ptr<DirEntry> root{std::make_unique<DirEntry>()};
|
||||
static inline Repository *repo;
|
||||
|
||||
virtual ~RepoFS() = 0;
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
DirEntry *getf(std::string path) {
|
||||
auto p = std::filesystem::relative(std::filesystem::u8path(path), "/");
|
||||
DirEntry *entry = &RepoFS::root;
|
||||
DirEntry *entry = RepoFS::root.get();
|
||||
if (p != ".")
|
||||
for (auto const &subp: p) {
|
||||
entry = &entry->children.at(subp);
|
||||
entry = entry->children.at(subp).get();
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ static int rfsReaddir(const char *path, void *buf, fuse_fill_dir_t filler,
|
||||
(void) offset;
|
||||
(void) fi;
|
||||
|
||||
DirEntry *entry = &RepoFS::root;
|
||||
DirEntry *entry = RepoFS::root.get();
|
||||
if (std::string(path) != "/")
|
||||
try {
|
||||
entry = getf(path);
|
||||
@@ -68,7 +68,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 = e.second.name;
|
||||
auto pstr = e.second->name;
|
||||
std::cout << pstr << std::endl;
|
||||
filler(buf, pstr.c_str(), NULL, 0);
|
||||
}
|
||||
@@ -77,7 +77,7 @@ static int rfsReaddir(const char *path, void *buf, fuse_fill_dir_t filler,
|
||||
}
|
||||
|
||||
static int rfsOpen(const char *path, struct fuse_file_info *fi) {
|
||||
DirEntry *entry = &RepoFS::root;
|
||||
DirEntry *entry = RepoFS::root.get();
|
||||
if (std::string(path) != "/")
|
||||
try {
|
||||
entry = getf(path);
|
||||
@@ -93,7 +93,7 @@ static int rfsRead(const char *path, char *buf, size_t size, off_t offset,
|
||||
struct fuse_file_info *fi) {
|
||||
size_t len;
|
||||
(void) fi;
|
||||
DirEntry *entry = &RepoFS::root;
|
||||
DirEntry *entry = RepoFS::root.get();
|
||||
if (std::string(path) != "/")
|
||||
try {
|
||||
entry = getf(path);
|
||||
@@ -127,7 +127,7 @@ static int rfsRead(const char *path, char *buf, size_t size, off_t offset,
|
||||
}
|
||||
|
||||
static int rfsReadlink(const char *path, char *buf, size_t size) {
|
||||
DirEntry *entry = &RepoFS::root;
|
||||
DirEntry *entry = RepoFS::root.get();
|
||||
if (std::string(path) != "/")
|
||||
try {
|
||||
entry = getf(path);
|
||||
@@ -154,11 +154,15 @@ void RepoFS::start(Repository *repo, std::string path) {
|
||||
for (auto const &f: a.files) {
|
||||
auto file = Serialize::deserialize<File>(repo->getObject(f));
|
||||
auto path = std::filesystem::u8path(file.name);
|
||||
DirEntry *entry = &(root.children[std::to_string(a.id)]);
|
||||
DirEntry *entry = root->children[std::to_string(a.id)].get()
|
||||
? root->children[std::to_string(a.id)].get()
|
||||
: (root->children[std::to_string(a.id)] = std::make_unique<DirEntry>()).get();
|
||||
entry->isFakeDir = true;
|
||||
entry->name = std::to_string(a.id);
|
||||
for (auto const &subp: path) {
|
||||
entry = &entry->children[subp];
|
||||
entry = entry->children[subp].get()
|
||||
? entry->children[subp].get()
|
||||
: (entry->children[subp] = std::make_unique<DirEntry>()).get();
|
||||
}
|
||||
entry->file.emplace(file);
|
||||
entry->name = std::filesystem::u8path(file.name).filename().u8string();
|
||||
|
||||
Reference in New Issue
Block a user