Windows: tree walk ends error if share discon. detected: no purge will be performed

This commit is contained in:
Jean-Francois Dockes 2019-09-01 08:45:21 +02:00
parent 85a3291fd7
commit c1d593b104

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2004 J.F.Dockes /* Copyright (C) 2004-2019 J.F.Dockes
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
@ -52,8 +52,7 @@ public:
dev_t dev; dev_t dev;
ino_t ino; ino_t ino;
DirId(dev_t d, ino_t i) : dev(d), ino(i) {} DirId(dev_t d, ino_t i) : dev(d), ino(i) {}
bool operator<(const DirId& r) const bool operator<(const DirId& r) const {
{
return dev < r.dev || (dev == r.dev && ino < r.ino); return dev < r.dev || (dev == r.dev && ino < r.ino);
} }
}; };
@ -362,7 +361,6 @@ FsTreeWalker::Status FsTreeWalker::iwalk(const string &top,
return status; return status;
} }
int curdepth = slashcount(top) - data->basedepth; int curdepth = slashcount(top) - data->basedepth;
if (data->maxdepth >= 0 && curdepth >= data->maxdepth) { if (data->maxdepth >= 0 && curdepth >= data->maxdepth) {
LOGDEB1("FsTreeWalker::iwalk: Maxdepth reached: [" << (top) << "]\n" ); LOGDEB1("FsTreeWalker::iwalk: Maxdepth reached: [" << (top) << "]\n" );
@ -388,10 +386,21 @@ FsTreeWalker::Status FsTreeWalker::iwalk(const string &top,
data->donedirs.insert(dirid); data->donedirs.insert(dirid);
} }
#endif #endif
SYSPATH(top, systop); SYSPATH(top, systop);
DIRHDL *d = OPENDIR(systop); DIRHDL *d = OPENDIR(systop);
if (d == 0) { if (nullptr == d) {
data->logsyserr("opendir", top); data->logsyserr("opendir", top);
#ifdef _WIN32
int rc = GetLastError();
LOGERR("opendir failed: LastError " << rc << endl);
if (rc == ERROR_NETNAME_DELETED) {
// 64: share disconnected.
// Not too sure of the errno in this case.
// Make sure it's not one of the permissible ones
errno = ENODEV;
}
#endif
switch (errno) { switch (errno) {
case EPERM: case EPERM:
case EACCES: case EACCES:
@ -400,6 +409,7 @@ FsTreeWalker::Status FsTreeWalker::iwalk(const string &top,
// We get this quite a lot, don't know why. To be checked. // We get this quite a lot, don't know why. To be checked.
case EINVAL: case EINVAL:
#endif #endif
// No error set: indexing will continue in other directories
goto out; goto out;
default: default:
status = FtwError; status = FtwError;
@ -408,7 +418,7 @@ FsTreeWalker::Status FsTreeWalker::iwalk(const string &top,
} }
struct DIRENT *ent; struct DIRENT *ent;
while ((ent = READDIR(d)) != 0) { while (errno = 0, ((ent = READDIR(d)) != 0)) {
string fn; string fn;
struct stat st; struct stat st;
#ifdef _WIN32 #ifdef _WIN32
@ -437,6 +447,14 @@ FsTreeWalker::Status FsTreeWalker::iwalk(const string &top,
int statret = path_fileprops(fn.c_str(), &st, data->options&FtwFollow); int statret = path_fileprops(fn.c_str(), &st, data->options&FtwFollow);
if (statret == -1) { if (statret == -1) {
data->logsyserr("stat", fn); data->logsyserr("stat", fn);
#ifdef _WIN32
int rc = GetLastError();
LOGERR("stat failed: LastError " << rc << endl);
if (rc == ERROR_NETNAME_DELETED) {
status = FtwError;
goto out;
}
#endif
continue; continue;
} }
@ -493,6 +511,18 @@ FsTreeWalker::Status FsTreeWalker::iwalk(const string &top,
} }
// We ignore other file types (devices etc...) // We ignore other file types (devices etc...)
} // readdir loop } // readdir loop
if (errno) {
// Actual readdir error, not eof.
data->logsyserr("readdir", top);
#ifdef _WIN32
int rc = GetLastError();
LOGERR("Readdir failed: LastError " << rc << endl);
if (rc == ERROR_NETNAME_DELETED) {
status = FtwError;
goto out;
}
#endif
}
out: out:
if (d) if (d)