2014-05-12 12:41:46 -04:00
|
|
|
/*
|
2026-02-23 13:22:21 -06:00
|
|
|
ISC License
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
|
2016-01-14 16:50:22 -05:00
|
|
|
|
|
|
|
|
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.
|
2015-12-15 23:52:09 -05:00
|
|
|
*/
|
2014-06-17 19:12:09 -04:00
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
#include "fuse_rename.hpp"
|
|
|
|
|
|
2014-05-12 12:41:46 -04:00
|
|
|
#include "config.hpp"
|
2025-07-25 17:53:48 -05:00
|
|
|
#include "error.hpp"
|
2016-09-14 08:36:06 -04:00
|
|
|
#include "errno.hpp"
|
2015-12-15 23:52:09 -05:00
|
|
|
#include "fs_clonepath.hpp"
|
2020-06-21 14:45:14 -04:00
|
|
|
#include "fs_link.hpp"
|
2025-12-05 21:03:48 -06:00
|
|
|
#include "fs_mkdir_as.hpp"
|
2015-09-15 18:49:18 -04:00
|
|
|
#include "fs_path.hpp"
|
2020-08-17 16:29:22 -04:00
|
|
|
#include "fs_remove.hpp"
|
|
|
|
|
#include "fs_rename.hpp"
|
2020-06-21 14:45:14 -04:00
|
|
|
#include "fs_symlink.hpp"
|
|
|
|
|
#include "fs_unlink.hpp"
|
|
|
|
|
#include "fuse_symlink.hpp"
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2019-09-24 10:27:46 -04:00
|
|
|
#include <algorithm>
|
2025-06-05 23:47:42 -05:00
|
|
|
#include <iostream>
|
2019-09-24 10:27:46 -04:00
|
|
|
#include <string>
|
2020-06-21 14:45:14 -04:00
|
|
|
#include <vector>
|
2019-09-24 10:27:46 -04:00
|
|
|
|
2020-09-13 00:25:24 -04:00
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
static
|
|
|
|
|
bool
|
|
|
|
|
_contains(const std::vector<Branch*> &haystack_,
|
|
|
|
|
const char *needle_)
|
|
|
|
|
{
|
|
|
|
|
for(auto &hay : haystack_)
|
|
|
|
|
{
|
|
|
|
|
if(hay->path == needle_)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
bool
|
|
|
|
|
_contains(const std::vector<Branch*> &haystack_,
|
|
|
|
|
const std::string &needle_)
|
|
|
|
|
{
|
|
|
|
|
return ::_contains(haystack_,needle_.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
void
|
|
|
|
|
_remove(const StrVec &toremove_)
|
2020-09-13 00:25:24 -04:00
|
|
|
{
|
2025-07-25 17:53:48 -05:00
|
|
|
for(auto &path : toremove_)
|
|
|
|
|
fs::remove(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
int
|
2025-09-17 23:51:16 -04:00
|
|
|
_rename_create_path(const Policy::Search &searchPolicy_,
|
Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
const Policy::Action &actionPolicy_,
|
|
|
|
|
const Branches::Ptr branches_,
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path &oldfusepath_,
|
|
|
|
|
const fs::path &newfusepath_)
|
2025-07-25 17:53:48 -05:00
|
|
|
{
|
|
|
|
|
int rv;
|
|
|
|
|
Err err;
|
|
|
|
|
StrVec toremove;
|
|
|
|
|
std::vector<Branch*> newbranches;
|
|
|
|
|
std::vector<Branch*> oldbranches;
|
2025-09-17 23:51:16 -04:00
|
|
|
fs::path oldfullpath;
|
|
|
|
|
fs::path newfullpath;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
rv = actionPolicy_(branches_,oldfusepath_,oldbranches);
|
|
|
|
|
if(rv < 0)
|
|
|
|
|
return rv;
|
FUSE: pass Branches::Ptr by value with empty-branches guards
Previously most FUSE ops took a reference to the live cfg.branches
object. With atomic_load now producing a shared_ptr snapshot, pass
it by value: the op works against a single stable view of the
configuration for its whole lifetime, immune to concurrent
reconfiguration.
Also bail out with -ENOENT when the policy returns an empty branch
set rather than dereferencing branches[0]. This was reachable if a
policy rejected every branch (e.g. everything readonly while
looking for a writable target).
Covers access, chmod, chown, create, getattr, getxattr, ioctl,
link, listxattr, mkdir, mknod, open, readdir (cor/cosr),
readlink, removexattr, rename, rmdir, setxattr, statfs, statx,
symlink, truncate, unlink, utimens.
While here, in _getattr only dereference st_->st_mode when lstat
succeeded (it is otherwise uninitialized).
2026-04-18 00:56:15 -04:00
|
|
|
if(oldbranches.empty())
|
|
|
|
|
return -ENOENT;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
rv = searchPolicy_(branches_,newfusepath_.parent_path(),newbranches);
|
|
|
|
|
if(rv < 0)
|
|
|
|
|
return rv;
|
FUSE: pass Branches::Ptr by value with empty-branches guards
Previously most FUSE ops took a reference to the live cfg.branches
object. With atomic_load now producing a shared_ptr snapshot, pass
it by value: the op works against a single stable view of the
configuration for its whole lifetime, immune to concurrent
reconfiguration.
Also bail out with -ENOENT when the policy returns an empty branch
set rather than dereferencing branches[0]. This was reachable if a
policy rejected every branch (e.g. everything readonly while
looking for a writable target).
Covers access, chmod, chown, create, getattr, getxattr, ioctl,
link, listxattr, mkdir, mknod, open, readdir (cor/cosr),
readlink, removexattr, rename, rmdir, setxattr, statfs, statx,
symlink, truncate, unlink, utimens.
While here, in _getattr only dereference st_->st_mode when lstat
succeeded (it is otherwise uninitialized).
2026-04-18 00:56:15 -04:00
|
|
|
if(newbranches.empty())
|
|
|
|
|
return -ENOENT;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
for(auto &branch : *branches_)
|
|
|
|
|
{
|
2025-10-01 18:47:13 -04:00
|
|
|
newfullpath = branch.path / newfusepath_;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
if(!::_contains(oldbranches,branch.path))
|
|
|
|
|
{
|
|
|
|
|
toremove.push_back(newfullpath);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-01 18:47:13 -04:00
|
|
|
oldfullpath = branch.path / oldfusepath_;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
rv = fs::rename(oldfullpath,newfullpath);
|
|
|
|
|
if(rv < 0)
|
|
|
|
|
{
|
2025-12-05 21:03:48 -06:00
|
|
|
rv = fs::clonepath(newbranches[0]->path,
|
|
|
|
|
branch.path,
|
|
|
|
|
newfusepath_.parent_path());
|
2025-07-25 17:53:48 -05:00
|
|
|
if(rv >= 0)
|
|
|
|
|
rv = fs::rename(oldfullpath,newfullpath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = rv;
|
|
|
|
|
if(rv < 0)
|
|
|
|
|
toremove.push_back(oldfullpath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(err == 0)
|
|
|
|
|
::_remove(toremove);
|
|
|
|
|
|
|
|
|
|
return err;
|
2020-09-13 00:25:24 -04:00
|
|
|
}
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
static
|
|
|
|
|
int
|
2025-09-17 23:51:16 -04:00
|
|
|
_rename_preserve_path(const Policy::Action &actionPolicy_,
|
Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
const Branches::Ptr branches_,
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path &oldfusepath_,
|
|
|
|
|
const fs::path &newfusepath_)
|
2015-08-30 17:10:15 -04:00
|
|
|
{
|
2025-07-25 17:53:48 -05:00
|
|
|
int rv;
|
|
|
|
|
bool success;
|
|
|
|
|
StrVec toremove;
|
|
|
|
|
std::vector<Branch*> oldbranches;
|
2025-09-17 23:51:16 -04:00
|
|
|
fs::path oldfullpath;
|
|
|
|
|
fs::path newfullpath;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
rv = actionPolicy_(branches_,oldfusepath_,oldbranches);
|
|
|
|
|
if(rv < 0)
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
|
|
success = false;
|
|
|
|
|
for(auto &branch : *branches_)
|
|
|
|
|
{
|
2025-10-01 18:47:13 -04:00
|
|
|
newfullpath = branch.path / newfusepath_;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
if(!::_contains(oldbranches,branch.path))
|
|
|
|
|
{
|
|
|
|
|
toremove.push_back(newfullpath);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-01 18:47:13 -04:00
|
|
|
oldfullpath = branch.path / oldfusepath_;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
rv = fs::rename(oldfullpath,newfullpath);
|
|
|
|
|
if(rv < 0)
|
|
|
|
|
{
|
2020-06-21 14:45:14 -04:00
|
|
|
toremove.push_back(oldfullpath);
|
2025-07-25 17:53:48 -05:00
|
|
|
continue;
|
|
|
|
|
}
|
2015-02-24 18:47:31 -05:00
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
success = true;
|
|
|
|
|
}
|
2020-06-21 14:45:14 -04:00
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
// TODO: probably should try to be nuanced here.
|
|
|
|
|
if(success == false)
|
2020-06-21 14:45:14 -04:00
|
|
|
return -EXDEV;
|
2015-12-15 23:52:09 -05:00
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
::_remove(toremove);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
void
|
2025-09-17 23:51:16 -04:00
|
|
|
_rename_exdev_rename_back(const std::vector<Branch*> &branches_,
|
|
|
|
|
const fs::path &oldfusepath_)
|
2025-07-25 17:53:48 -05:00
|
|
|
{
|
2025-09-17 23:51:16 -04:00
|
|
|
fs::path oldpath;
|
|
|
|
|
fs::path newpath;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
for(auto &branch : branches_)
|
|
|
|
|
{
|
|
|
|
|
oldpath = branch->path;
|
|
|
|
|
oldpath /= ".mergerfs_rename_exdev";
|
2025-10-01 18:47:13 -04:00
|
|
|
oldpath /= oldfusepath_;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
newpath = branch->path;
|
2025-10-01 18:47:13 -04:00
|
|
|
newpath /= oldfusepath_;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
fs::rename(oldpath,newpath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
int
|
2025-09-17 23:51:16 -04:00
|
|
|
_rename_exdev_rename_target(const Policy::Action &actionPolicy_,
|
Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
const Branches::Ptr ibranches_,
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path &oldfusepath_,
|
|
|
|
|
std::vector<Branch*> &obranches_)
|
2025-07-25 17:53:48 -05:00
|
|
|
{
|
|
|
|
|
int rv;
|
2025-09-17 23:51:16 -04:00
|
|
|
fs::path clonesrc;
|
2025-10-01 18:47:13 -04:00
|
|
|
fs::path clonedst;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
rv = actionPolicy_(ibranches_,oldfusepath_,obranches_);
|
|
|
|
|
if(rv < 0)
|
2020-06-21 14:45:14 -04:00
|
|
|
return rv;
|
|
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
for(auto &branch : obranches_)
|
|
|
|
|
{
|
|
|
|
|
clonesrc = branch->path;
|
2025-10-01 18:47:13 -04:00
|
|
|
clonedst = branch->path;
|
|
|
|
|
clonedst /= ".mergerfs_rename_exdev";
|
2025-07-25 17:53:48 -05:00
|
|
|
|
2025-10-01 18:47:13 -04:00
|
|
|
rv = fs::clonepath(clonesrc,clonedst,oldfusepath_.parent_path());
|
2025-07-25 17:53:48 -05:00
|
|
|
if(rv == -ENOENT)
|
|
|
|
|
{
|
2025-12-05 21:03:48 -06:00
|
|
|
fs::mkdir_as({0,0},clonedst,01777);
|
2025-10-01 18:47:13 -04:00
|
|
|
rv = fs::clonepath(clonesrc,clonedst,oldfusepath_.parent_path());
|
2025-07-25 17:53:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(rv < 0)
|
|
|
|
|
goto error;
|
|
|
|
|
|
2025-10-01 18:47:13 -04:00
|
|
|
clonesrc /= oldfusepath_;
|
|
|
|
|
clonedst /= oldfusepath_;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
2025-10-01 18:47:13 -04:00
|
|
|
rv = fs::rename(clonesrc,clonedst);
|
2025-07-25 17:53:48 -05:00
|
|
|
if(rv < 0)
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
::_rename_exdev_rename_back(obranches_,oldfusepath_);
|
|
|
|
|
|
|
|
|
|
return -EXDEV;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
_rename_exdev_rel_symlink(const fuse_req_ctx_t *ctx_,
|
Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
const Policy::Action &actionPolicy_,
|
|
|
|
|
const Branches::Ptr branches_,
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path &oldfusepath_,
|
|
|
|
|
const fs::path &newfusepath_)
|
2025-07-25 17:53:48 -05:00
|
|
|
{
|
|
|
|
|
int rv;
|
2025-09-17 23:51:16 -04:00
|
|
|
fs::path target;
|
|
|
|
|
fs::path linkpath;
|
2025-07-25 17:53:48 -05:00
|
|
|
std::vector<Branch*> branches;
|
|
|
|
|
|
|
|
|
|
rv = ::_rename_exdev_rename_target(actionPolicy_,branches_,oldfusepath_,branches);
|
|
|
|
|
if(rv < 0)
|
2020-06-21 14:45:14 -04:00
|
|
|
return rv;
|
|
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
linkpath = newfusepath_;
|
|
|
|
|
target = "/.mergerfs_rename_exdev";
|
2025-10-01 18:47:13 -04:00
|
|
|
target /= oldfusepath_;
|
2025-07-25 17:53:48 -05:00
|
|
|
target = target.lexically_relative(linkpath.parent_path());
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
rv = FUSE::symlink(ctx_,target.c_str(),linkpath);
|
2025-07-25 17:53:48 -05:00
|
|
|
if(rv < 0)
|
|
|
|
|
::_rename_exdev_rename_back(branches,oldfusepath_);
|
|
|
|
|
|
|
|
|
|
return rv;
|
2014-05-12 12:41:46 -04:00
|
|
|
}
|
|
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
static
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
_rename_exdev_abs_symlink(const fuse_req_ctx_t *ctx_,
|
Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
const Policy::Action &actionPolicy_,
|
|
|
|
|
const Branches::Ptr branches_,
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path &mount_,
|
|
|
|
|
const fs::path &oldfusepath_,
|
|
|
|
|
const fs::path &newfusepath_)
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
2025-07-25 17:53:48 -05:00
|
|
|
int rv;
|
2025-09-17 23:51:16 -04:00
|
|
|
fs::path target;
|
|
|
|
|
fs::path linkpath;
|
2025-07-25 17:53:48 -05:00
|
|
|
std::vector<Branch*> branches;
|
2020-06-21 14:45:14 -04:00
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
rv = ::_rename_exdev_rename_target(actionPolicy_,branches_,oldfusepath_,branches);
|
|
|
|
|
if(rv < 0)
|
2020-06-21 14:45:14 -04:00
|
|
|
return rv;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
linkpath = newfusepath_;
|
|
|
|
|
target = mount_;
|
|
|
|
|
target /= ".mergerfs_rename_exdev";
|
2025-10-01 18:47:13 -04:00
|
|
|
target /= oldfusepath_;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
rv = FUSE::symlink(ctx_,target.c_str(),linkpath);
|
2025-07-25 17:53:48 -05:00
|
|
|
if(rv < 0)
|
|
|
|
|
::_rename_exdev_rename_back(branches,oldfusepath_);
|
|
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
_rename_exdev(const fuse_req_ctx_t *ctx_,
|
|
|
|
|
const fs::path &oldfusepath_,
|
|
|
|
|
const fs::path &newfusepath_)
|
2025-07-25 17:53:48 -05:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
switch(cfg.rename_exdev)
|
2025-07-25 17:53:48 -05:00
|
|
|
{
|
|
|
|
|
case RenameEXDEV::ENUM::PASSTHROUGH:
|
|
|
|
|
return -EXDEV;
|
|
|
|
|
case RenameEXDEV::ENUM::REL_SYMLINK:
|
2025-10-13 00:21:36 -04:00
|
|
|
return ::_rename_exdev_rel_symlink(ctx_,
|
|
|
|
|
cfg.func.rename.policy,
|
|
|
|
|
cfg.branches,
|
2025-07-25 17:53:48 -05:00
|
|
|
oldfusepath_,
|
|
|
|
|
newfusepath_);
|
|
|
|
|
case RenameEXDEV::ENUM::ABS_SYMLINK:
|
2025-10-13 00:21:36 -04:00
|
|
|
return ::_rename_exdev_abs_symlink(ctx_,
|
|
|
|
|
cfg.func.rename.policy,
|
|
|
|
|
cfg.branches,
|
|
|
|
|
cfg.mountpoint,
|
2025-07-25 17:53:48 -05:00
|
|
|
oldfusepath_,
|
|
|
|
|
newfusepath_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -EXDEV;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
_rename(const fs::path &oldpath_,
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path &newpath_)
|
2025-07-25 17:53:48 -05:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
if(cfg.func.create.policy.path_preserving() && !cfg.ignorepponrename)
|
|
|
|
|
return ::_rename_preserve_path(cfg.func.rename.policy,
|
|
|
|
|
cfg.branches,
|
2025-07-25 17:53:48 -05:00
|
|
|
oldpath_,
|
|
|
|
|
newpath_);
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
return ::_rename_create_path(cfg.func.getattr.policy,
|
|
|
|
|
cfg.func.rename.policy,
|
|
|
|
|
cfg.branches,
|
2025-07-25 17:53:48 -05:00
|
|
|
oldpath_,
|
|
|
|
|
newpath_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
FUSE::rename(const fuse_req_ctx_t *ctx_,
|
|
|
|
|
const char *oldfusepath_,
|
|
|
|
|
const char *newfusepath_)
|
2025-07-25 17:53:48 -05:00
|
|
|
{
|
|
|
|
|
int rv;
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path oldfusepath{oldfusepath_};
|
|
|
|
|
const fs::path newfusepath{newfusepath_};
|
2025-07-25 17:53:48 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
rv = ::_rename(oldfusepath,newfusepath);
|
2025-07-25 17:53:48 -05:00
|
|
|
if(rv == -EXDEV)
|
2025-10-13 00:21:36 -04:00
|
|
|
return ::_rename_exdev(ctx_,oldfusepath,newfusepath);
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
return rv;
|
2014-05-12 12:41:46 -04:00
|
|
|
}
|