From a70ca528e05ca6076d383887bfe2c8b7076e5ad8 Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Thu, 8 Jun 2023 23:54:49 +0200 Subject: [PATCH] repofs kinda working --- CMakeLists.txt | 12 ++++++------ src/commands/srcs/CommandMount.cpp | 2 +- src/fuse/srcs/RepoFS.cpp | 6 +++--- tests/clitests/scripts/backup.sh | 11 +++++++++++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ad7929..83703cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,13 +3,13 @@ cmake_minimum_required(VERSION 3.22) #add_compile_options(-Ofast) #add_link_options(-Ofast) -# add_compile_options(-Ofast -flto) -# add_link_options(-Ofast -flto) +add_compile_options(-Ofast -flto) +add_link_options(-Ofast -flto) -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(-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) project(backup) diff --git a/src/commands/srcs/CommandMount.cpp b/src/commands/srcs/CommandMount.cpp index 0f5c65c..e55ef6a 100644 --- a/src/commands/srcs/CommandMount.cpp +++ b/src/commands/srcs/CommandMount.cpp @@ -9,5 +9,5 @@ CommandMount::CommandMount() : Command("mount") { } void CommandMount::run(Context ctx) { - RepoFS::start(ctx.repo, "./hi"); + RepoFS::start(ctx.repo, ctx.repo->getConfig().getStr("to")); } diff --git a/src/fuse/srcs/RepoFS.cpp b/src/fuse/srcs/RepoFS.cpp index b07c95e..edf7d7e 100644 --- a/src/fuse/srcs/RepoFS.cpp +++ b/src/fuse/srcs/RepoFS.cpp @@ -38,7 +38,7 @@ static int rfsGetattr(const char *path, struct stat *stbuf) { e = getf(path); if (e->isFakeDir || e->file->fileType == File::Type::Directory) { stbuf->st_mode = S_IFDIR | 0755; - stbuf->st_nlink = 1; + stbuf->st_nlink = 2; } else if (e->file->fileType == File::Type::Normal) { stbuf->st_mode = S_IFREG | 0444; stbuf->st_nlink = 1; @@ -137,9 +137,9 @@ 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[r.first]); + DirEntry *entry = &(root.children[std::to_string(a.id)]); entry->isFakeDir = true; - entry->name = a.name; + entry->name = std::to_string(a.id); for (auto const &subp: path) { entry = &entry->children[subp]; } diff --git a/tests/clitests/scripts/backup.sh b/tests/clitests/scripts/backup.sh index 41505e0..2ffee4a 100755 --- a/tests/clitests/scripts/backup.sh +++ b/tests/clitests/scripts/backup.sh @@ -120,6 +120,9 @@ AIDS=() OUT=$($CMD list --repo testdir/to1 --password asdff) echo "$OUT" +mkdir testmount +$CMD mount --repo testdir/to1 --password asdff --to testmount & + while IFS= read -r l; do ((i++)) aid=$(echo $l | grep -Eo '[0-9]+' | tail -1) @@ -129,9 +132,16 @@ while IFS= read -r l; do echo "Archive not restored properly!" exit 1 fi + if ! diff --no-dereference -r testmount/$((aid)) testdir/res$((i)); then + echo "Archive not mounted properly!" + exit 1 + fi + echo "Restore $((i)) OK" done <<< "$OUT" +umount testmount + OUT=$($CMD diff --from testdata/4 --repo testdir/to1 --password asdff --progress none --verbose 1 --aid ${AIDS[0]} --aid2 ${AIDS[1]}) echo "$OUT" if ! ( ( echo "$OUT" | grep -q 'c is different' ) && ! ( echo "$OUT" | grep -q 'a is different' ) && ! ( echo "$OUT" | grep -q 'l is different' )\ @@ -290,5 +300,6 @@ echo "Backup 11 ok" rm -rf testdata rm -rf testdir +rm -rf testmount exit 0 \ No newline at end of file