mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-03 05:10:14 -05:00
check metadata on chown/chmod errors when cloning
This commit is contained in:
parent
899670bc93
commit
492d895632
4 changed files with 125 additions and 4 deletions
|
|
@ -25,6 +25,8 @@
|
|||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "fs_base_stat.hpp"
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
|
|
@ -56,6 +58,15 @@ namespace fs
|
|||
return ::lchown(path.c_str(),uid,gid);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
lchown(const std::string &path,
|
||||
const struct stat &st)
|
||||
{
|
||||
return fs::lchown(path,st.st_uid,st.st_gid);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
|
|
@ -74,6 +85,60 @@ namespace fs
|
|||
{
|
||||
return fs::fchown(fd,st.st_uid,st.st_gid);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
lchown_check_on_error(const std::string &path,
|
||||
const struct stat &st)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = fs::lchown(path,st);
|
||||
if(rv == -1)
|
||||
{
|
||||
int error;
|
||||
struct stat tmpst;
|
||||
|
||||
error = errno;
|
||||
rv = fs::lstat(path,tmpst);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
if((st.st_uid != tmpst.st_uid) ||
|
||||
(st.st_gid != tmpst.st_gid))
|
||||
return (errno=error,-1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
fchown_check_on_error(const int fd,
|
||||
const struct stat &st)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = fs::fchown(fd,st);
|
||||
if(rv == -1)
|
||||
{
|
||||
int error;
|
||||
struct stat tmpst;
|
||||
|
||||
error = errno;
|
||||
rv = fs::fstat(fd,tmpst);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
if((st.st_uid != tmpst.st_uid) ||
|
||||
(st.st_gid != tmpst.st_gid))
|
||||
return (errno=error,-1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue