version 1.33, 2021/11/03 14:42:12 |
version 1.34, 2023/04/28 10:24:39 |
|
|
* The stat pointer st is only valid for 0, 1, and 2 returns. |
* The stat pointer st is only valid for 0, 1, and 2 returns. |
*/ |
*/ |
static int |
static int |
check_file(int rootfd, const struct flist *f, struct stat *st) |
check_file(int rootfd, const struct flist *f, struct stat *st, |
|
struct sess *sess) |
{ |
{ |
if (fstatat(rootfd, f->path, st, AT_SYMLINK_NOFOLLOW) == -1) { |
if (fstatat(rootfd, f->path, st, AT_SYMLINK_NOFOLLOW) == -1) { |
if (errno == ENOENT) |
if (errno == ENOENT) |
|
|
if (!S_ISREG(st->st_mode)) |
if (!S_ISREG(st->st_mode)) |
return 2; |
return 2; |
|
|
|
/* TODO: add support for --checksum */ |
|
|
|
/* if ignore_times is on file needs attention */ |
|
if (sess->opts->ignore_times) |
|
return 2; |
|
|
/* quick check if file is the same */ |
/* quick check if file is the same */ |
/* TODO: add support for --checksum, --size-only and --ignore-times */ |
|
if (st->st_size == f->st.size) { |
if (st->st_size == f->st.size) { |
|
if (sess->opts->size_only) |
|
return 0; |
if (st->st_mtime == f->st.mtime) |
if (st->st_mtime == f->st.mtime) |
return 0; |
return 0; |
return 1; |
return 1; |
|
|
*size = 0; |
*size = 0; |
*filefd = -1; |
*filefd = -1; |
|
|
rc = check_file(p->rootfd, f, &st); |
rc = check_file(p->rootfd, f, &st, sess); |
if (rc == -1) |
if (rc == -1) |
return -1; |
return -1; |
if (rc == 2 && !S_ISREG(st.st_mode)) { |
if (rc == 2 && !S_ISREG(st.st_mode)) { |
|
|
dfd = openat(p->rootfd, root, O_RDONLY | O_DIRECTORY); |
dfd = openat(p->rootfd, root, O_RDONLY | O_DIRECTORY); |
if (dfd == -1) |
if (dfd == -1) |
err(ERR_FILE_IO, "%s: openat", root); |
err(ERR_FILE_IO, "%s: openat", root); |
x = check_file(dfd, f, &st); |
x = check_file(dfd, f, &st, sess); |
/* found a match */ |
/* found a match */ |
if (x == 0) { |
if (x == 0) { |
if (rc >= 0) { |
if (rc >= 0) { |