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.
|
2014-05-12 12:41:46 -04:00
|
|
|
*/
|
|
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
#include "fuse_rmdir.hpp"
|
|
|
|
|
|
2014-05-12 12:41:46 -04:00
|
|
|
#include "config.hpp"
|
2016-09-14 08:36:06 -04:00
|
|
|
#include "errno.hpp"
|
2025-07-25 17:53:48 -05:00
|
|
|
#include "error.hpp"
|
2015-09-15 18:49:18 -04:00
|
|
|
#include "fs_path.hpp"
|
2020-06-21 14:45:14 -04:00
|
|
|
#include "fs_rmdir.hpp"
|
|
|
|
|
#include "fs_unlink.hpp"
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2020-12-19 15:06:08 -05:00
|
|
|
#include "fuse.h"
|
2019-01-06 12:52:55 -05:00
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2020-09-13 00:25:24 -04:00
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
static
|
|
|
|
|
int
|
|
|
|
|
_should_unlink(int rv_,
|
|
|
|
|
FollowSymlinks followsymlinks_)
|
|
|
|
|
{
|
|
|
|
|
return ((rv_ == -ENOTDIR) &&
|
|
|
|
|
(followsymlinks_ != FollowSymlinks::ENUM::NEVER));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
int
|
2025-09-17 23:51:16 -04:00
|
|
|
_rmdir_core(const fs::path &basepath_,
|
|
|
|
|
const fs::path &fusepath_,
|
2025-07-25 17:53:48 -05:00
|
|
|
const FollowSymlinks followsymlinks_)
|
|
|
|
|
{
|
|
|
|
|
int rv;
|
2025-09-17 23:51:16 -04:00
|
|
|
fs::path fullpath;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
2025-09-17 23:51:16 -04:00
|
|
|
fullpath = basepath_ / fusepath_;
|
2025-07-25 17:53:48 -05:00
|
|
|
|
|
|
|
|
rv = fs::rmdir(fullpath);
|
|
|
|
|
if(::_should_unlink(rv,followsymlinks_))
|
|
|
|
|
rv = fs::unlink(fullpath);
|
|
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
int
|
|
|
|
|
_rmdir_loop(const std::vector<Branch*> &branches_,
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path &fusepath_,
|
2025-07-25 17:53:48 -05:00
|
|
|
const FollowSymlinks followsymlinks_)
|
2020-09-13 00:25:24 -04:00
|
|
|
{
|
2025-07-25 17:53:48 -05:00
|
|
|
Err err;
|
|
|
|
|
|
2025-08-05 00:39:52 -04:00
|
|
|
for(const auto &branch : branches_)
|
2025-07-25 17:53:48 -05:00
|
|
|
{
|
|
|
|
|
err = ::_rmdir_core(branch->path,fusepath_,followsymlinks_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return err;
|
2020-09-13 00:25:24 -04:00
|
|
|
}
|
|
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
static
|
|
|
|
|
int
|
|
|
|
|
_rmdir(const Policy::Action &actionFunc_,
|
|
|
|
|
const Branches &branches_,
|
|
|
|
|
const FollowSymlinks followsymlinks_,
|
2025-09-17 23:51:16 -04:00
|
|
|
const fs::path &fusepath_)
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
2025-07-25 17:53:48 -05:00
|
|
|
int rv;
|
|
|
|
|
std::vector<Branch*> branches;
|
|
|
|
|
|
|
|
|
|
rv = actionFunc_(branches_,fusepath_,branches);
|
|
|
|
|
if(rv < 0)
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
|
|
return ::_rmdir_loop(branches,fusepath_,followsymlinks_);
|
2016-01-29 16:54:39 -05:00
|
|
|
}
|
|
|
|
|
|
2025-07-25 17:53:48 -05:00
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
FUSE::rmdir(const fuse_req_ctx_t *ctx_,
|
|
|
|
|
const char *fusepath_)
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
const fs::path fusepath{fusepath_};
|
2025-07-25 17:53:48 -05:00
|
|
|
|
2025-09-06 12:03:51 -04:00
|
|
|
return ::_rmdir(cfg.func.rmdir.policy,
|
|
|
|
|
cfg.branches,
|
|
|
|
|
cfg.follow_symlinks,
|
2025-09-17 23:51:16 -04:00
|
|
|
fusepath);
|
2014-05-12 12:41:46 -04:00
|
|
|
}
|