diff --git a/src/config.cpp b/src/config.cpp index 265b7d47..012194c9 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -30,7 +30,7 @@ #include -constexpr static const char CACHE_FILES_PROCESS_NAMES_DEFAULT[] = +constexpr const char CACHE_FILES_PROCESS_NAMES_DEFAULT[] = "rtorrent|" "qbittorrent-nox"; diff --git a/src/fs_is_same_file.hpp b/src/fs_is_same_file.hpp new file mode 100644 index 00000000..4b3bfb99 --- /dev/null +++ b/src/fs_is_same_file.hpp @@ -0,0 +1,62 @@ +/* + ISC License + + Copyright (c) 2026, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#pragma once + +#include "to_neg_errno.hpp" + +#include + +#include +#include + + +namespace fs +{ + static + inline + int + is_same_file(const char *a_, + const char *b_) + { + int rv_a; + int rv_b; + struct stat st_a; + struct stat st_b; + + rv_a = ::lstat(a_,&st_a); + rv_b = ::lstat(b_,&st_b); + + if(rv_a < 0 || rv_b < 0) + return -errno; + if(st_a.st_dev != st_b.st_dev || st_a.st_ino != st_b.st_ino) + return 0; + + return 1; + } + + static + inline + int + is_same_file(const std::string &a_, + const std::string &b_) + { + return fs::is_same_file(a_.c_str(), + b_.c_str()); + } +} diff --git a/src/mergerfs_fsck.cpp b/src/mergerfs_fsck.cpp index 83e7ef9b..73f9c208 100644 --- a/src/mergerfs_fsck.cpp +++ b/src/mergerfs_fsck.cpp @@ -20,6 +20,7 @@ #include "fs_close.hpp" #include "fs_copyfile.hpp" +#include "fs_is_same_file.hpp" #include "fs_lchmod.hpp" #include "fs_lchown.hpp" #include "fs_lgetxattr.hpp" @@ -246,10 +247,10 @@ _copy_files(const std::string &src_, { int rv; - // TODO: Additional protection to confirm not the literal same - // file. fs::is_same_file(src,dst); if(src_ == dst.path) continue; + if(fs::is_same_file(src_,dst.path) == 1) + continue; rv = fs::copyfile(src_,dst.path,{.cleanup_failure=false}); if(rv < 0)