mirror of https://github.com/trapexit/mergerfs.git
5 changed files with 179 additions and 0 deletions
-
9src/follow_symlinks_enum.hpp
-
70src/fs_stat.cpp
-
35src/func_getattr_base.hpp
-
42src/func_getattr_ff.cpp
-
23src/func_getattr_ff.hpp
@ -0,0 +1,9 @@ |
|||
#pragma once
|
|||
|
|||
enum class FollowSymlinksEnum |
|||
{ |
|||
NEVER, |
|||
DIRECTORY, |
|||
REGULAR, |
|||
ALL |
|||
}; |
|||
@ -0,0 +1,70 @@ |
|||
#include "fs_stat.hpp"
|
|||
#include "fs_lstat.hpp"
|
|||
|
|||
static |
|||
void |
|||
_set_stat_if_leads_to_dir(const char *path_, |
|||
struct stat *st_) |
|||
{ |
|||
int rv; |
|||
struct stat st; |
|||
|
|||
rv = fs::stat(path_,&st); |
|||
if(rv < 0) |
|||
return; |
|||
|
|||
if(S_ISDIR(st.st_mode)) |
|||
*st_ = st; |
|||
|
|||
return; |
|||
} |
|||
|
|||
static |
|||
void |
|||
_set_stat_if_leads_to_reg(const char *path_, |
|||
struct stat *st_) |
|||
{ |
|||
int rv; |
|||
struct stat st; |
|||
|
|||
rv = fs::stat(path_,&st); |
|||
if(rv < 0) |
|||
return; |
|||
|
|||
if(S_ISREG(st.st_mode)) |
|||
*st_ = st; |
|||
|
|||
return; |
|||
} |
|||
|
|||
int |
|||
fs::stat(const char *path_, |
|||
struct stat *st_, |
|||
FollowSymlinksEnum follow_) |
|||
{ |
|||
int rv; |
|||
|
|||
switch(follow_) |
|||
{ |
|||
case FollowSymlinksEnum::NEVER: |
|||
rv = fs::lstat(path_,st_); |
|||
break; |
|||
case FollowSymlinksEnum::DIRECTORY: |
|||
rv = fs::lstat(path_,st_); |
|||
if(S_ISLNK(st_->st_mode)) |
|||
_set_stat_if_leads_to_dir(path_,st_); |
|||
break; |
|||
case FollowSymlinksEnum::REGULAR: |
|||
rv = fs::lstat(path_,st_); |
|||
if(S_ISLNK(st_->st_mode)) |
|||
_set_stat_if_leads_to_reg(path_,st_); |
|||
break; |
|||
case FollowSymlinksEnum::ALL: |
|||
rv = fs::stat(path_,st_); |
|||
if(rv != 0) |
|||
rv = fs::lstat(path_,st_); |
|||
break; |
|||
} |
|||
|
|||
return rv; |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
#pragma once
|
|||
|
|||
#include "follow_symlinks_enum.hpp"
|
|||
|
|||
#include "fs_path.hpp"
|
|||
#include "branches.hpp"
|
|||
#include "int_types.h"
|
|||
|
|||
#include "fuse.h"
|
|||
|
|||
#include <string_view>
|
|||
|
|||
#include <sys/types.h>
|
|||
#include <sys/stat.h>
|
|||
#include <unistd.h>
|
|||
|
|||
namespace Func2 |
|||
{ |
|||
class GetAttrBase |
|||
{ |
|||
public: |
|||
GetAttrBase() {} |
|||
~GetAttrBase() {} |
|||
|
|||
public: |
|||
virtual std::string_view name() const = 0; |
|||
|
|||
public: |
|||
virtual int operator()(const Branches &branches, |
|||
const fs::path &fusepath, |
|||
struct stat *st, |
|||
const FollowSymlinksEnum follow_symlinks, |
|||
const s64 symlinkify_timeout) = 0; |
|||
}; |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
#include "func_getattr_ff.hpp"
|
|||
|
|||
#include "fs_stat.hpp"
|
|||
#include "fs_inode.hpp"
|
|||
#include "symlinkify.hpp"
|
|||
|
|||
|
|||
std::string_view |
|||
Func2::GetAttrFF::name() const |
|||
{ |
|||
return "ff"; |
|||
} |
|||
|
|||
int |
|||
Func2::GetAttrFF::operator()(const Branches &branches_, |
|||
const fs::path &fusepath_, |
|||
struct stat *st_, |
|||
const FollowSymlinksEnum follow_symlinks_, |
|||
const s64 symlinkify_timeout_) |
|||
{ |
|||
int rv; |
|||
fs::path fullpath; |
|||
|
|||
for(const auto &branch : branches_) |
|||
{ |
|||
fullpath = branch.path; |
|||
fullpath += fusepath_; |
|||
rv = fs::stat(fullpath.string(),st_,follow_symlinks_); |
|||
if(rv != 0) |
|||
continue; |
|||
|
|||
symlinkify::convert_if_can_be_symlink(fullpath, |
|||
st_, |
|||
symlinkify_timeout_); |
|||
|
|||
fs::inode::calc(branch.path,fusepath_.string(),st_); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
return -ENOENT; |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
#pragma once
|
|||
|
|||
#include "func_getattr_base.hpp"
|
|||
|
|||
namespace Func2 |
|||
{ |
|||
class GetAttrFF : public GetAttrBase |
|||
{ |
|||
public: |
|||
GetAttrFF() {} |
|||
~GetAttrFF() {} |
|||
|
|||
public: |
|||
std::string_view name() const; |
|||
|
|||
public: |
|||
int operator()(const Branches &branches, |
|||
const fs::path &fusepath, |
|||
struct stat *st, |
|||
const FollowSymlinksEnum follow_symlinks, |
|||
const s64 symlinkify_timeout); |
|||
}; |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue