=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/rsync/uploader.c,v retrieving revision 1.25 retrieving revision 1.26 diff -c -r1.25 -r1.26 *** src/usr.bin/rsync/uploader.c 2021/05/06 07:35:22 1.25 --- src/usr.bin/rsync/uploader.c 2021/05/17 11:49:01 1.26 *************** *** 1,4 **** ! /* $Id: uploader.c,v 1.25 2021/05/06 07:35:22 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * Copyright (c) 2019 Florian Obser --- 1,4 ---- ! /* $Id: uploader.c,v 1.26 2021/05/17 11:49:01 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * Copyright (c) 2019 Florian Obser *************** *** 79,85 **** * operator that we're a link. */ static void ! log_link(struct sess *sess, const struct flist *f) { if (!sess->opts->server) --- 79,85 ---- * operator that we're a link. */ static void ! log_symlink(struct sess *sess, const struct flist *f) { if (!sess->opts->server) *************** *** 181,187 **** return 0; } if (sess->opts->dry_run) { ! log_link(sess, f); return 0; } --- 181,187 ---- return 0; } if (sess->opts->dry_run) { ! log_symlink(sess, f); return 0; } *************** *** 259,265 **** free(temp); } ! log_link(sess, f); return 0; } --- 259,265 ---- free(temp); } ! log_symlink(sess, f); return 0; } *************** *** 645,650 **** --- 645,651 ---- struct sess *sess) { const struct flist *f; + int rc; f = &p->fl[p->idx]; assert(S_ISREG(f->st.mode)); *************** *** 661,711 **** /* * For non dry-run cases, we'll write the acknowledgement later * in the rsync_uploader() function. - * If the call to openat() fails with ENOENT, there's a - * fast-path between here and the write function. */ ! *filefd = openat(p->rootfd, f->path, ! O_RDONLY | O_NOFOLLOW, 0); ! if (*filefd == -1 && errno != ENOENT) { ! ERR("%s: openat", f->path); return -1; } ! if (*filefd == -1) return 1; - - /* - * Check if the file is already up to date, in which case close it - * and go to the next one. - */ - - if (fstat(*filefd, st) == -1) { - ERR("%s: fstat", f->path); - close(*filefd); - *filefd = -1; - return -1; - } else if (!S_ISREG(st->st_mode)) { - ERRX("%s: not regular", f->path); - close(*filefd); - *filefd = -1; - return -1; } if (st->st_size == f->st.size && st->st_mtime == f->st.mtime) { LOG3("%s: skipping: up to date", f->path); ! if (!rsync_set_metadata(sess, 0, *filefd, f, f->path)) { ERRX1("rsync_set_metadata"); - close(*filefd); - *filefd = -1; return -1; } - close(*filefd); - *filefd = -1; return 0; } /* file needs attention */ return 1; } --- 662,704 ---- /* * For non dry-run cases, we'll write the acknowledgement later * in the rsync_uploader() function. */ ! *filefd = -1; ! rc = fstatat(p->rootfd, f->path, st, AT_SYMLINK_NOFOLLOW); ! if (rc == -1) { ! if (errno == ENOENT) ! return 1; ! ! ERR("%s: fstatat", f->path); return -1; } ! if (rc != -1 && !S_ISREG(st->st_mode)) { ! if (S_ISDIR(st->st_mode) && ! unlinkat(p->rootfd, f->path, AT_REMOVEDIR) == -1) { ! ERR("%s: unlinkat", f->path); ! return -1; ! } return 1; } if (st->st_size == f->st.size && st->st_mtime == f->st.mtime) { LOG3("%s: skipping: up to date", f->path); ! if (!rsync_set_metadata_at(sess, 0, p->rootfd, f, f->path)) { ERRX1("rsync_set_metadata"); return -1; } return 0; } + *filefd = openat(p->rootfd, f->path, O_RDONLY | O_NOFOLLOW, 0); + if (*filefd == -1 && errno != ENOENT) { + ERR("%s: openat", f->path); + return -1; + } + /* file needs attention */ return 1; } *************** *** 785,792 **** off_t offs; int c; ! /* This should never get called. */ ! assert(u->state != UPLOAD_FINISHED); /* --- 778,784 ---- off_t offs; int c; ! /* Once finished this should never get called again. */ assert(u->state != UPLOAD_FINISHED); /*