X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/29a89172f77ed76dcf53612e96dc35daf15d7362..4ecf3e067151e45dc7dead9862416722dcb4a20f:/flist.c diff --git a/flist.c b/flist.c index 4e302aa6..0554b5d7 100644 --- a/flist.c +++ b/flist.c @@ -366,19 +366,23 @@ int change_pathname(struct file_struct *file, const char *dir, int dirlen) change_dir(orig_dir, CD_SKIP_CHDIR); } - if (!change_dir(dir ? dir : orig_dir, CD_NORMAL)) { + pathname = dir; + pathname_len = dirlen; + + if (!dir) + dir = orig_dir; + + if (!change_dir(dir, CD_NORMAL)) { chdir_error: io_error |= IOERR_GENERAL; rsyserr(FERROR, errno, "change_dir %s failed", full_fname(dir)); - change_dir(orig_dir, CD_NORMAL); + if (dir != orig_dir) + change_dir(orig_dir, CD_NORMAL); pathname = NULL; pathname_len = 0; return 0; } - pathname = dir; - pathname_len = dirlen; - return 1; } @@ -634,7 +638,7 @@ static struct file_struct *recv_file_entry(struct file_list *flist, int alloc_len, basename_len, linkname_len; int extra_len = file_extra_cnt * EXTRA_LEN; int first_hlink_ndx = -1; - OFF_T file_length; + int64 file_length; const char *basename; struct file_struct *file; alloc_pool_t *pool; @@ -833,8 +837,14 @@ static struct file_struct *recv_file_entry(struct file_list *flist, if (always_checksum && S_ISREG(mode)) extra_len += SUM_EXTRA_CNT * EXTRA_LEN; +#if SIZEOF_INT64 >= 8 if (file_length > 0xFFFFFFFFu && S_ISREG(mode)) extra_len += EXTRA_LEN; +#endif + if (file_length < 0) { + rprintf(FERROR, "Offset underflow: file-length is negative\n"); + exit_cleanup(RERR_UNSUPPORTED); + } if (inc_recurse && S_ISDIR(mode)) { if (one_file_system) { @@ -867,10 +877,17 @@ static struct file_struct *recv_file_entry(struct file_list *flist, #endif file->modtime = (time_t)modtime; file->len32 = (uint32)file_length; +#if SIZEOF_INT64 >= 8 if (file_length > 0xFFFFFFFFu && S_ISREG(mode)) { +#if SIZEOF_CAPITAL_OFF_T < 8 + rprintf(FERROR, "Offset overflow: attempted 64-bit file-length\n"); + exit_cleanup(RERR_UNSUPPORTED); +#else file->flags |= FLAG_LENGTH64; OPT_EXTRA(file, 0)->unum = (uint32)(file_length >> 32); +#endif } +#endif file->mode = mode; if (preserve_uid) F_OWNER(file) = uid; @@ -1019,7 +1036,6 @@ struct file_struct *make_file(const char *fname, struct file_list *flist, const char *basename; alloc_pool_t *pool; STRUCT_STAT st; - int excl_ret; char *bp; if (strlcpy(thisname, fname, sizeof thisname) >= sizeof thisname) { @@ -1074,7 +1090,6 @@ struct file_struct *make_file(const char *fname, struct file_list *flist, return NULL; } - /* backup.c calls us with filter_level set to NO_FILTERS. */ if (filter_level == NO_FILTERS) goto skip_filters; @@ -1102,17 +1117,7 @@ struct file_struct *make_file(const char *fname, struct file_list *flist, } else flags &= ~FLAG_CONTENT_DIR; - if (S_ISDIR(st.st_mode)) { - if (flags & FLAG_DOTDIR_NAME) { - /* A "." fname (or "/." fname in relative mode) is - * never excluded. No other trailing-dotdir names - * are possible. */ - excl_ret = 0; - } else - excl_ret = is_excluded(thisname, 1, filter_level); - } else - excl_ret = is_excluded(thisname, 0, filter_level); - if (excl_ret) { + if (is_excluded(thisname, S_ISDIR(st.st_mode) != 0, filter_level)) { if (ignore_perishable) non_perishable_cnt++; return NULL; @@ -1171,8 +1176,10 @@ struct file_struct *make_file(const char *fname, struct file_list *flist, linkname_len = 0; #endif +#if SIZEOF_CAPITAL_OFF_T >= 8 if (st.st_size > 0xFFFFFFFFu && S_ISREG(st.st_mode)) extra_len += EXTRA_LEN; +#endif #if EXTRA_ROUNDING > 0 if (extra_len & (EXTRA_ROUNDING * EXTRA_LEN)) @@ -1217,10 +1224,12 @@ struct file_struct *make_file(const char *fname, struct file_list *flist, file->flags = flags; file->modtime = st.st_mtime; file->len32 = (uint32)st.st_size; +#if SIZEOF_CAPITAL_OFF_T >= 8 if (st.st_size > 0xFFFFFFFFu && S_ISREG(st.st_mode)) { file->flags |= FLAG_LENGTH64; OPT_EXTRA(file, 0)->unum = (uint32)(st.st_size >> 32); } +#endif file->mode = st.st_mode; if (uid_ndx) /* Check uid_ndx instead of preserve_uid for del support */ F_OWNER(file) = st.st_uid; @@ -1849,7 +1858,7 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) int64 start_write; int use_ff_fd = 0; int disable_buffering; - int arg_flags, flags = recurse ? FLAG_CONTENT_DIR : 0; + int flags = recurse ? FLAG_CONTENT_DIR : 0; int reading_remotely = filesfrom_host != NULL; int rl_flags = (reading_remotely ? 0 : RL_DUMP_COMMENTS) #ifdef ICONV_OPTION @@ -2031,6 +2040,11 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) continue; } + /* A dot-dir should not be excluded! */ + if (name_type != DOTDIR_NAME + && is_excluded(fbuf, S_ISDIR(st.st_mode) != 0, ALL_FILTERS)) + continue; + if (S_ISDIR(st.st_mode) && !xfer_dirs) { rprintf(FINFO, "skipping directory %s\n", fbuf); continue; @@ -2056,13 +2070,11 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) if (one_file_system) filesystem_dev = st.st_dev; - arg_flags = name_type == DOTDIR_NAME ? FLAG_DOTDIR_NAME : 0; - if (recurse || (xfer_dirs && name_type != NORMAL_NAME)) { struct file_struct *file; - arg_flags |= FLAG_TOP_DIR | FLAG_CONTENT_DIR; file = send_file_name(f, flist, fbuf, &st, - arg_flags | flags, ALL_FILTERS); + FLAG_TOP_DIR | FLAG_CONTENT_DIR | flags, + NO_FILTERS); if (!file) continue; if (inc_recurse) { @@ -2076,7 +2088,7 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) } else send_if_directory(f, flist, file, fbuf, len, flags); } else - send_file_name(f, flist, fbuf, &st, arg_flags | flags, ALL_FILTERS); + send_file_name(f, flist, fbuf, &st, flags, NO_FILTERS); } gettimeofday(&end_tv, NULL);