From 929057ada177e74f521ba69190cc77c742f6ccea Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Sat, 15 Jul 2023 00:36:34 +0200 Subject: [PATCH] fix repofs for gcc --- .github/workflows/cmake.yml | 5 +++-- CMakeLists.txt | 20 ++++++++++++-------- src/fuse/includes/RepoFS.h | 6 +++--- src/fuse/srcs/RepoFS.cpp | 22 +++++++++++++--------- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 4e4af75..e97a318 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -9,6 +9,7 @@ on: env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Debug + SANITIZE: YES jobs: build: @@ -21,12 +22,12 @@ jobs: - uses: actions/checkout@v3 - 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 # 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 - 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 # Build your program with the given configuration diff --git a/CMakeLists.txt b/CMakeLists.txt index 69dc848..3d66f81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,19 @@ cmake_minimum_required(VERSION 3.22) -add_compile_options(-Ofast) -add_link_options(-Ofast) +if (SANITIZE STREQUAL "YES") + 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) -#add_link_options(-Ofast -flto) +if (CMAKE_BUILD_TYPE STREQUAL "Release") + 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(-fsanitize=address -fsanitize=undefined -fno-sanitize-recover) -#add_link_options(-fsanitize=address -fsanitize=undefined -fno-sanitize-recover) -#add_link_options(-rdynamic) +add_compile_options(-rdynamic) +add_link_options(-rdynamic) project(backup) diff --git a/src/fuse/includes/RepoFS.h b/src/fuse/includes/RepoFS.h index dea5691..db8c9db 100644 --- a/src/fuse/includes/RepoFS.h +++ b/src/fuse/includes/RepoFS.h @@ -7,6 +7,7 @@ #define FUSE_USE_VERSION 26 +#include #include #include #include @@ -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 children; + std::unordered_map> children; std::optional 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 root{std::make_unique()}; static inline Repository *repo; virtual ~RepoFS() = 0; diff --git a/src/fuse/srcs/RepoFS.cpp b/src/fuse/srcs/RepoFS.cpp index 2109c9b..8147906 100644 --- a/src/fuse/srcs/RepoFS.cpp +++ b/src/fuse/srcs/RepoFS.cpp @@ -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(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()).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()).get(); } entry->file.emplace(file); entry->name = std::filesystem::u8path(file.name).filename().u8string();