X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/9decb4d2ef51599425f12a68dbeba2b4f3a2d908..8e41b68e8f975c02a5d9281be780ba5d1a385107:/flist.c diff --git a/flist.c b/flist.c index bac097b3..e33cd585 100644 --- a/flist.c +++ b/flist.c @@ -7,8 +7,9 @@ * Copyright (C) 2002-2007 Wayne Davison * * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3 as - * published by the Free Software Foundation. + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -708,7 +709,7 @@ static struct file_struct *recv_file_entry(struct file_list *flist, || (preserve_specials && IS_SPECIAL(mode))) { uint32 *devp = F_RDEV_P(first); rdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)); - extra_len += 2 * EXTRA_LEN; + extra_len += DEV_EXTRA_CNT * EXTRA_LEN; } if (preserve_links && S_ISLNK(mode)) linkname_len = strlen(F_SYMLINK(first)) + 1; @@ -779,7 +780,7 @@ static struct file_struct *recv_file_entry(struct file_list *flist, rdev_minor = read_int(f); rdev = MAKEDEV(rdev_major, rdev_minor); } - extra_len += 2 * EXTRA_LEN; + extra_len += DEV_EXTRA_CNT * EXTRA_LEN; file_length = 0; } else if (protocol_version < 28) rdev = MAKEDEV(0, 0); @@ -827,7 +828,7 @@ static struct file_struct *recv_file_entry(struct file_list *flist, if (inc_recurse && S_ISDIR(mode)) { if (one_file_system) { /* Room to save the dir's device for -x */ - extra_len += 2 * EXTRA_LEN; + extra_len += DEV_EXTRA_CNT * EXTRA_LEN; } pool = dir_flist->file_pool; } else @@ -945,7 +946,7 @@ static struct file_struct *recv_file_entry(struct file_list *flist, if (always_checksum && (S_ISREG(mode) || protocol_version < 28)) { if (S_ISREG(mode)) - bp = (char*)F_SUM(file); + bp = F_SUM(file); else { /* Prior to 28, we get a useless set of nulls. */ bp = tmp_sum; @@ -1093,7 +1094,7 @@ struct file_struct *make_file(const char *fname, struct file_list *flist, if (flist->prev && S_ISDIR(st.st_mode) && flags & FLAG_DIVERT_DIRS) { /* Room for parent/sibling/next-child info. */ - extra_len += 3 * EXTRA_LEN; + extra_len += DIRNODE_EXTRA_CNT * EXTRA_LEN; dir_count++; pool = dir_flist->file_pool; } else @@ -1239,14 +1240,14 @@ void unmake_file(struct file_struct *file) static struct file_struct *send_file_name(int f, struct file_list *flist, char *fname, STRUCT_STAT *stp, - int flags, int filter_flags) + int flags, int filter_level) { struct file_struct *file; #if defined SUPPORT_ACLS || defined SUPPORT_XATTRS statx sx; #endif - file = make_file(fname, flist, stp, flags, filter_flags); + file = make_file(fname, flist, stp, flags, filter_level); if (!file) return NULL; @@ -1393,7 +1394,7 @@ static void add_dirs_to_tree(int parent_ndx, struct file_list *from_flist, int i; int32 *dp = NULL; int32 *parent_dp = parent_ndx < 0 ? NULL - : F_DIRNODE_P(dir_flist->sorted[parent_ndx]); + : F_DIR_NODE_P(dir_flist->sorted[parent_ndx]); flist_expand(dir_flist, dir_cnt); dir_flist->sorted = dir_flist->files; @@ -1418,7 +1419,7 @@ static void add_dirs_to_tree(int parent_ndx, struct file_list *from_flist, else send_dir_ndx = dir_flist->used - 1; - dp = F_DIRNODE_P(file); + dp = F_DIR_NODE_P(file); DIR_PARENT(dp) = parent_ndx; DIR_FIRST_CHILD(dp) = -1; } @@ -1440,7 +1441,7 @@ static void send_directory(int f, struct file_list *flist, char *fbuf, int len, DIR *d; int divert_dirs = (flags & FLAG_DIVERT_DIRS) != 0; int start = flist->used; - int filter_flags = f == -2 ? SERVER_FILTERS : ALL_FILTERS; + int filter_level = f == -2 ? SERVER_FILTERS : ALL_FILTERS; assert(flist != NULL); @@ -1469,7 +1470,7 @@ static void send_directory(int f, struct file_list *flist, char *fbuf, int len, continue; } - send_file_name(f, flist, fbuf, NULL, flags, filter_flags); + send_file_name(f, flist, fbuf, NULL, flags, filter_level); } fbuf[len] = '\0'; @@ -1520,8 +1521,7 @@ void send_extra_file_list(int f, int at_least) * files in the upcoming file-lists. */ if (cur_flist->next) { flist = first_flist->prev; /* the newest flist */ - future_cnt = flist->used + flist->ndx_start - - cur_flist->next->ndx_start; + future_cnt = flist->ndx_end - cur_flist->next->ndx_start + 1; } else future_cnt = 0; while (future_cnt < at_least) { @@ -1539,9 +1539,10 @@ void send_extra_file_list(int f, int at_least) #endif dir_ndx = send_dir_ndx; write_ndx(f, NDX_FLIST_OFFSET - dir_ndx); + flist->parent_ndx = dir_ndx; send1extra(f, file, flist); - dp = F_DIRNODE_P(file); + dp = F_DIR_NODE_P(file); /* If there are any duplicate directory names that follow, we * send all the dirs together in one file-list. The dir_flist @@ -1551,7 +1552,7 @@ void send_extra_file_list(int f, int at_least) send_dir_ndx = dir_ndx; file = dir_flist->sorted[dir_ndx]; send1extra(f, file, flist); - dp = F_DIRNODE_P(file); + dp = F_DIR_NODE_P(file); } write_byte(f, 0); @@ -1568,6 +1569,9 @@ void send_extra_file_list(int f, int at_least) clean_flist(flist, 0); + flist->ndx_end = flist->ndx_start + flist->used - 1 + - (dir_count - dstart); + add_dirs_to_tree(send_dir_ndx, flist, dir_count - dstart); flist_done_allocating(flist); @@ -1591,7 +1595,7 @@ void send_extra_file_list(int f, int at_least) } send_dir_depth--; file = dir_flist->sorted[send_dir_ndx]; - dp = F_DIRNODE_P(file); + dp = F_DIR_NODE_P(file); } send_dir_ndx = DIR_NEXT_SIBLING(dp); } @@ -1883,6 +1887,10 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) } file_total += flist->used; + /* We don't subtract dir_count for the first send since we + * might have one or more dot dirs which need to get sent. */ + flist->ndx_end = flist->ndx_start + flist->used - 1; + if (!numeric_ids && !inc_recurse) send_id_list(f); @@ -1978,6 +1986,10 @@ struct file_list *recv_file_list(int f) } file_total += flist->used; + flist->ndx_end = flist->ndx_start + flist->used - 1; + if (inc_recurse && flist->ndx_start) + flist->ndx_end -= dir_flist->used - dstart; + if (verbose > 2) rprintf(FINFO, "received %d names\n", flist->used); @@ -2168,8 +2180,7 @@ struct file_list *flist_new(int flags, char *msg) } else { flist->file_pool = first_flist->file_pool; - flist->ndx_start = first_flist->prev->ndx_start - + first_flist->prev->used; + flist->ndx_start = first_flist->prev->ndx_end + 2; flist->prev = first_flist->prev; flist->prev->next = first_flist->prev = flist; @@ -2398,8 +2409,8 @@ static void output_flist(struct file_list *flist) const char *who = who_am_i(); int i; - rprintf(FINFO, "[%s] flist start=%d, count=%d, low=%d, high=%d\n", - who, flist->ndx_start, flist->used, flist->low, flist->high); + rprintf(FINFO, "[%s] flist start=%d, end=%d, used=%d, low=%d, high=%d\n", + who, flist->ndx_start, flist->ndx_end, flist->used, flist->low, flist->high); for (i = 0; i < flist->used; i++) { file = flist->sorted[i]; if ((am_root || am_sender) && uid_ndx) { @@ -2615,6 +2626,7 @@ struct file_list *get_dirlist(char *dirname, int dlen, int ignore_filter_rules) char dirbuf[MAXPATHLEN]; int save_recurse = recurse; int save_xfer_dirs = xfer_dirs; + int save_prune_empty_dirs = prune_empty_dirs; if (dlen < 0) { dlen = strlcpy(dirbuf, dirname, MAXPATHLEN); @@ -2633,8 +2645,10 @@ struct file_list *get_dirlist(char *dirname, int dlen, int ignore_filter_rules) if (do_progress) flist_count_offset += dirlist->used; + prune_empty_dirs = 0; dirlist->sorted = dirlist->files; clean_flist(dirlist, 0); + prune_empty_dirs = save_prune_empty_dirs; if (verbose > 3) output_flist(dirlist);