Do not count usage on root path (#471)

This commit is contained in:
Ben RUBSON 2018-03-17 16:18:03 +01:00 committed by rfjakob
parent 6567b82822
commit 8caea461a7
3 changed files with 16 additions and 2 deletions

View File

@ -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 {
{
@ -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) {

View File

@ -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;

View File

@ -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;
}