make all ENOENT errors non-fatal: files and dirs disappear. Reset error string when it is retrieved to avoid accumulating memory in long-running programs

This commit is contained in:
Jean-Francois Dockes 2011-10-14 14:05:33 +02:00
parent ccd58e0843
commit 6d82d83037

View File

@ -99,7 +99,10 @@ void FsTreeWalker::setOpts(Options opts, int depthswitch)
string FsTreeWalker::getReason() string FsTreeWalker::getReason()
{ {
return data->reason.str(); string reason = data->reason.str();
data->reason.str(string());
data->errors = 0;
return reason;
} }
int FsTreeWalker::getErrCnt() int FsTreeWalker::getErrCnt()
@ -198,8 +201,10 @@ FsTreeWalker::Status FsTreeWalker::walk(const string& _top,
struct stat st; struct stat st;
// We always follow symlinks at this point. Makes more sense. // We always follow symlinks at this point. Makes more sense.
if (stat(top.c_str(), &st) == -1) { if (stat(top.c_str(), &st) == -1) {
// Note that we do not return an error if the stat call
// fails. A temp file may have gone away.
data->logsyserr("stat", top); data->logsyserr("stat", top);
return FtwError; return errno == ENOENT ? FtwOk : FtwError;
} }
// Recursive version, using the call stack to store state. iwalk // Recursive version, using the call stack to store state. iwalk
@ -259,7 +264,7 @@ FsTreeWalker::Status FsTreeWalker::walk(const string& _top,
if (!nfather.empty()) { if (!nfather.empty()) {
if (stat(nfather.c_str(), &st) == -1) { if (stat(nfather.c_str(), &st) == -1) {
data->logsyserr("stat", nfather); data->logsyserr("stat", nfather);
return FtwError; return errno == ENOENT ? FtwOk : FtwError;
} }
if ((status = cb.processone(nfather, &st, FtwDirReturn)) & if ((status = cb.processone(nfather, &st, FtwDirReturn)) &
(FtwStop|FtwError)) { (FtwStop|FtwError)) {
@ -269,7 +274,7 @@ FsTreeWalker::Status FsTreeWalker::walk(const string& _top,
if (stat(dir.c_str(), &st) == -1) { if (stat(dir.c_str(), &st) == -1) {
data->logsyserr("stat", dir); data->logsyserr("stat", dir);
return FtwError; return errno == ENOENT ? FtwOk : FtwError;
} }
// iwalk will not recurse in this case, just process file entries // iwalk will not recurse in this case, just process file entries
// and append subdir entries to the list. // and append subdir entries to the list.
@ -326,6 +331,7 @@ FsTreeWalker::Status FsTreeWalker::iwalk(const string &top,
switch (errno) { switch (errno) {
case EPERM: case EPERM:
case EACCES: case EACCES:
case ENOENT:
goto out; goto out;
default: default:
status = FtwError; status = FtwError;