Skip to content

Commit

Permalink
Do not count usage on root path (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben RUBSON authored and rfjakob committed Mar 17, 2018
1 parent 6567b82 commit 8caea46
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
11 changes: 10 additions & 1 deletion encfs/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ EncFS_Context::~EncFS_Context() {
// release all entries from map
openFiles.clear();
}

std::shared_ptr<DirNode> EncFS_Context::getRoot(int *errCode) {
return getRoot(errCode, false);
}

std::shared_ptr<DirNode> EncFS_Context::getRoot(int *errCode, bool skipUsageCount) {
std::shared_ptr<DirNode> ret = nullptr;
do {
{
Expand All @@ -57,7 +62,11 @@ std::shared_ptr<DirNode> EncFS_Context::getRoot(int *errCode) {
break;
}
ret = root;
++usageCount;
// On some system, stat of "/" is allowed even if the calling user is
// not allowed to list / to go deeper. Do not then count this call.
if (!skipUsageCount) {
++usageCount;
}
}

if (!ret) {
Expand Down
1 change: 1 addition & 0 deletions encfs/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class EncFS_Context {

void setRoot(const std::shared_ptr<DirNode> &root);
std::shared_ptr<DirNode> getRoot(int *err);
std::shared_ptr<DirNode> getRoot(int *err, bool skipUsageCount);

std::shared_ptr<EncFS_Args> args;
std::shared_ptr<EncFS_Opts> opts;
Expand Down
6 changes: 5 additions & 1 deletion encfs/encfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ static int withFileNode(const char *opName, const char *path,
EncFS_Context *ctx = context();

int res = -EIO;
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
bool skipUsageCount = false;
if (strlen(path) == 1) {
skipUsageCount = true;
}
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res, skipUsageCount);
if (!FSRoot) {
return res;
}
Expand Down

0 comments on commit 8caea46

Please sign in to comment.