X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/82ad07c4182f744c07b96a15df4572e559ed7dc8..bd6edd3fa26dde8d134edb0166665c12082dd9a6:/flist.c diff --git a/flist.c b/flist.c index 2fab393a..1d5fbff2 100644 --- a/flist.c +++ b/flist.c @@ -22,6 +22,7 @@ */ #include "rsync.h" +#include "rounding.h" extern int verbose; extern int list_only; @@ -48,7 +49,7 @@ extern int preserve_uid; extern int preserve_gid; extern int relative_paths; extern int implied_dirs; -extern int flist_extra_ndx; +extern int flist_extra_cnt; extern int ignore_perishable; extern int non_perishable_cnt; extern int prune_empty_dirs; @@ -58,6 +59,7 @@ extern int protocol_version; extern int sanitize_paths; extern struct stats stats; extern struct file_list *the_file_list; +extern alloc_pool_t hlink_pool; extern char curr_dir[MAXPATHLEN]; @@ -69,27 +71,28 @@ extern struct filter_list_struct server_filter_list; int io_error; int checksum_len; dev_t filesystem_dev; /* used to implement -x */ -int file_struct_len; /* The tmp_* vars are used as a cache area by make_file() to store data * that the sender doesn't need to remember in its file list. The data * will survive just long enough to be used by send_file_entry(). */ static dev_t tmp_rdev; +#ifdef SUPPORT_HARD_LINKS static struct idev tmp_idev; +#endif static char tmp_sum[MD4_SUM_LENGTH]; static char empty_sum[MD4_SUM_LENGTH]; -static int flist_count_offset; +static int flist_count_offset; /* for --delete --progress */ static void clean_flist(struct file_list *flist, int strip_root, int no_dups); static void output_flist(struct file_list *flist); void init_flist(void) { - struct file_struct f; - - /* Figure out how big the file_struct is without trailing padding */ - file_struct_len = offsetof(struct file_struct, flags) + sizeof f.flags; + if (verbose > 4) { + rprintf(FINFO, "FILE_STRUCT_LEN=%d, EXTRA_LEN=%d\n", + (int)FILE_STRUCT_LEN, (int)EXTRA_LEN); + } checksum_len = protocol_version < 21 ? 2 : MD4_SUM_LENGTH; } @@ -135,26 +138,26 @@ void show_flist_stats(void) static void list_file_entry(struct file_struct *f) { char permbuf[PERMSTRING_SIZE]; + double len; - if (!f->basename) { + if (!F_IS_ACTIVE(f)) { /* this can happen if duplicate names were removed */ return; } permstring(permbuf, f->mode); + len = F_LENGTH(f); #ifdef SUPPORT_LINKS if (preserve_links && S_ISLNK(f->mode)) { rprintf(FINFO, "%s %11.0f %s %s -> %s\n", - permbuf, - (double)f->length, timestring(f->modtime), + permbuf, len, timestring(f->modtime), f_name(f, NULL), F_SYMLINK(f)); } else #endif { rprintf(FINFO, "%s %11.0f %s %s\n", - permbuf, - (double)f->length, timestring(f->modtime), + permbuf, len, timestring(f->modtime), f_name(f, NULL)); } } @@ -308,7 +311,7 @@ void flist_expand(struct file_list *flist) out_of_memory("flist_expand"); } -static void send_file_entry(struct file_struct *file, int f) +static void send_file_entry(struct file_struct *file, int f, int ndx) { unsigned short flags; static time_t modtime; @@ -320,21 +323,9 @@ static void send_file_entry(struct file_struct *file, int f) static gid_t gid; static char lastname[MAXPATHLEN]; char fname[MAXPATHLEN]; + int first_hlink_ndx = -1; int l1, l2; - if (f < 0) - return; - - if (!file) { - write_byte(f, 0); - modtime = 0, mode = 0; - dev = 0, rdev = MAKEDEV(0, 0); - rdev_major = 0; - uid = 0, gid = 0; - *lastname = '\0'; - return; - } - f_name(file, fname); flags = file->flags & FLAG_TOP_DIR; /* FLAG_TOP_DIR == XMIT_TOP_DIR */ @@ -380,12 +371,22 @@ static void send_file_entry(struct file_struct *file, int f) #ifdef SUPPORT_HARD_LINKS if (tmp_idev.dev != 0) { - if (tmp_idev.dev == dev) { - if (protocol_version >= 28) - flags |= XMIT_SAME_DEV; - } else - dev = tmp_idev.dev; - flags |= XMIT_HAS_IDEV_DATA; + if (protocol_version >= 30) { + struct idev_node *np = idev_node(tmp_idev.dev, tmp_idev.ino); + first_hlink_ndx = (int32)np->data - 1; + if (first_hlink_ndx < 0) { + np->data = (void*)(ndx + 1); + flags |= XMIT_HLINK_FIRST; + } + flags |= XMIT_HLINKED; + } else { + if (tmp_idev.dev == dev) { + if (protocol_version >= 28) + flags |= XMIT_SAME_DEV_pre30; + } else + dev = tmp_idev.dev; + flags |= XMIT_HLINKED; + } } #endif @@ -424,7 +425,12 @@ static void send_file_entry(struct file_struct *file, int f) write_byte(f, l2); write_buf(f, fname + l1, l2); - write_longint(f, file->length); + if (first_hlink_ndx >= 0) { + write_int(f, first_hlink_ndx); + goto the_end; + } + + write_longint(f, F_LENGTH(file)); if (!(flags & XMIT_SAME_TIME)) write_int(f, modtime); if (!(flags & XMIT_SAME_MODE)) @@ -464,14 +470,14 @@ static void send_file_entry(struct file_struct *file, int f) #endif #ifdef SUPPORT_HARD_LINKS - if (tmp_idev.dev != 0) { + if (tmp_idev.dev != 0 && protocol_version < 30) { if (protocol_version < 26) { /* 32-bit dev_t and ino_t */ write_int(f, (int32)dev); write_int(f, (int32)tmp_idev.ino); } else { /* 64-bit dev_t and ino_t */ - if (!(flags & XMIT_SAME_DEV)) + if (!(flags & XMIT_SAME_DEV_pre30)) write_longint(f, dev); write_longint(f, tmp_idev.ino); } @@ -489,6 +495,7 @@ static void send_file_entry(struct file_struct *file, int f) write_buf(f, sum, checksum_len); } + the_end: strlcpy(lastname, fname, MAXPATHLEN); } @@ -508,8 +515,9 @@ static struct file_struct *recv_file_entry(struct file_list *flist, static int in_del_hier = 0; char thisname[MAXPATHLEN]; unsigned int l1 = 0, l2 = 0; - int alloc_len, basename_len, dirname_len, linkname_len, sum_len; - int extra_len = (flist_extra_ndx-1) * sizeof (union flist_extras); + int alloc_len, basename_len, dirname_len, linkname_len; + int extra_len = flist_extra_cnt * EXTRA_LEN; + int first_hlink_ndx = -1; OFF_T file_length; char *basename, *dirname, *bp; struct file_struct *file; @@ -566,6 +574,38 @@ static struct file_struct *recv_file_entry(struct file_list *flist, } basename_len = strlen(basename) + 1; /* count the '\0' */ +#ifdef SUPPORT_HARD_LINKS + if (protocol_version >= 30 + && BITS_SETnUNSET(flags, XMIT_HLINKED, XMIT_HLINK_FIRST)) { + struct file_struct *first; + first_hlink_ndx = read_int(f); + if (first_hlink_ndx < 0 || first_hlink_ndx >= flist->count) { + rprintf(FERROR, + "hard-link reference out of range: %d (%d)\n", + first_hlink_ndx, flist->count); + exit_cleanup(RERR_PROTOCOL); + } + first = flist->files[first_hlink_ndx]; + file_length = F_LENGTH(first); + modtime = first->modtime; + mode = first->mode; + if (preserve_uid) + uid = F_UID(first); + if (preserve_gid) + gid = F_GID(first); + if ((preserve_devices && IS_DEVICE(mode)) + || (preserve_specials && IS_SPECIAL(mode))) { + uint32 *devp = F_RDEV_P(first); + rdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)); + } + if (preserve_links && S_ISLNK(mode)) + linkname_len = strlen(F_SYMLINK(first)) + 1; + else + linkname_len = 0; + goto create_object; + } +#endif + file_length = read_longint(f); if (!(flags & XMIT_SAME_TIME)) modtime = (time_t)read_int(f); @@ -595,7 +635,8 @@ 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 * sizeof (union flist_extras); + extra_len += 2 * EXTRA_LEN; + file_length = 0; } else if (protocol_version < 28) rdev = MAKEDEV(0, 0); @@ -613,31 +654,48 @@ static struct file_struct *recv_file_entry(struct file_list *flist, linkname_len = 0; #ifdef SUPPORT_HARD_LINKS - if (preserve_hard_links && protocol_version < 28 && S_ISREG(mode)) - flags |= XMIT_HAS_IDEV_DATA; - if (flags & XMIT_HAS_IDEV_DATA) { - extra_len += sizeof (union flist_extras); - assert(flist->hlink_pool != NULL); + create_object: + if (preserve_hard_links) { + if (protocol_version < 28 && S_ISREG(mode)) + flags |= XMIT_HLINKED; + if (flags & XMIT_HLINKED) + extra_len += EXTRA_LEN; } #endif - sum_len = always_checksum && S_ISREG(mode) ? MD4_SUM_LENGTH : 0; + if (always_checksum && S_ISREG(mode)) + extra_len += SUM_EXTRA_CNT * EXTRA_LEN; + + if (file_length > 0xFFFFFFFFu && S_ISREG(mode)) + extra_len += EXTRA_LEN; + +#if EXTRA_ROUNDING > 0 + if (extra_len & (EXTRA_ROUNDING * EXTRA_LEN)) + extra_len = (extra_len | (EXTRA_ROUNDING * EXTRA_LEN)) + EXTRA_LEN; +#endif - alloc_len = file_struct_len + dirname_len + basename_len - + linkname_len + sum_len + extra_len; + alloc_len = FILE_STRUCT_LEN + extra_len + basename_len + dirname_len + + linkname_len; bp = pool_alloc(flist->file_pool, alloc_len, "recv_file_entry"); - memset(bp, 0, file_struct_len + extra_len); + memset(bp, 0, extra_len + FILE_STRUCT_LEN); bp += extra_len; file = (struct file_struct *)bp; - bp += file_struct_len + linkname_len + sum_len; + bp += FILE_STRUCT_LEN; + + memcpy(bp, basename, basename_len); + bp += basename_len + linkname_len; /* skip space for symlink too */ #ifdef SUPPORT_HARD_LINKS - if (flags & XMIT_HAS_IDEV_DATA) - file->flags |= FLAG_HLINK_INFO; + if (flags & XMIT_HLINKED) + file->flags |= FLAG_HLINKED; #endif file->modtime = modtime; - file->length = file_length; + file->len32 = (uint32)file_length; + if (file_length > 0xFFFFFFFFu && S_ISREG(mode)) { + file->flags |= FLAG_LENGTH64; + OPT_EXTRA(file, 0)->unum = (uint32)(file_length >> 32); + } file->mode = mode; if (preserve_uid) F_UID(file) = uid; @@ -679,50 +737,60 @@ static struct file_struct *recv_file_entry(struct file_list *flist, } } - file->basename = bp; - memcpy(bp, basename, basename_len); - bp += basename_len; - if ((preserve_devices && IS_DEVICE(mode)) || (preserve_specials && IS_SPECIAL(mode))) { - F_DMAJOR(file) = major(rdev); - F_DMINOR(file) = minor(rdev); + uint32 *devp = F_RDEV_P(file); + DEV_MAJOR(devp) = major(rdev); + DEV_MINOR(devp) = minor(rdev); } #ifdef SUPPORT_LINKS if (linkname_len) { - bp = F_SYMLINK(file); - read_sbuf(f, bp, linkname_len - 1); + bp = (char*)file->basename + basename_len; + if (first_hlink_ndx >= 0) { + struct file_struct *first = flist->files[first_hlink_ndx]; + memcpy(bp, F_SYMLINK(first), linkname_len); + } else + read_sbuf(f, bp, linkname_len - 1); if (sanitize_paths) sanitize_path(bp, bp, "", lastdir_depth, NULL); } #endif #ifdef SUPPORT_HARD_LINKS - if (flags & XMIT_HAS_IDEV_DATA) { - struct idev *idevp = pool_talloc(flist->hlink_pool, struct idev, - 1, "inode_table"); - F_IDEV(file) = idevp; - if (protocol_version < 26) { - idevp->dev = read_int(f); - idevp->ino = read_int(f); + if (preserve_hard_links && flags & XMIT_HLINKED) { + if (protocol_version >= 30) { + F_HL_GNUM(file) = flags & XMIT_HLINK_FIRST + ? flist->count : first_hlink_ndx; } else { - if (!(flags & XMIT_SAME_DEV)) - dev = read_longint(f); - idevp->dev = dev; - idevp->ino = read_longint(f); + struct idev *idevp = pool_talloc(hlink_pool, struct idev, + 1, "inode_table"); + F_HL_IDEV(file) = idevp; + if (protocol_version < 26) { + idevp->dev = read_int(f); + idevp->ino = read_int(f); + } else { + if (!(flags & XMIT_SAME_DEV_pre30)) + dev = read_longint(f); + idevp->dev = dev; + idevp->ino = read_longint(f); + } } } #endif - if (always_checksum && (sum_len || protocol_version < 28)) { - if (sum_len) - bp = F_SUM(file); + if (always_checksum && (S_ISREG(mode) || protocol_version < 28)) { + if (S_ISREG(mode)) + bp = (char*)F_SUM(file); else { /* Prior to 28, we get a useless set of nulls. */ bp = tmp_sum; } - read_buf(f, bp, checksum_len); + if (first_hlink_ndx >= 0) { + struct file_struct *first = flist->files[first_hlink_ndx]; + memcpy(bp, F_SUM(first), checksum_len); + } else + read_buf(f, bp, checksum_len); } return file; @@ -753,7 +821,7 @@ struct file_struct *make_file(const char *fname, struct file_list *flist, char thisname[MAXPATHLEN]; char linkname[MAXPATHLEN]; int alloc_len, basename_len, dirname_len, linkname_len; - int extra_len = (flist_extra_ndx-1) * sizeof (union flist_extras); + int extra_len = flist_extra_cnt * EXTRA_LEN; char *basename, *dirname, *bp; if (!flist || !flist->count) /* Ignore lastdir when invalid. */ @@ -872,8 +940,16 @@ struct file_struct *make_file(const char *fname, struct file_list *flist, linkname_len = 0; #endif - alloc_len = file_struct_len + dirname_len + basename_len - + linkname_len + extra_len; + if (st.st_size > 0xFFFFFFFFu && S_ISREG(st.st_mode)) + extra_len += EXTRA_LEN; + +#if EXTRA_ROUNDING > 0 + if (extra_len & (EXTRA_ROUNDING * EXTRA_LEN)) + extra_len = (extra_len | (EXTRA_ROUNDING * EXTRA_LEN)) + EXTRA_LEN; +#endif + + alloc_len = FILE_STRUCT_LEN + extra_len + basename_len + dirname_len + + linkname_len; if (flist) bp = pool_alloc(flist->file_pool, alloc_len, "make_file"); else { @@ -881,10 +957,13 @@ struct file_struct *make_file(const char *fname, struct file_list *flist, out_of_memory("make_file"); } - memset(bp, 0, file_struct_len + extra_len); + memset(bp, 0, extra_len + FILE_STRUCT_LEN); bp += extra_len; file = (struct file_struct *)bp; - bp += file_struct_len + linkname_len; + bp += FILE_STRUCT_LEN; + + memcpy(bp, basename, basename_len); + bp += basename_len + linkname_len; /* skip space for symlink too */ #ifdef SUPPORT_HARD_LINKS if (preserve_hard_links && flist) { @@ -898,9 +977,20 @@ struct file_struct *make_file(const char *fname, struct file_list *flist, } #endif +#ifdef HAVE_STRUCT_STAT_ST_RDEV + if (IS_DEVICE(st.st_mode) || IS_SPECIAL(st.st_mode)) { + tmp_rdev = st.st_rdev; + st.st_size = 0; + } +#endif + file->flags = flags; file->modtime = st.st_mtime; - file->length = st.st_size; + file->len32 = (uint32)st.st_size; + if (st.st_size > 0xFFFFFFFFu && S_ISREG(st.st_mode)) { + file->flags |= FLAG_LENGTH64; + OPT_EXTRA(file, 0)->unum = (uint32)(st.st_size >> 32); + } file->mode = st.st_mode; if (preserve_uid) F_UID(file) = st.st_uid; @@ -916,19 +1006,11 @@ struct file_struct *make_file(const char *fname, struct file_list *flist, } else if (dirname) file->dirname = dirname; - file->basename = bp; - memcpy(bp, basename, basename_len); - bp += basename_len; - -#ifdef HAVE_STRUCT_STAT_ST_RDEV - if ((preserve_devices && IS_DEVICE(st.st_mode)) - || (preserve_specials && IS_SPECIAL(st.st_mode))) - tmp_rdev = st.st_rdev; -#endif - #ifdef SUPPORT_LINKS - if (linkname_len) - memcpy(F_SYMLINK(file), linkname, linkname_len); + if (linkname_len) { + bp = (char*)file->basename + basename_len; + memcpy(bp, linkname, linkname_len); + } #endif if (always_checksum && am_sender && S_ISREG(st.st_mode)) @@ -945,7 +1027,7 @@ struct file_struct *make_file(const char *fname, struct file_list *flist, if (flist_find(the_file_list, file) >= 0 && do_stat(thisname, &st2) == 0 && S_ISDIR(st2.st_mode)) { file->modtime = st2.st_mtime; - file->length = st2.st_size; + file->len32 = 0; file->mode = st2.st_mode; if (preserve_uid) F_UID(file) = st2.st_uid; @@ -964,12 +1046,15 @@ struct file_struct *make_file(const char *fname, struct file_list *flist, return file; } -/* Only called for temporary file_struct entries. */ +/* Only called for temporary file_struct entries created by make_file(). */ void unmake_file(struct file_struct *file) { - union flist_extras *start = (union flist_extras *)file - - (flist_extra_ndx - 1); - free(start); + int extra_cnt = flist_extra_cnt + LEN64_BUMP(file); +#if EXTRA_ROUNDING > 0 + if (extra_cnt & EXTRA_ROUNDING) + extra_cnt = (extra_cnt | EXTRA_ROUNDING) + 1; +#endif + free(REQ_EXTRA(file, extra_cnt)); } static struct file_struct *send_file_name(int f, struct file_list *flist, @@ -990,7 +1075,8 @@ static struct file_struct *send_file_name(int f, struct file_list *flist, flist_expand(flist); flist->files[flist->count++] = file; - send_file_entry(file, f); + if (f >= 0) + send_file_entry(file, f, flist->count - 1); return file; } @@ -1026,8 +1112,7 @@ static void send_if_directory(int f, struct file_list *flist, * file list in memory without sending it over the wire. Also, get_dirlist() * might call this with f set to -2, which also indicates that local filter * rules should be ignored. */ -static void send_directory(int f, struct file_list *flist, - char *fbuf, int len) +static void send_directory(int f, struct file_list *flist, char *fbuf, int len) { struct dirent *di; unsigned remainder; @@ -1074,6 +1159,7 @@ static void send_directory(int f, struct file_list *flist, if (recurse) { int i, end = flist->count - 1; + /* send_if_directory() bumps flist->count, so use "end". */ for (i = start; i <= end; i++) send_if_directory(f, flist, flist->files[i], fbuf, len); } @@ -1097,7 +1183,12 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) start_write = stats.total_written; gettimeofday(&start_tv, NULL); - flist = flist_new(0, "send_file_list"); +#ifdef SUPPORT_HARD_LINKS + if (preserve_hard_links && protocol_version >= 30) + init_hard_links(); +#endif + + flist = flist_new("send_file_list"); io_start_buffering_out(); if (filesfrom_fd >= 0) { @@ -1315,7 +1406,12 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) stats.flist_buildtime = 1; start_tv = end_tv; - send_file_entry(NULL, f); + write_byte(f, 0); /* Indicate end of file list */ + +#ifdef SUPPORT_HARD_LINKS + if (preserve_hard_links && protocol_version >= 30) + idev_destroy(); +#endif if (show_filelist_p()) finish_filelist_progress(flist); @@ -1361,8 +1457,12 @@ struct file_list *recv_file_list(int f) start_read = stats.total_read; - flist = flist_new(WITH_HLINK, "recv_file_list"); + flist = flist_new("recv_file_list"); +#ifdef SUPPORT_HARD_LINKS + if (preserve_hard_links && protocol_version < 30) + init_hard_links(); +#endif while ((flags = read_byte(f)) != 0) { struct file_struct *file; @@ -1374,7 +1474,7 @@ struct file_list *recv_file_list(int f) file = recv_file_entry(flist, flags, f); if (S_ISREG(file->mode) || S_ISLNK(file->mode)) - stats.total_size += file->length; + stats.total_size += F_LENGTH(file); flist->files[flist->count++] = file; @@ -1437,28 +1537,28 @@ int flist_find(struct file_list *flist, struct file_struct *f) while (low <= high) { mid = (low + high) / 2; - if (flist->files[mid]->basename) + if (F_IS_ACTIVE(flist->files[mid])) mid_up = mid; else { /* Scan for the next non-empty entry using the cached * distance values. If the value isn't fully up-to- * date, update it. */ mid_up = mid + flist->files[mid]->dir.depth; - if (!flist->files[mid_up]->basename) { + if (!F_IS_ACTIVE(flist->files[mid_up])) { do { mid_up += flist->files[mid_up]->dir.depth; - } while (!flist->files[mid_up]->basename); + } while (!F_IS_ACTIVE(flist->files[mid_up])); flist->files[mid]->dir.depth = mid_up - mid; } if (mid_up > high) { /* If there's nothing left above us, set high to * a non-empty entry below us and continue. */ - high = mid - (int)flist->files[mid]->length; - if (!flist->files[high]->basename) { + high = mid - (int)flist->files[mid]->len32; + if (!F_IS_ACTIVE(flist->files[high])) { do { - high -= (int)flist->files[high]->length; - } while (!flist->files[high]->basename); - flist->files[mid]->length = mid - high; + high -= (int)flist->files[high]->len32; + } while (!F_IS_ACTIVE(flist->files[high])); + flist->files[mid]->len32 = mid - high; } continue; } @@ -1485,18 +1585,17 @@ int flist_find(struct file_list *flist, struct file_struct *f) */ void clear_file(struct file_struct *file) { - memset(file, 0, file_struct_len); + /* The +1 zeros out the first char of the basename. */ + memset(file, 0, FILE_STRUCT_LEN + 1); /* In an empty entry, dir.depth is an offset to the next non-empty - * entry. Likewise for length in the opposite direction. We assume + * entry. Likewise for len32 in the opposite direction. We assume * that we're alone for now since flist_find() will adjust the counts * it runs into that aren't up-to-date. */ - file->length = file->dir.depth = 1; + file->len32 = file->dir.depth = 1; } -/* - * allocate a new file list - */ -struct file_list *flist_new(int with_hlink, char *msg) +/* Allocate a new file list. */ +struct file_list *flist_new(char *msg) { struct file_list *flist; @@ -1509,24 +1608,13 @@ struct file_list *flist_new(int with_hlink, char *msg) if (!(flist->file_pool = pool_create(FILE_EXTENT, 0, out_of_memory, POOL_INTERN))) out_of_memory(msg); -#ifdef SUPPORT_HARD_LINKS - if (with_hlink && preserve_hard_links) { - if (!(flist->hlink_pool = pool_create(HLINK_EXTENT, - sizeof (struct idev), out_of_memory, POOL_INTERN))) - out_of_memory(msg); - } -#endif - return flist; } -/* - * free up all elements in a flist - */ +/* Free up all elements in a flist. */ void flist_free(struct file_list *flist) { pool_destroy(flist->file_pool); - pool_destroy(flist->hlink_pool); free(flist->files); free(flist); } @@ -1551,7 +1639,7 @@ static void clean_flist(struct file_list *flist, int strip_root, int no_dups) sizeof flist->files[0], (int (*)())file_compare); for (i = no_dups? 0 : flist->count; i < flist->count; i++) { - if (flist->files[i]->basename) { + if (F_IS_ACTIVE(flist->files[i])) { prev_i = i; break; } @@ -1561,7 +1649,7 @@ static void clean_flist(struct file_list *flist, int strip_root, int no_dups) int j; struct file_struct *file = flist->files[i]; - if (!file->basename) + if (!F_IS_ACTIVE(file)) continue; if (f_name_cmp(file, flist->files[prev_i]) == 0) j = prev_i; @@ -1603,7 +1691,7 @@ static void clean_flist(struct file_list *flist, int strip_root, int no_dups) if (keep == i) { if (flist->low == drop) { for (j = drop + 1; - j < i && !flist->files[j]->basename; + j < i && !F_IS_ACTIVE(flist->files[j]); j++) {} flist->low = j; } @@ -1684,12 +1772,12 @@ static void clean_flist(struct file_list *flist, int strip_root, int no_dups) } for (i = flist->low; i <= flist->high; i++) { - if (flist->files[i]->basename) + if (F_IS_ACTIVE(flist->files[i])) break; } flist->low = i; for (i = flist->high; i >= flist->low; i--) { - if (flist->files[i]->basename) + if (F_IS_ACTIVE(flist->files[i])) break; } flist->high = i; @@ -1700,6 +1788,7 @@ static void output_flist(struct file_list *flist) { char uidbuf[16], gidbuf[16], depthbuf[16]; struct file_struct *file; + const char *dir, *slash, *name, *trail; const char *who = who_am_i(); int i; @@ -1717,12 +1806,19 @@ static void output_flist(struct file_list *flist) *gidbuf = '\0'; if (!am_sender) snprintf(depthbuf, sizeof depthbuf, "%d", file->dir.depth); + if (F_IS_ACTIVE(file)) { + if ((dir = file->dirname) == NULL) + dir = slash = ""; + else + slash = "/"; + name = file->basename; + trail = S_ISDIR(file->mode) ? "/" : ""; + } else + dir = slash = name = trail = ""; rprintf(FINFO, "[%s] i=%d %s %s%s%s%s mode=0%o len=%.0f%s%s flags=%x\n", who, i, am_sender ? NS(file->dir.root) : depthbuf, - file->dirname ? file->dirname : "", - file->dirname ? "/" : "", NS(file->basename), - S_ISDIR(file->mode) ? "/" : "", (int)file->mode, - (double)file->length, uidbuf, gidbuf, file->flags); + dir, slash, name, trail, (int)file->mode, + (double)F_LENGTH(file), uidbuf, gidbuf, file->flags); } } @@ -1752,12 +1848,12 @@ int f_name_cmp(struct file_struct *f1, struct file_struct *f2) enum fnc_type type1, type2; enum fnc_type t_path = protocol_version >= 29 ? t_PATH : t_ITEM; - if (!f1 || !f1->basename) { - if (!f2 || !f2->basename) + if (!f1 || !F_IS_ACTIVE(f1)) { + if (!f2 || !F_IS_ACTIVE(f2)) return 0; return -1; } - if (!f2 || !f2->basename) + if (!f2 || !F_IS_ACTIVE(f2)) return 1; c1 = (uchar*)f1->dirname; @@ -1766,7 +1862,7 @@ int f_name_cmp(struct file_struct *f1, struct file_struct *f2) c1 = c2 = NULL; if (!c1) { type1 = S_ISDIR(f1->mode) ? t_path : t_ITEM; - c1 = (uchar*)f1->basename; + c1 = (const uchar*)f1->basename; if (type1 == t_PATH && *c1 == '.' && !c1[1]) { type1 = t_ITEM; state1 = s_TRAILING; @@ -1779,7 +1875,7 @@ int f_name_cmp(struct file_struct *f1, struct file_struct *f2) } if (!c2) { type2 = S_ISDIR(f2->mode) ? t_path : t_ITEM; - c2 = (uchar*)f2->basename; + c2 = (const uchar*)f2->basename; if (type2 == t_PATH && *c2 == '.' && !c2[1]) { type2 = t_ITEM; state2 = s_TRAILING; @@ -1803,7 +1899,7 @@ int f_name_cmp(struct file_struct *f1, struct file_struct *f2) break; case s_SLASH: type1 = S_ISDIR(f1->mode) ? t_path : t_ITEM; - c1 = (uchar*)f1->basename; + c1 = (const uchar*)f1->basename; if (type1 == t_PATH && *c1 == '.' && !c1[1]) { type1 = t_ITEM; state1 = s_TRAILING; @@ -1833,7 +1929,7 @@ int f_name_cmp(struct file_struct *f1, struct file_struct *f2) break; case s_SLASH: type2 = S_ISDIR(f2->mode) ? t_path : t_ITEM; - c2 = (uchar*)f2->basename; + c2 = (const uchar*)f2->basename; if (type2 == t_PATH && *c2 == '.' && !c2[1]) { type2 = t_ITEM; state2 = s_TRAILING; @@ -1862,23 +1958,27 @@ int f_name_cmp(struct file_struct *f1, struct file_struct *f2) return dif; } +char *f_name_buf(void) +{ + static char names[5][MAXPATHLEN]; + static unsigned int n; + + n = (n + 1) % (sizeof names / sizeof names[0]); + + return names[n]; +} + /* Return a copy of the full filename of a flist entry, using the indicated * buffer or one of 5 static buffers if fbuf is NULL. No size-checking is * done because we checked the size when creating the file_struct entry. */ char *f_name(struct file_struct *f, char *fbuf) { - if (!f || !f->basename) + if (!f || !F_IS_ACTIVE(f)) return NULL; - if (!fbuf) { - static char names[5][MAXPATHLEN]; - static unsigned int n; - - n = (n + 1) % (sizeof names / sizeof names[0]); - - fbuf = names[n]; - } + if (!fbuf) + fbuf = f_name_buf(); if (f->dirname) { int len = strlen(f->dirname); @@ -1896,8 +1996,7 @@ char *f_name(struct file_struct *f, char *fbuf) * of the dirname string, and also indicates that "dirname" is a MAXPATHLEN * buffer (the functions we call will append names onto the end, but the old * dir value will be restored on exit). */ -struct file_list *get_dirlist(char *dirname, int dlen, - int ignore_filter_rules) +struct file_list *get_dirlist(char *dirname, int dlen, int ignore_filter_rules) { struct file_list *dirlist; char dirbuf[MAXPATHLEN]; @@ -1911,7 +2010,7 @@ struct file_list *get_dirlist(char *dirname, int dlen, dirname = dirbuf; } - dirlist = flist_new(WITHOUT_HLINK, "get_dirlist"); + dirlist = flist_new("get_dirlist"); recurse = 0; xfer_dirs = 1;