From 660f556ac67c57d64ff993d801616de0f0334496 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Wed, 29 Apr 2026 09:19:28 -0500 Subject: [PATCH] Don't return success on ENOTEMPTY rmdir errors --- src/fuse_rmdir.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/fuse_rmdir.cpp b/src/fuse_rmdir.cpp index e6fcbd53..ccecd2dc 100644 --- a/src/fuse_rmdir.cpp +++ b/src/fuse_rmdir.cpp @@ -20,7 +20,6 @@ #include "config.hpp" #include "errno.hpp" -#include "error.hpp" #include "fs_path.hpp" #include "fs_rmdir.hpp" #include "fs_unlink.hpp" @@ -31,6 +30,51 @@ #include +// 1. First error sets the initial value +// 2. If we get -EEXIST or -ENOTEMPTY, it takes priority (overwrites anything) +// 3. If we already have -EEXIST or -ENOTEMPTY, keep them (don't overwrite) +// 4. Success (>= 0) only sets to 0 if we don't have a priority error +// 5. Any other error only overwrites if we don't have a priority error +struct RmdirErr +{ +private: + std::optional _err; + +public: + RmdirErr() + { + } + + operator int() + { + return (_err.has_value() ? _err.value() : -ENOENT); + } + + RmdirErr& + operator=(int v_) + { + if(!_err.has_value()) + _err = ((v_ >= 0) ? 0 : v_); + else if((v_ == -EEXIST) || (v_ == -ENOTEMPTY)) + _err = v_; + else if((*_err == -EEXIST) || (*_err == -ENOTEMPTY)) + ; + else if(v_ >= 0) + _err = 0; + else + _err = v_; + + return *this; + } + + bool + operator==(int v_) + { + if(_err.has_value()) + return (_err.value() == v_); + return false; + } +}; static int @@ -65,7 +109,7 @@ _rmdir_loop(const std::vector &branches_, const fs::path &fusepath_, const FollowSymlinks followsymlinks_) { - Err err; + RmdirErr err; for(const auto &branch : branches_) {