|
a/src/utils/fstreewalk.cpp |
|
b/src/utils/fstreewalk.cpp |
|
... |
|
... |
19 |
|
19 |
|
20 |
#ifndef TEST_FSTREEWALK
|
20 |
#ifndef TEST_FSTREEWALK
|
21 |
|
21 |
|
22 |
#include <stdio.h>
|
22 |
#include <stdio.h>
|
23 |
#include <dirent.h>
|
23 |
#include <dirent.h>
|
24 |
#include <sys/stat.h>
|
|
|
25 |
#include <errno.h>
|
24 |
#include <errno.h>
|
26 |
#include <fnmatch.h>
|
25 |
#include <fnmatch.h>
|
27 |
#include "safesysstat.h"
|
26 |
#include "safesysstat.h"
|
28 |
#include <cstring>
|
27 |
#include <cstring>
|
29 |
#include <algorithm>
|
28 |
#include <algorithm>
|
|
... |
|
... |
224 |
}
|
223 |
}
|
225 |
|
224 |
|
226 |
data->basedepth = slashcount(top); // Only used for breadthxx
|
225 |
data->basedepth = slashcount(top); // Only used for breadthxx
|
227 |
struct stat st;
|
226 |
struct stat st;
|
228 |
// We always follow symlinks at this point. Makes more sense.
|
227 |
// We always follow symlinks at this point. Makes more sense.
|
229 |
if (stat(top.c_str(), &st) == -1) {
|
228 |
if (path_fileprops(top, &st) == -1) {
|
230 |
// Note that we do not return an error if the stat call
|
229 |
// Note that we do not return an error if the stat call
|
231 |
// fails. A temp file may have gone away.
|
230 |
// fails. A temp file may have gone away.
|
232 |
data->logsyserr("stat", top);
|
231 |
data->logsyserr("stat", top);
|
233 |
return errno == ENOENT ? FtwOk : FtwError;
|
232 |
return errno == ENOENT ? FtwOk : FtwError;
|
234 |
}
|
233 |
}
|
|
... |
|
... |
286 |
}
|
285 |
}
|
287 |
}
|
286 |
}
|
288 |
|
287 |
|
289 |
// If changing parent directory, advise our user.
|
288 |
// If changing parent directory, advise our user.
|
290 |
if (!nfather.empty()) {
|
289 |
if (!nfather.empty()) {
|
291 |
if (stat(nfather.c_str(), &st) == -1) {
|
290 |
if (path_fileprops(nfather, &st) == -1) {
|
292 |
data->logsyserr("stat", nfather);
|
291 |
data->logsyserr("stat", nfather);
|
293 |
return errno == ENOENT ? FtwOk : FtwError;
|
292 |
return errno == ENOENT ? FtwOk : FtwError;
|
294 |
}
|
293 |
}
|
295 |
if ((status = cb.processone(nfather, &st, FtwDirReturn)) &
|
294 |
if ((status = cb.processone(nfather, &st, FtwDirReturn)) &
|
296 |
(FtwStop|FtwError)) {
|
295 |
(FtwStop|FtwError)) {
|
297 |
return status;
|
296 |
return status;
|
298 |
}
|
297 |
}
|
299 |
}
|
298 |
}
|
300 |
|
299 |
|
301 |
if (stat(dir.c_str(), &st) == -1) {
|
300 |
if (path_fileprops(dir, &st) == -1) {
|
302 |
data->logsyserr("stat", dir);
|
301 |
data->logsyserr("stat", dir);
|
303 |
return errno == ENOENT ? FtwOk : FtwError;
|
302 |
return errno == ENOENT ? FtwOk : FtwError;
|
304 |
}
|
303 |
}
|
305 |
// iwalk will not recurse in this case, just process file entries
|
304 |
// iwalk will not recurse in this case, just process file entries
|
306 |
// and append subdir entries to the queue.
|
305 |
// and append subdir entries to the queue.
|
|
... |
|
... |
395 |
continue;
|
394 |
continue;
|
396 |
}
|
395 |
}
|
397 |
|
396 |
|
398 |
fn = path_cat(top, ent->d_name);
|
397 |
fn = path_cat(top, ent->d_name);
|
399 |
#ifdef _WIN32
|
398 |
#ifdef _WIN32
|
400 |
// readdir gets the useful attrs, no inode indirection on windows
|
399 |
// readdir gets the useful attrs, no inode indirection on windows,
|
|
|
400 |
// spare the path_fileprops() call, but make sure we mimick it.
|
401 |
memset(&st, 0, sizeof(st));
|
401 |
memset(&st, 0, sizeof(st));
|
402 |
st.st_mtime = ent->d_mtime;
|
402 |
st.st_mtime = ent->d_mtime;
|
403 |
st.st_size = ent->d_size;
|
403 |
st.st_size = ent->d_size;
|
404 |
st.st_mode = ent->d_mode;
|
404 |
st.st_mode = ent->d_mode;
|
405 |
// ctime is really creation time on Windows. Just use mtime
|
405 |
// ctime is really creation time on Windows. Just use mtime
|
406 |
// for all. We only use ctime on Unix to catch xattr changes
|
406 |
// for all. We only use ctime on Unix to catch xattr changes
|
407 |
// anyway.
|
407 |
// anyway.
|
408 |
st.st_ctime = st.st_mtime;
|
408 |
st.st_ctime = st.st_mtime;
|
409 |
#else
|
409 |
#else
|
410 |
int statret = (data->options & FtwFollow) ? stat(fn.c_str(), &st) :
|
410 |
int statret = path_fileprops(fn.c_str(), &st, data->options&FtwFollow);
|
411 |
lstat(fn.c_str(), &st);
|
|
|
412 |
if (statret == -1) {
|
411 |
if (statret == -1) {
|
413 |
data->logsyserr("stat", fn);
|
412 |
data->logsyserr("stat", fn);
|
414 |
continue;
|
413 |
continue;
|
415 |
}
|
414 |
}
|
416 |
#endif
|
415 |
#endif
|