fix repofs for gcc

This commit is contained in:
2023-07-15 00:36:34 +02:00
parent 4ffadddbae
commit 929057ada1
4 changed files with 31 additions and 22 deletions

View File

@@ -9,6 +9,7 @@ on:
env: env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug BUILD_TYPE: Debug
SANITIZE: YES
jobs: jobs:
build: build:
@@ -21,12 +22,12 @@ jobs:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: install everything - name: install everything
run: sudo apt-get install -y fuse libfuse-dev clang-14 lld-14 run: sudo apt-get install -y fuse libfuse-dev
- name: Configure CMake - name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: CXX=/usr/bin/clang++ CC=/usr/bin/clang CXXFLAGS=-gdwarf-4 cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DSANITIZE=${{env.SANITIZE}}
- name: Build - name: Build
# Build your program with the given configuration # Build your program with the given configuration

View File

@@ -1,15 +1,19 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.22)
add_compile_options(-Ofast) if (SANITIZE STREQUAL "YES")
add_link_options(-Ofast) message(WARNING "Enabling sanitizers!")
add_compile_options(-Wall -Wextra -pedantic -Wshadow -Wformat=2 -Wfloat-equal -D_GLIBCXX_DEBUG -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2)
add_compile_options(-fsanitize=address -fsanitize=undefined -fno-sanitize-recover)
add_link_options(-fsanitize=address -fsanitize=undefined -fno-sanitize-recover)
endif ()
#add_compile_options(-Ofast -flto) if (CMAKE_BUILD_TYPE STREQUAL "Release")
#add_link_options(-Ofast -flto) add_compile_options(-flto)
add_link_options(-flto)
endif ()
#add_compile_options(-Wall -O0 -Wextra -pedantic -Wshadow -Wformat=2 -Wfloat-equal -D_GLIBCXX_DEBUG -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g -rdynamic) add_compile_options(-rdynamic)
#add_compile_options(-fsanitize=address -fsanitize=undefined -fno-sanitize-recover) add_link_options(-rdynamic)
#add_link_options(-fsanitize=address -fsanitize=undefined -fno-sanitize-recover)
#add_link_options(-rdynamic)
project(backup) project(backup)

View File

@@ -7,6 +7,7 @@
#define FUSE_USE_VERSION 26 #define FUSE_USE_VERSION 26
#include <memory>
#include <optional> #include <optional>
#include <string> #include <string>
#include <thread> #include <thread>
@@ -16,9 +17,8 @@
#include "objects/Archive.h" #include "objects/Archive.h"
#include "objects/File.h" #include "objects/File.h"
// TODO: fix it so it compiles with something other than clang
struct DirEntry { struct DirEntry {
std::unordered_map<std::string, DirEntry> children; std::unordered_map<std::string, std::unique_ptr<DirEntry>> children;
std::optional<File> file; std::optional<File> file;
std::string name; std::string name;
bool isFakeDir = false; bool isFakeDir = false;
@@ -28,7 +28,7 @@ class RepoFS {
public: public:
static void start(Repository *repo, std::string path); 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; static inline Repository *repo;
virtual ~RepoFS() = 0; virtual ~RepoFS() = 0;

View File

@@ -16,10 +16,10 @@
DirEntry *getf(std::string path) { DirEntry *getf(std::string path) {
auto p = std::filesystem::relative(std::filesystem::u8path(path), "/"); auto p = std::filesystem::relative(std::filesystem::u8path(path), "/");
DirEntry *entry = &RepoFS::root; DirEntry *entry = RepoFS::root.get();
if (p != ".") if (p != ".")
for (auto const &subp: p) { for (auto const &subp: p) {
entry = &entry->children.at(subp); entry = entry->children.at(subp).get();
} }
return entry; return entry;
} }
@@ -58,7 +58,7 @@ static int rfsReaddir(const char *path, void *buf, fuse_fill_dir_t filler,
(void) offset; (void) offset;
(void) fi; (void) fi;
DirEntry *entry = &RepoFS::root; DirEntry *entry = RepoFS::root.get();
if (std::string(path) != "/") if (std::string(path) != "/")
try { try {
entry = getf(path); entry = getf(path);
@@ -68,7 +68,7 @@ static int rfsReaddir(const char *path, void *buf, fuse_fill_dir_t filler,
filler(buf, "..", NULL, 0); filler(buf, "..", NULL, 0);
for (auto const &e: entry->children) { for (auto const &e: entry->children) {
auto pstr = e.second.name; auto pstr = e.second->name;
std::cout << pstr << std::endl; std::cout << pstr << std::endl;
filler(buf, pstr.c_str(), NULL, 0); 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) { static int rfsOpen(const char *path, struct fuse_file_info *fi) {
DirEntry *entry = &RepoFS::root; DirEntry *entry = RepoFS::root.get();
if (std::string(path) != "/") if (std::string(path) != "/")
try { try {
entry = getf(path); 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) { struct fuse_file_info *fi) {
size_t len; size_t len;
(void) fi; (void) fi;
DirEntry *entry = &RepoFS::root; DirEntry *entry = RepoFS::root.get();
if (std::string(path) != "/") if (std::string(path) != "/")
try { try {
entry = getf(path); 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) { static int rfsReadlink(const char *path, char *buf, size_t size) {
DirEntry *entry = &RepoFS::root; DirEntry *entry = RepoFS::root.get();
if (std::string(path) != "/") if (std::string(path) != "/")
try { try {
entry = getf(path); entry = getf(path);
@@ -154,11 +154,15 @@ void RepoFS::start(Repository *repo, std::string path) {
for (auto const &f: a.files) { for (auto const &f: a.files) {
auto file = Serialize::deserialize<File>(repo->getObject(f)); auto file = Serialize::deserialize<File>(repo->getObject(f));
auto path = std::filesystem::u8path(file.name); 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->isFakeDir = true;
entry->name = std::to_string(a.id); entry->name = std::to_string(a.id);
for (auto const &subp: path) { 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->file.emplace(file);
entry->name = std::filesystem::u8path(file.name).filename().u8string(); entry->name = std::filesystem::u8path(file.name).filename().u8string();