Browse Source

Merge pull request #549 from trapexit/cow

optimize link_cow eligibility check
pull/552/head
trapexit 6 years ago
committed by GitHub
parent
commit
adcbf0eef0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      src/fs_cow.cpp
  2. 3
      src/fs_cow.hpp

23
src/fs_cow.cpp

@ -60,13 +60,23 @@ namespace fs
{ {
namespace cow namespace cow
{ {
bool
is_eligible(const int flags_)
{
return ((flags_ & O_RDWR) || (flags_ & O_WRONLY));
}
bool
is_eligible(const struct stat &st_)
{
return ((S_ISREG(st_.st_mode)) && (st_.st_nlink > 1));
}
bool bool
is_eligible(const int flags_, is_eligible(const int flags_,
const struct stat &st_) const struct stat &st_)
{ {
return (((flags_ & O_RDWR) || (flags_ & O_WRONLY)) &&
(S_ISREG(st_.st_mode)) &&
(st_.st_nlink > 1));
return (is_eligible(flags_) && is_eligible(st_));
} }
bool bool
@ -76,11 +86,14 @@ namespace fs
int rv; int rv;
struct stat st; struct stat st;
rv = fs::stat(fullpath_,st);
if(!is_eligible(flags_))
return false;
rv = fs::lstat(fullpath_,st);
if(rv == -1) if(rv == -1)
return false; return false;
return fs::cow::is_eligible(flags_,st);
return fs::cow::is_eligible(st);
} }
int int

3
src/fs_cow.hpp

@ -25,7 +25,10 @@ namespace fs
{ {
namespace cow namespace cow
{ {
bool is_eligible(const int flags_);
bool is_eligible(const struct stat &st_);
bool is_eligible(const int flags_, const struct stat &st_); bool is_eligible(const int flags_, const struct stat &st_);
bool is_eligible(const char *fullpath_, const int flags_); bool is_eligible(const char *fullpath_, const int flags_);
int break_link(const char *fullpath_); int break_link(const char *fullpath_);

Loading…
Cancel
Save