mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-26 19:01:56 -04:00
Better same file check for fsck
This commit is contained in:
parent
1a8eb326af
commit
e613d9415f
3 changed files with 66 additions and 3 deletions
|
|
@ -30,7 +30,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
constexpr static const char CACHE_FILES_PROCESS_NAMES_DEFAULT[] =
|
constexpr const char CACHE_FILES_PROCESS_NAMES_DEFAULT[] =
|
||||||
"rtorrent|"
|
"rtorrent|"
|
||||||
"qbittorrent-nox";
|
"qbittorrent-nox";
|
||||||
|
|
||||||
|
|
|
||||||
62
src/fs_is_same_file.hpp
Normal file
62
src/fs_is_same_file.hpp
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
ISC License
|
||||||
|
|
||||||
|
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||||
|
|
||||||
|
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 <string>
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include "fs_close.hpp"
|
#include "fs_close.hpp"
|
||||||
#include "fs_copyfile.hpp"
|
#include "fs_copyfile.hpp"
|
||||||
|
#include "fs_is_same_file.hpp"
|
||||||
#include "fs_lchmod.hpp"
|
#include "fs_lchmod.hpp"
|
||||||
#include "fs_lchown.hpp"
|
#include "fs_lchown.hpp"
|
||||||
#include "fs_lgetxattr.hpp"
|
#include "fs_lgetxattr.hpp"
|
||||||
|
|
@ -246,10 +247,10 @@ _copy_files(const std::string &src_,
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
// TODO: Additional protection to confirm not the literal same
|
|
||||||
// file. fs::is_same_file(src,dst);
|
|
||||||
if(src_ == dst.path)
|
if(src_ == dst.path)
|
||||||
continue;
|
continue;
|
||||||
|
if(fs::is_same_file(src_,dst.path) == 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
rv = fs::copyfile(src_,dst.path,{.cleanup_failure=false});
|
rv = fs::copyfile(src_,dst.path,{.cleanup_failure=false});
|
||||||
if(rv < 0)
|
if(rv < 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue