|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
|
#include <dirent.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
@ -21,20 +22,15 @@ recurse(const char *path, void *data, struct recursor *r)
|
|
|
|
|
struct history *new, *h;
|
|
|
|
|
struct stat st, dst;
|
|
|
|
|
DIR *dp;
|
|
|
|
|
int (*statf)(const char *, struct stat *);
|
|
|
|
|
char subpath[PATH_MAX], *statf_name;
|
|
|
|
|
char subpath[PATH_MAX];
|
|
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
|
|
if (r->follow == 'P' || (r->follow == 'H' && r->depth)) {
|
|
|
|
|
statf_name = "lstat";
|
|
|
|
|
statf = lstat;
|
|
|
|
|
} else {
|
|
|
|
|
statf_name = "stat";
|
|
|
|
|
statf = stat;
|
|
|
|
|
}
|
|
|
|
|
if (r->follow == 'P' || (r->follow == 'H' && r->depth))
|
|
|
|
|
flags |= AT_SYMLINK_NOFOLLOW;
|
|
|
|
|
|
|
|
|
|
if (statf(path, &st) < 0) {
|
|
|
|
|
if (fstatat(AT_FDCWD, path, &st, flags) < 0) {
|
|
|
|
|
if (!(r->flags & SILENT)) {
|
|
|
|
|
weprintf("%s %s:", statf_name, path);
|
|
|
|
|
weprintf("stat %s:", path);
|
|
|
|
|
recurse_status = 1;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
@ -66,19 +62,17 @@ recurse(const char *path, void *data, struct recursor *r)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
while ((d = readdir(dp))) {
|
|
|
|
|
if (r->follow == 'H') {
|
|
|
|
|
statf_name = "lstat";
|
|
|
|
|
statf = lstat;
|
|
|
|
|
}
|
|
|
|
|
if (r->follow == 'H')
|
|
|
|
|
flags |= AT_SYMLINK_NOFOLLOW;
|
|
|
|
|
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
|
|
|
|
|
continue;
|
|
|
|
|
estrlcpy(subpath, path, sizeof(subpath));
|
|
|
|
|
if (path[strlen(path) - 1] != '/')
|
|
|
|
|
estrlcat(subpath, "/", sizeof(subpath));
|
|
|
|
|
estrlcat(subpath, d->d_name, sizeof(subpath));
|
|
|
|
|
if (statf(subpath, &dst) < 0) {
|
|
|
|
|
if (fstatat(AT_FDCWD, subpath, &dst, flags) < 0) {
|
|
|
|
|
if (!(r->flags & SILENT)) {
|
|
|
|
|
weprintf("%s %s:", statf_name, subpath);
|
|
|
|
|
weprintf("stat %s:", subpath);
|
|
|
|
|
recurse_status = 1;
|
|
|
|
|
}
|
|
|
|
|
} else if ((r->flags & SAMEDEV) && dst.st_dev != st.st_dev) {
|
|
|
|
|