2 * Generate and receive file lists.
4 * Copyright (C) 1996 Andrew Tridgell
5 * Copyright (C) 1996 Paul Mackerras
6 * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
7 * Copyright (C) 2002-2007 Wayne Davison
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 3 as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, visit the http://fsf.org website.
32 extern int am_generator;
33 extern int inc_recurse;
34 extern int do_progress;
35 extern int always_checksum;
37 extern int ignore_errors;
38 extern int numeric_ids;
42 extern int filesfrom_fd;
43 extern int one_file_system;
44 extern int copy_dirlinks;
45 extern int keep_dirlinks;
46 extern int preserve_acls;
47 extern int preserve_xattrs;
48 extern int preserve_links;
49 extern int preserve_hard_links;
50 extern int preserve_devices;
51 extern int preserve_specials;
54 extern int relative_paths;
55 extern int implied_dirs;
56 extern int file_extra_cnt;
57 extern int ignore_perishable;
58 extern int non_perishable_cnt;
59 extern int prune_empty_dirs;
60 extern int copy_links;
61 extern int copy_unsafe_links;
62 extern int protocol_version;
63 extern int sanitize_paths;
64 extern struct stats stats;
66 extern char curr_dir[MAXPATHLEN];
68 extern struct chmod_mode_struct *chmod_modes;
70 extern struct filter_list_struct filter_list;
71 extern struct filter_list_struct server_filter_list;
75 extern int need_unsorted_flist;
76 extern iconv_t ic_send, ic_recv;
79 #define PTR_SIZE (sizeof (struct file_struct *))
83 dev_t filesystem_dev; /* used to implement -x */
85 struct file_list *cur_flist, *first_flist, *dir_flist;
86 int send_dir_ndx = -1, send_dir_depth = 0;
87 int flist_cnt = 0; /* how many (non-tmp) file list objects exist */
88 int file_total = 0; /* total of all active items over all file-lists */
89 int flist_eof = 0; /* all the file-lists are now known */
91 /* The tmp_* vars are used as a cache area by make_file() to store data
92 * that the sender doesn't need to remember in its file list. The data
93 * will survive just long enough to be used by send_file_entry(). */
94 static dev_t tmp_rdev;
95 #ifdef SUPPORT_HARD_LINKS
96 static int64 tmp_dev, tmp_ino;
98 static char tmp_sum[MAX_DIGEST_LEN];
100 static char empty_sum[MAX_DIGEST_LEN];
101 static int flist_count_offset; /* for --delete --progress */
102 static int dir_count = 0;
104 static void clean_flist(struct file_list *flist, int strip_root);
105 static void output_flist(struct file_list *flist);
107 void init_flist(void)
110 rprintf(FINFO, "FILE_STRUCT_LEN=%d, EXTRA_LEN=%d\n",
111 (int)FILE_STRUCT_LEN, (int)EXTRA_LEN);
113 checksum_len = protocol_version < 21 ? 2
114 : protocol_version < 30 ? MD4_DIGEST_LEN
118 static int show_filelist_p(void)
120 return verbose && xfer_dirs && !am_server && !inc_recurse;
123 static void start_filelist_progress(char *kind)
125 rprintf(FCLIENT, "%s ... ", kind);
126 if (verbose > 1 || do_progress)
127 rprintf(FCLIENT, "\n");
131 static void emit_filelist_progress(int count)
133 rprintf(FCLIENT, " %d files...\r", count);
136 static void maybe_emit_filelist_progress(int count)
138 if (do_progress && show_filelist_p() && (count % 100) == 0)
139 emit_filelist_progress(count);
142 static void finish_filelist_progress(const struct file_list *flist)
145 /* This overwrites the progress line */
146 rprintf(FINFO, "%d file%sto consider\n",
147 flist->used, flist->used == 1 ? " " : "s ");
149 rprintf(FINFO, "done\n");
152 void show_flist_stats(void)
157 static void list_file_entry(struct file_struct *f)
159 char permbuf[PERMSTRING_SIZE];
162 if (!F_IS_ACTIVE(f)) {
163 /* this can happen if duplicate names were removed */
167 permstring(permbuf, f->mode);
170 /* TODO: indicate '+' if the entry has an ACL. */
173 if (preserve_links && S_ISLNK(f->mode)) {
174 rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
175 permbuf, len, timestring(f->modtime),
176 f_name(f, NULL), F_SYMLINK(f));
180 rprintf(FINFO, "%s %11.0f %s %s\n",
181 permbuf, len, timestring(f->modtime),
186 /* Stat either a symlink or its referent, depending on the settings of
187 * copy_links, copy_unsafe_links, etc. Returns -1 on error, 0 on success.
189 * If path is the name of a symlink, then the linkbuf buffer (which must hold
190 * MAXPATHLEN chars) will be set to the symlink's target string.
192 * The stat structure pointed to by stp will contain information about the
193 * link or the referent as appropriate, if they exist. */
194 static int readlink_stat(const char *path, STRUCT_STAT *stp, char *linkbuf)
197 if (link_stat(path, stp, copy_dirlinks) < 0)
199 if (S_ISLNK(stp->st_mode)) {
200 int llen = readlink(path, linkbuf, MAXPATHLEN - 1);
203 linkbuf[llen] = '\0';
204 if (copy_unsafe_links && unsafe_symlink(linkbuf, path)) {
206 rprintf(FINFO,"copying unsafe symlink \"%s\" -> \"%s\"\n",
209 return x_stat(path, stp, NULL);
214 return x_stat(path, stp, NULL);
218 int link_stat(const char *path, STRUCT_STAT *stp, int follow_dirlinks)
222 return x_stat(path, stp, NULL);
223 if (x_lstat(path, stp, NULL) < 0)
225 if (follow_dirlinks && S_ISLNK(stp->st_mode)) {
227 if (x_stat(path, &st, NULL) == 0 && S_ISDIR(st.st_mode))
232 return x_stat(path, stp, NULL);
236 /* This function is used to check if a file should be included/excluded
237 * from the list of files based on its name and type etc. The value of
238 * filter_level is set to either SERVER_FILTERS or ALL_FILTERS. */
239 static int is_excluded(char *fname, int is_dir, int filter_level)
241 #if 0 /* This currently never happens, so avoid a useless compare. */
242 if (filter_level == NO_FILTERS)
246 /* never exclude '.', even if somebody does --exclude '*' */
247 if (fname[0] == '.' && !fname[1])
249 /* Handle the -R version of the '.' dir. */
250 if (fname[0] == '/') {
251 int len = strlen(fname);
252 if (fname[len-1] == '.' && fname[len-2] == '/')
256 if (server_filter_list.head
257 && check_filter(&server_filter_list, fname, is_dir) < 0)
259 if (filter_level != ALL_FILTERS)
262 && check_filter(&filter_list, fname, is_dir) < 0)
267 static void send_directory(int f, struct file_list *flist,
268 char *fbuf, int len, int flags);
270 static const char *pathname, *orig_dir;
271 static int pathname_len;
274 /* Make sure flist can hold at least flist->used + extra entries. */
275 static void flist_expand(struct file_list *flist, int extra)
277 struct file_struct **new_ptr;
279 if (flist->used + extra <= flist->malloced)
282 if (flist->malloced < FLIST_START)
283 flist->malloced = FLIST_START;
284 else if (flist->malloced >= FLIST_LINEAR)
285 flist->malloced += FLIST_LINEAR;
287 flist->malloced *= 2;
289 /* In case count jumped or we are starting the list
290 * with a known size just set it. */
291 if (flist->malloced < flist->used + extra)
292 flist->malloced = flist->used + extra;
294 new_ptr = realloc_array(flist->files, struct file_struct *,
297 if (verbose >= 2 && flist->malloced != FLIST_START) {
298 rprintf(FCLIENT, "[%s] expand file_list to %.0f bytes, did%s move\n",
300 (double)sizeof flist->files[0] * flist->malloced,
301 (new_ptr == flist->files) ? " not" : "");
304 flist->files = new_ptr;
307 out_of_memory("flist_expand");
310 static void flist_done_allocating(struct file_list *flist)
312 void *ptr = pool_boundary(flist->file_pool, 8*1024);
313 if (flist->pool_boundary == ptr)
314 flist->pool_boundary = NULL; /* list didn't use any pool memory */
316 flist->pool_boundary = ptr;
319 int push_pathname(const char *dir, int len)
325 orig_dir = strdup(curr_dir);
327 if (pathname && !pop_dir(orig_dir)) {
328 rsyserr(FERROR, errno, "pop_dir %s failed",
329 full_fname(orig_dir));
330 exit_cleanup(RERR_FILESELECT);
333 if (dir && !push_dir(dir, 0)) {
334 io_error |= IOERR_GENERAL;
335 rsyserr(FERROR, errno, "push_dir %s failed in %s",
336 full_fname(dir), curr_dir);
341 pathname_len = len >= 0 ? len : dir ? (int)strlen(dir) : 0;
346 static void send_file_entry(int f, struct file_struct *file, int ndx)
348 static time_t modtime;
352 static uint32 rdev_major;
355 static char *user_name, *group_name;
356 static char lastname[MAXPATHLEN];
357 char fname[MAXPATHLEN];
358 int first_hlink_ndx = -1;
363 if (ic_send != (iconv_t)-1) {
364 ICONV_CONST char *ibuf;
366 size_t ocnt = MAXPATHLEN, icnt;
368 iconv(ic_send, NULL,0, NULL,0);
369 if ((ibuf = (ICONV_CONST char *)file->dirname) != NULL) {
371 ocnt--; /* pre-subtract the space for the '/' */
372 if (iconv(ic_send, &ibuf,&icnt, &obuf,&ocnt) == (size_t)-1)
377 ibuf = (ICONV_CONST char *)file->basename;
379 if (iconv(ic_send, &ibuf,&icnt, &obuf,&ocnt) == (size_t)-1) {
381 io_error |= IOERR_GENERAL;
383 "[%s] cannot convert filename: %s (%s)\n",
384 who_am_i(), f_name(file, fname), strerror(errno));
392 flags = file->flags & FLAG_TOP_DIR; /* FLAG_TOP_DIR == XMIT_TOP_DIR */
394 if (file->mode == mode)
395 flags |= XMIT_SAME_MODE;
398 if ((preserve_devices && IS_DEVICE(mode))
399 || (preserve_specials && IS_SPECIAL(mode))) {
400 if (protocol_version < 28) {
401 if (tmp_rdev == rdev)
402 flags |= XMIT_SAME_RDEV_pre28;
407 if ((uint32)major(rdev) == rdev_major)
408 flags |= XMIT_SAME_RDEV_MAJOR;
410 rdev_major = major(rdev);
411 if (protocol_version < 30 && (uint32)minor(rdev) <= 0xFFu)
412 flags |= XMIT_RDEV_MINOR_8_pre30;
414 } else if (protocol_version < 28)
415 rdev = MAKEDEV(0, 0);
417 if ((uid_t)F_OWNER(file) == uid && *lastname)
418 flags |= XMIT_SAME_UID;
421 if (uid_ndx && !numeric_ids) {
422 user_name = add_uid(uid);
423 if (inc_recurse && user_name)
424 flags |= XMIT_USER_NAME_FOLLOWS;
429 if ((gid_t)F_GROUP(file) == gid && *lastname)
430 flags |= XMIT_SAME_GID;
433 if (gid_ndx && !numeric_ids) {
434 group_name = add_gid(gid);
435 if (inc_recurse && group_name)
436 flags |= XMIT_GROUP_NAME_FOLLOWS;
440 if (file->modtime == modtime)
441 flags |= XMIT_SAME_TIME;
443 modtime = file->modtime;
445 #ifdef SUPPORT_HARD_LINKS
447 if (protocol_version >= 30) {
448 struct idev_node *np = idev_node(tmp_dev, tmp_ino);
449 first_hlink_ndx = (int32)(long)np->data - 1;
450 if (first_hlink_ndx < 0) {
451 np->data = (void*)(long)(ndx + 1);
452 flags |= XMIT_HLINK_FIRST;
454 flags |= XMIT_HLINKED;
456 if (tmp_dev == dev) {
457 if (protocol_version >= 28)
458 flags |= XMIT_SAME_DEV_pre30;
461 flags |= XMIT_HLINKED;
467 lastname[l1] && (fname[l1] == lastname[l1]) && (l1 < 255);
469 l2 = strlen(fname+l1);
472 flags |= XMIT_SAME_NAME;
474 flags |= XMIT_LONG_NAME;
476 /* We must make sure we don't send a zero flag byte or the
477 * other end will terminate the flist transfer. Note that
478 * the use of XMIT_TOP_DIR on a non-dir has no meaning, so
479 * it's harmless way to add a bit to the first flag byte. */
480 if (protocol_version >= 28) {
481 if (!flags && !S_ISDIR(mode))
482 flags |= XMIT_TOP_DIR;
483 if ((flags & 0xFF00) || !flags) {
484 flags |= XMIT_EXTENDED_FLAGS;
485 write_shortint(f, flags);
487 write_byte(f, flags);
490 flags |= S_ISDIR(mode) ? XMIT_LONG_NAME : XMIT_TOP_DIR;
491 write_byte(f, flags);
493 if (flags & XMIT_SAME_NAME)
495 if (flags & XMIT_LONG_NAME)
496 write_varint30(f, l2);
499 write_buf(f, fname + l1, l2);
501 if (first_hlink_ndx >= 0) {
502 write_varint30(f, first_hlink_ndx);
506 write_varlong30(f, F_LENGTH(file), 3);
507 if (!(flags & XMIT_SAME_TIME)) {
508 if (protocol_version >= 30)
509 write_varlong(f, modtime, 4);
511 write_int(f, modtime);
513 if (!(flags & XMIT_SAME_MODE))
514 write_int(f, to_wire_mode(mode));
515 if (uid_ndx && !(flags & XMIT_SAME_UID)) {
516 if (protocol_version < 30)
519 write_varint(f, uid);
520 if (flags & XMIT_USER_NAME_FOLLOWS) {
521 int len = strlen(user_name);
523 write_buf(f, user_name, len);
527 if (gid_ndx && !(flags & XMIT_SAME_GID)) {
528 if (protocol_version < 30)
531 write_varint(f, gid);
532 if (flags & XMIT_GROUP_NAME_FOLLOWS) {
533 int len = strlen(group_name);
535 write_buf(f, group_name, len);
539 if ((preserve_devices && IS_DEVICE(mode))
540 || (preserve_specials && IS_SPECIAL(mode))) {
541 if (protocol_version < 28) {
542 if (!(flags & XMIT_SAME_RDEV_pre28))
543 write_int(f, (int)rdev);
545 if (!(flags & XMIT_SAME_RDEV_MAJOR))
546 write_varint30(f, major(rdev));
547 if (protocol_version >= 30)
548 write_varint(f, minor(rdev));
549 else if (flags & XMIT_RDEV_MINOR_8_pre30)
550 write_byte(f, minor(rdev));
552 write_int(f, minor(rdev));
557 if (preserve_links && S_ISLNK(mode)) {
558 const char *sl = F_SYMLINK(file);
559 int len = strlen(sl);
560 write_varint30(f, len);
561 write_buf(f, sl, len);
565 #ifdef SUPPORT_HARD_LINKS
566 if (tmp_dev != 0 && protocol_version < 30) {
567 if (protocol_version < 26) {
568 /* 32-bit dev_t and ino_t */
569 write_int(f, (int32)dev);
570 write_int(f, (int32)tmp_ino);
572 /* 64-bit dev_t and ino_t */
573 if (!(flags & XMIT_SAME_DEV_pre30))
574 write_longint(f, dev);
575 write_longint(f, tmp_ino);
580 if (always_checksum && (S_ISREG(mode) || protocol_version < 28)) {
585 /* Prior to 28, we sent a useless set of nulls. */
588 write_buf(f, sum, checksum_len);
592 strlcpy(lastname, fname, MAXPATHLEN);
594 if (S_ISREG(mode) || S_ISLNK(mode))
595 stats.total_size += F_LENGTH(file);
598 static struct file_struct *recv_file_entry(struct file_list *flist,
601 static int64 modtime;
605 static uint32 rdev_major;
608 static uint16 gid_flags;
609 static char lastname[MAXPATHLEN], *lastdir;
610 static int lastdir_depth, lastdir_len = -1;
611 static unsigned int del_hier_name_len = 0;
612 static int in_del_hier = 0;
613 char thisname[MAXPATHLEN];
614 unsigned int l1 = 0, l2 = 0;
615 int alloc_len, basename_len, linkname_len;
616 int extra_len = file_extra_cnt * EXTRA_LEN;
617 int first_hlink_ndx = -1;
619 const char *basename;
620 struct file_struct *file;
624 if (xflags & XMIT_SAME_NAME)
627 if (xflags & XMIT_LONG_NAME)
628 l2 = read_varint30(f);
632 if (l2 >= MAXPATHLEN - l1) {
634 "overflow: xflags=0x%x l1=%d l2=%d lastname=%s [%s]\n",
635 xflags, l1, l2, lastname, who_am_i());
636 overflow_exit("recv_file_entry");
639 strlcpy(thisname, lastname, l1 + 1);
640 read_sbuf(f, &thisname[l1], l2);
641 thisname[l1 + l2] = 0;
643 /* Abuse basename_len for a moment... */
644 basename_len = strlcpy(lastname, thisname, MAXPATHLEN);
647 if (ic_recv != (iconv_t)-1) {
648 char *obuf = thisname;
649 ICONV_CONST char *ibuf = (ICONV_CONST char *)lastname;
650 size_t ocnt = MAXPATHLEN, icnt = basename_len;
652 if (icnt >= MAXPATHLEN) {
657 iconv(ic_recv, NULL,0, NULL,0);
658 if (iconv(ic_recv, &ibuf,&icnt, &obuf,&ocnt) == (size_t)-1) {
660 io_error |= IOERR_GENERAL;
662 "[%s] cannot convert filename: %s (%s)\n",
663 who_am_i(), lastname, strerror(errno));
670 clean_fname(thisname, 0);
673 sanitize_path(thisname, thisname, "", 0, NULL);
675 if ((basename = strrchr(thisname, '/')) != NULL) {
676 int len = basename++ - thisname;
677 if (len != lastdir_len || memcmp(thisname, lastdir, len) != 0) {
678 lastdir = new_array(char, len + 1);
679 memcpy(lastdir, thisname, len);
682 lastdir_depth = count_dir_elements(lastdir);
686 basename_len = strlen(basename) + 1; /* count the '\0' */
688 #ifdef SUPPORT_HARD_LINKS
689 if (protocol_version >= 30
690 && BITS_SETnUNSET(xflags, XMIT_HLINKED, XMIT_HLINK_FIRST)) {
691 struct file_struct *first;
692 first_hlink_ndx = read_varint30(f);
693 if (first_hlink_ndx < 0 || first_hlink_ndx >= flist->used) {
695 "hard-link reference out of range: %d (%d)\n",
696 first_hlink_ndx, flist->used);
697 exit_cleanup(RERR_PROTOCOL);
699 first = flist->files[first_hlink_ndx];
700 file_length = F_LENGTH(first);
701 modtime = first->modtime;
704 uid = F_OWNER(first);
706 gid = F_GROUP(first);
707 if ((preserve_devices && IS_DEVICE(mode))
708 || (preserve_specials && IS_SPECIAL(mode))) {
709 uint32 *devp = F_RDEV_P(first);
710 rdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp));
711 extra_len += 2 * EXTRA_LEN;
713 if (preserve_links && S_ISLNK(mode))
714 linkname_len = strlen(F_SYMLINK(first)) + 1;
721 file_length = read_varlong30(f, 3);
722 if (!(xflags & XMIT_SAME_TIME)) {
723 if (protocol_version >= 30) {
724 modtime = read_varlong(f, 4);
725 #if SIZEOF_TIME_T < SIZEOF_INT64
726 if ((modtime > INT_MAX || modtime < INT_MIN) && !am_generator) {
728 "Time value of %s truncated on receiver.\n",
733 modtime = read_int(f);
735 if (!(xflags & XMIT_SAME_MODE))
736 mode = from_wire_mode(read_int(f));
738 if (chmod_modes && !S_ISLNK(mode))
739 mode = tweak_mode(mode, chmod_modes);
741 if (uid_ndx && !(xflags & XMIT_SAME_UID)) {
742 if (protocol_version < 30)
743 uid = (uid_t)read_int(f);
745 uid = (uid_t)read_varint(f);
746 if (xflags & XMIT_USER_NAME_FOLLOWS)
747 uid = recv_user_name(f, uid);
748 else if (inc_recurse && am_root && !numeric_ids)
749 uid = match_uid(uid);
752 if (gid_ndx && !(xflags & XMIT_SAME_GID)) {
753 if (protocol_version < 30)
754 gid = (gid_t)read_int(f);
756 gid = (gid_t)read_varint(f);
758 if (xflags & XMIT_GROUP_NAME_FOLLOWS)
759 gid = recv_group_name(f, gid, &gid_flags);
760 else if (inc_recurse && (!am_root || !numeric_ids))
761 gid = match_gid(gid, &gid_flags);
765 if ((preserve_devices && IS_DEVICE(mode))
766 || (preserve_specials && IS_SPECIAL(mode))) {
767 if (protocol_version < 28) {
768 if (!(xflags & XMIT_SAME_RDEV_pre28))
769 rdev = (dev_t)read_int(f);
772 if (!(xflags & XMIT_SAME_RDEV_MAJOR))
773 rdev_major = read_varint30(f);
774 if (protocol_version >= 30)
775 rdev_minor = read_varint(f);
776 else if (xflags & XMIT_RDEV_MINOR_8_pre30)
777 rdev_minor = read_byte(f);
779 rdev_minor = read_int(f);
780 rdev = MAKEDEV(rdev_major, rdev_minor);
782 extra_len += 2 * EXTRA_LEN;
784 } else if (protocol_version < 28)
785 rdev = MAKEDEV(0, 0);
788 if (preserve_links && S_ISLNK(mode)) {
789 linkname_len = read_varint30(f) + 1; /* count the '\0' */
790 if (linkname_len <= 0 || linkname_len > MAXPATHLEN) {
791 rprintf(FERROR, "overflow: linkname_len=%d\n",
793 overflow_exit("recv_file_entry");
800 #ifdef SUPPORT_HARD_LINKS
802 if (preserve_hard_links) {
803 if (protocol_version < 28 && S_ISREG(mode))
804 xflags |= XMIT_HLINKED;
805 if (xflags & XMIT_HLINKED)
806 extra_len += EXTRA_LEN;
811 /* We need one or two index int32s when we're preserving ACLs. */
813 extra_len += (S_ISDIR(mode) ? 2 : 1) * EXTRA_LEN;
816 if (always_checksum && S_ISREG(mode))
817 extra_len += SUM_EXTRA_CNT * EXTRA_LEN;
819 if (file_length > 0xFFFFFFFFu && S_ISREG(mode))
820 extra_len += EXTRA_LEN;
822 #if EXTRA_ROUNDING > 0
823 if (extra_len & (EXTRA_ROUNDING * EXTRA_LEN))
824 extra_len = (extra_len | (EXTRA_ROUNDING * EXTRA_LEN)) + EXTRA_LEN;
827 if (inc_recurse && S_ISDIR(mode)) {
828 if (one_file_system) {
829 /* Room to save the dir's device for -x */
830 extra_len += 2 * EXTRA_LEN;
832 pool = dir_flist->file_pool;
834 pool = flist->file_pool;
836 alloc_len = FILE_STRUCT_LEN + extra_len + basename_len
838 bp = pool_alloc(pool, alloc_len, "recv_file_entry");
840 memset(bp, 0, extra_len + FILE_STRUCT_LEN);
842 file = (struct file_struct *)bp;
843 bp += FILE_STRUCT_LEN;
845 memcpy(bp, basename, basename_len);
846 bp += basename_len + linkname_len; /* skip space for symlink too */
848 #ifdef SUPPORT_HARD_LINKS
849 if (xflags & XMIT_HLINKED)
850 file->flags |= FLAG_HLINKED;
852 file->modtime = (time_t)modtime;
853 file->len32 = (uint32)file_length;
854 if (file_length > 0xFFFFFFFFu && S_ISREG(mode)) {
855 file->flags |= FLAG_LENGTH64;
856 OPT_EXTRA(file, 0)->unum = (uint32)(file_length >> 32);
863 file->flags |= gid_flags;
867 F_NDX(file) = flist->used + flist->ndx_start;
870 if (basename != thisname) {
871 file->dirname = lastdir;
872 F_DEPTH(file) = lastdir_depth + 1;
877 if (basename_len == 1+1 && *basename == '.') /* +1 for '\0' */
879 if (xflags & XMIT_TOP_DIR) {
880 in_del_hier = recurse;
881 del_hier_name_len = F_DEPTH(file) == 0 ? 0 : l1 + l2;
882 if (relative_paths && del_hier_name_len > 2
883 && lastname[del_hier_name_len-1] == '.'
884 && lastname[del_hier_name_len-2] == '/')
885 del_hier_name_len -= 2;
886 file->flags |= FLAG_TOP_DIR | FLAG_XFER_DIR;
887 } else if (in_del_hier) {
888 if (!relative_paths || !del_hier_name_len
889 || (l1 >= del_hier_name_len
890 && lastname[del_hier_name_len] == '/'))
891 file->flags |= FLAG_XFER_DIR;
897 if ((preserve_devices && IS_DEVICE(mode))
898 || (preserve_specials && IS_SPECIAL(mode))) {
899 uint32 *devp = F_RDEV_P(file);
900 DEV_MAJOR(devp) = major(rdev);
901 DEV_MINOR(devp) = minor(rdev);
906 bp = (char*)file->basename + basename_len;
907 if (first_hlink_ndx >= 0) {
908 struct file_struct *first = flist->files[first_hlink_ndx];
909 memcpy(bp, F_SYMLINK(first), linkname_len);
911 read_sbuf(f, bp, linkname_len - 1);
913 sanitize_path(bp, bp, "", lastdir_depth, NULL);
917 #ifdef SUPPORT_HARD_LINKS
918 if (preserve_hard_links && xflags & XMIT_HLINKED) {
919 if (protocol_version >= 30) {
920 F_HL_GNUM(file) = xflags & XMIT_HLINK_FIRST
921 ? flist->used : first_hlink_ndx;
923 static int32 cnt = 0;
924 struct idev_node *np;
927 if (protocol_version < 26) {
931 if (!(xflags & XMIT_SAME_DEV_pre30))
932 dev = read_longint(f);
933 ino = read_longint(f);
935 np = idev_node(dev, ino);
936 ndx = (int32)(long)np->data - 1;
939 np->data = (void*)(long)cnt;
941 F_HL_GNUM(file) = ndx;
946 if (always_checksum && (S_ISREG(mode) || protocol_version < 28)) {
948 bp = (char*)F_SUM(file);
950 /* Prior to 28, we get a useless set of nulls. */
953 if (first_hlink_ndx >= 0) {
954 struct file_struct *first = flist->files[first_hlink_ndx];
955 memcpy(bp, F_SUM(first), checksum_len);
957 read_buf(f, bp, checksum_len);
961 if (preserve_acls && !S_ISLNK(mode))
962 receive_acl(file, f);
964 #ifdef SUPPORT_XATTRS
966 receive_xattr(file, f );
969 if (S_ISREG(mode) || S_ISLNK(mode))
970 stats.total_size += file_length;
976 * Create a file_struct for a named file by reading its stat()
977 * information and performing extensive checks against global
980 * @return the new file, or NULL if there was an error or this file
981 * should be excluded.
983 * @todo There is a small optimization opportunity here to avoid
984 * stat()ing the file in some circumstances, which has a certain cost.
985 * We are called immediately after doing readdir(), and so we may
986 * already know the d_type of the file. We could for example avoid
987 * statting directories if we're not recursing, but this is not a very
988 * important case. Some systems may not have d_type.
990 struct file_struct *make_file(const char *fname, struct file_list *flist,
991 STRUCT_STAT *stp, int flags, int filter_level)
993 static char *lastdir;
994 static int lastdir_len = -1;
995 struct file_struct *file;
997 char thisname[MAXPATHLEN];
998 char linkname[MAXPATHLEN];
999 int alloc_len, basename_len, linkname_len;
1000 int extra_len = file_extra_cnt * EXTRA_LEN;
1001 const char *basename;
1005 if (strlcpy(thisname, fname, sizeof thisname) >= sizeof thisname) {
1006 rprintf(FINFO, "skipping overly long name: %s\n", fname);
1009 clean_fname(thisname, 0);
1011 sanitize_path(thisname, thisname, "", 0, NULL);
1013 if (stp && S_ISDIR(stp->st_mode)) {
1014 st = *stp; /* Needed for "symlink/." with --relative. */
1015 *linkname = '\0'; /* make IBM code checker happy */
1016 } else if (readlink_stat(thisname, &st, linkname) != 0) {
1017 int save_errno = errno;
1018 /* See if file is excluded before reporting an error. */
1019 if (filter_level != NO_FILTERS
1020 && (is_excluded(thisname, 0, filter_level)
1021 || is_excluded(thisname, 1, filter_level))) {
1022 if (ignore_perishable && save_errno != ENOENT)
1023 non_perishable_cnt++;
1026 if (save_errno == ENOENT) {
1027 #ifdef SUPPORT_LINKS
1028 /* Avoid "vanished" error if symlink points nowhere. */
1029 if (copy_links && x_lstat(thisname, &st, NULL) == 0
1030 && S_ISLNK(st.st_mode)) {
1031 io_error |= IOERR_GENERAL;
1032 rprintf(FERROR, "symlink has no referent: %s\n",
1033 full_fname(thisname));
1037 enum logcode c = am_daemon && protocol_version < 28
1039 io_error |= IOERR_VANISHED;
1040 rprintf(c, "file has vanished: %s\n",
1041 full_fname(thisname));
1044 io_error |= IOERR_GENERAL;
1045 rsyserr(FERROR, save_errno, "readlink %s failed",
1046 full_fname(thisname));
1051 /* backup.c calls us with filter_level set to NO_FILTERS. */
1052 if (filter_level == NO_FILTERS)
1055 if (S_ISDIR(st.st_mode) && !xfer_dirs) {
1056 rprintf(FINFO, "skipping directory %s\n", thisname);
1060 /* -x only affects directories because we need to avoid recursing
1061 * into a mount-point directory, not to avoid copying a symlinked
1062 * file if -L (or similar) was specified. */
1063 if (one_file_system && st.st_dev != filesystem_dev
1064 && S_ISDIR(st.st_mode)) {
1065 if (one_file_system > 1) {
1067 rprintf(FINFO, "skipping mount-point dir %s\n",
1072 flags |= FLAG_MOUNT_DIR;
1075 if (is_excluded(thisname, S_ISDIR(st.st_mode) != 0, filter_level)) {
1076 if (ignore_perishable)
1077 non_perishable_cnt++;
1081 if (lp_ignore_nonreadable(module_id)) {
1082 #ifdef SUPPORT_LINKS
1083 if (!S_ISLNK(st.st_mode))
1085 if (access(thisname, R_OK) != 0)
1091 /* Only divert a directory in the main transfer. */
1093 if (flist->prev && S_ISDIR(st.st_mode)
1094 && flags & FLAG_DIVERT_DIRS) {
1095 /* Room for parent/sibling/next-child info. */
1096 extra_len += 3 * EXTRA_LEN;
1098 pool = dir_flist->file_pool;
1100 pool = flist->file_pool;
1105 rprintf(FINFO, "[%s] make_file(%s,*,%d)\n",
1106 who_am_i(), thisname, filter_level);
1109 if ((basename = strrchr(thisname, '/')) != NULL) {
1110 int len = basename++ - thisname;
1111 if (len != lastdir_len || memcmp(thisname, lastdir, len) != 0) {
1112 lastdir = new_array(char, len + 1);
1113 memcpy(lastdir, thisname, len);
1114 lastdir[len] = '\0';
1118 basename = thisname;
1119 basename_len = strlen(basename) + 1; /* count the '\0' */
1121 #ifdef SUPPORT_LINKS
1122 linkname_len = S_ISLNK(st.st_mode) ? strlen(linkname) + 1 : 0;
1127 if (st.st_size > 0xFFFFFFFFu && S_ISREG(st.st_mode))
1128 extra_len += EXTRA_LEN;
1130 #if EXTRA_ROUNDING > 0
1131 if (extra_len & (EXTRA_ROUNDING * EXTRA_LEN))
1132 extra_len = (extra_len | (EXTRA_ROUNDING * EXTRA_LEN)) + EXTRA_LEN;
1135 alloc_len = FILE_STRUCT_LEN + extra_len + basename_len
1138 bp = pool_alloc(pool, alloc_len, "make_file");
1140 if (!(bp = new_array(char, alloc_len)))
1141 out_of_memory("make_file");
1144 memset(bp, 0, extra_len + FILE_STRUCT_LEN);
1146 file = (struct file_struct *)bp;
1147 bp += FILE_STRUCT_LEN;
1149 memcpy(bp, basename, basename_len);
1150 bp += basename_len + linkname_len; /* skip space for symlink too */
1152 #ifdef SUPPORT_HARD_LINKS
1153 if (preserve_hard_links && flist && flist->prev) {
1154 if (protocol_version >= 28
1155 ? (!S_ISDIR(st.st_mode) && st.st_nlink > 1)
1156 : S_ISREG(st.st_mode)) {
1157 tmp_dev = st.st_dev;
1158 tmp_ino = st.st_ino;
1164 #ifdef HAVE_STRUCT_STAT_ST_RDEV
1165 if (IS_DEVICE(st.st_mode) || IS_SPECIAL(st.st_mode)) {
1166 tmp_rdev = st.st_rdev;
1171 file->flags = flags;
1172 file->modtime = st.st_mtime;
1173 file->len32 = (uint32)st.st_size;
1174 if (st.st_size > 0xFFFFFFFFu && S_ISREG(st.st_mode)) {
1175 file->flags |= FLAG_LENGTH64;
1176 OPT_EXTRA(file, 0)->unum = (uint32)(st.st_size >> 32);
1178 file->mode = st.st_mode;
1180 F_OWNER(file) = st.st_uid;
1182 F_GROUP(file) = st.st_gid;
1184 if (basename != thisname)
1185 file->dirname = lastdir;
1187 #ifdef SUPPORT_LINKS
1189 bp = (char*)file->basename + basename_len;
1190 memcpy(bp, linkname, linkname_len);
1194 if (always_checksum && am_sender && S_ISREG(st.st_mode))
1195 file_checksum(thisname, tmp_sum, st.st_size);
1197 F_PATHNAME(file) = pathname;
1199 /* This code is only used by the receiver when it is building
1200 * a list of files for a delete pass. */
1201 if (keep_dirlinks && linkname_len && flist) {
1203 int save_mode = file->mode;
1204 file->mode = S_IFDIR; /* Find a directory with our name. */
1205 if (flist_find(dir_flist, file) >= 0
1206 && x_stat(thisname, &st2, NULL) == 0 && S_ISDIR(st2.st_mode)) {
1207 file->modtime = st2.st_mtime;
1209 file->mode = st2.st_mode;
1211 F_OWNER(file) = st2.st_uid;
1213 F_GROUP(file) = st2.st_gid;
1215 file->mode = save_mode;
1218 if (basename_len == 0+1)
1223 F_NDX(file) = dir_count - 1;
1229 /* Only called for temporary file_struct entries created by make_file(). */
1230 void unmake_file(struct file_struct *file)
1232 int extra_cnt = file_extra_cnt + LEN64_BUMP(file);
1233 #if EXTRA_ROUNDING > 0
1234 if (extra_cnt & EXTRA_ROUNDING)
1235 extra_cnt = (extra_cnt | EXTRA_ROUNDING) + 1;
1237 free(REQ_EXTRA(file, extra_cnt));
1240 static struct file_struct *send_file_name(int f, struct file_list *flist,
1241 char *fname, STRUCT_STAT *stp,
1242 int flags, int filter_flags)
1244 struct file_struct *file;
1245 #if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
1249 file = make_file(fname, flist, stp, flags, filter_flags);
1253 if (chmod_modes && !S_ISLNK(file->mode))
1254 file->mode = tweak_mode(file->mode, chmod_modes);
1257 if (preserve_acls && !S_ISLNK(file->mode) && f >= 0) {
1258 sx.st.st_mode = file->mode;
1259 sx.acc_acl = sx.def_acl = NULL;
1260 if (get_acl(fname, &sx) < 0)
1264 #ifdef SUPPORT_XATTRS
1265 if (preserve_xattrs && f >= 0) {
1267 if (get_xattr(fname, &sx) < 0)
1272 maybe_emit_filelist_progress(flist->used + flist_count_offset);
1274 flist_expand(flist, 1);
1275 flist->files[flist->used++] = file;
1277 send_file_entry(f, file, flist->used - 1);
1279 if (preserve_acls && !S_ISLNK(file->mode)) {
1284 #ifdef SUPPORT_XATTRS
1285 if (preserve_xattrs) {
1286 F_XATTR(file) = send_xattr(&sx, f);
1294 static void send_if_directory(int f, struct file_list *flist,
1295 struct file_struct *file,
1296 char *fbuf, unsigned int ol,
1299 char is_dot_dir = fbuf[ol-1] == '.' && (ol == 1 || fbuf[ol-2] == '/');
1301 if (S_ISDIR(file->mode)
1302 && !(file->flags & FLAG_MOUNT_DIR) && f_name(file, fbuf)) {
1304 unsigned int len = strlen(fbuf);
1305 if (len > 1 && fbuf[len-1] == '/')
1307 if (len >= MAXPATHLEN - 1) {
1308 io_error |= IOERR_GENERAL;
1309 rprintf(FERROR, "skipping long-named directory: %s\n",
1313 save_filters = push_local_filters(fbuf, len);
1314 send_directory(f, flist, fbuf, len, flags);
1315 pop_local_filters(save_filters);
1322 static int file_compare(const void *file1, const void *file2)
1324 return f_name_cmp(*(struct file_struct **)file1,
1325 *(struct file_struct **)file2);
1328 /* The guts of a merge-sort algorithm. This was derived from the glibc
1329 * version, but I (Wayne) changed the merge code to do less copying and
1330 * to require only half the amount of temporary memory. */
1331 static void fsort_tmp(struct file_struct **fp, size_t num,
1332 struct file_struct **tmp)
1334 struct file_struct **f1, **f2, **t;
1343 fsort_tmp(f1, n1, tmp);
1345 fsort_tmp(f2, n2, tmp);
1347 while (f_name_cmp(*f1, *f2) <= 0) {
1354 memcpy(t, f1, n1 * PTR_SIZE);
1356 *f1++ = *f2++, n2--;
1358 while (n1 > 0 && n2 > 0) {
1359 if (f_name_cmp(*t, *f2) <= 0)
1362 *f1++ = *f2++, n2--;
1366 memcpy(f1, t, n1 * PTR_SIZE);
1369 /* This file-struct sorting routine makes sure that any identical names in
1370 * the file list stay in the same order as they were in the original list.
1371 * This is particularly vital in inc_recurse mode where we expect a sort
1372 * on the flist to match the exact order of a sort on the dir_flist. */
1373 static void fsort(struct file_struct **fp, size_t num)
1379 qsort(fp, num, PTR_SIZE, file_compare);
1381 struct file_struct **tmp = new_array(struct file_struct *,
1383 fsort_tmp(fp, num, tmp);
1388 /* We take an entire set of sibling dirs from the sorted flist and link them
1389 * into the tree, setting the appropriate parent/child/sibling pointers. */
1390 static void add_dirs_to_tree(int parent_ndx, struct file_list *from_flist,
1395 int32 *parent_dp = parent_ndx < 0 ? NULL
1396 : F_DIRNODE_P(dir_flist->sorted[parent_ndx]);
1398 flist_expand(dir_flist, dir_cnt);
1399 dir_flist->sorted = dir_flist->files;
1401 for (i = 0; dir_cnt; i++) {
1402 struct file_struct *file = from_flist->sorted[i];
1404 if (!S_ISDIR(file->mode))
1407 dir_flist->files[dir_flist->used++] = file;
1410 if (!(file->flags & FLAG_XFER_DIR)
1411 || file->flags & FLAG_MOUNT_DIR)
1415 DIR_NEXT_SIBLING(dp) = dir_flist->used - 1;
1417 DIR_FIRST_CHILD(parent_dp) = dir_flist->used - 1;
1419 send_dir_ndx = dir_flist->used - 1;
1421 dp = F_DIRNODE_P(file);
1422 DIR_PARENT(dp) = parent_ndx;
1423 DIR_FIRST_CHILD(dp) = -1;
1426 DIR_NEXT_SIBLING(dp) = -1;
1429 /* This function is normally called by the sender, but the receiving side also
1430 * calls it from get_dirlist() with f set to -1 so that we just construct the
1431 * file list in memory without sending it over the wire. Also, get_dirlist()
1432 * might call this with f set to -2, which also indicates that local filter
1433 * rules should be ignored. */
1434 static void send_directory(int f, struct file_list *flist, char *fbuf, int len,
1441 int divert_dirs = (flags & FLAG_DIVERT_DIRS) != 0;
1442 int start = flist->used;
1443 int filter_flags = f == -2 ? SERVER_FILTERS : ALL_FILTERS;
1445 assert(flist != NULL);
1447 if (!(d = opendir(fbuf))) {
1448 io_error |= IOERR_GENERAL;
1449 rsyserr(FERROR, errno, "opendir %s failed", full_fname(fbuf));
1454 if (len != 1 || *fbuf != '/')
1457 remainder = MAXPATHLEN - (p - fbuf);
1459 for (errno = 0, di = readdir(d); di; errno = 0, di = readdir(d)) {
1460 char *dname = d_name(di);
1461 if (dname[0] == '.' && (dname[1] == '\0'
1462 || (dname[1] == '.' && dname[2] == '\0')))
1464 if (strlcpy(p, dname, remainder) >= remainder) {
1465 io_error |= IOERR_GENERAL;
1467 "cannot send long-named file %s\n",
1472 send_file_name(f, flist, fbuf, NULL, flags, filter_flags);
1478 io_error |= IOERR_GENERAL;
1479 rsyserr(FERROR, errno, "readdir(%s)", full_fname(fbuf));
1484 if (f >= 0 && recurse && !divert_dirs) {
1485 int i, end = flist->used - 1;
1486 /* send_if_directory() bumps flist->used, so use "end". */
1487 for (i = start; i <= end; i++)
1488 send_if_directory(f, flist, flist->files[i], fbuf, len, flags);
1492 static void send1extra(int f, struct file_struct *file, struct file_list *flist)
1494 char fbuf[MAXPATHLEN];
1498 dlen = strlen(fbuf);
1500 if (F_PATHNAME(file) != pathname) {
1501 if (!push_pathname(F_PATHNAME(file), -1))
1502 exit_cleanup(RERR_FILESELECT);
1505 change_local_filter_dir(fbuf, dlen, send_dir_depth);
1507 send_directory(f, flist, fbuf, dlen, FLAG_DIVERT_DIRS | FLAG_XFER_DIR);
1510 void send_extra_file_list(int f, int at_least)
1512 struct file_list *flist;
1514 int future_cnt, save_io_error = io_error;
1519 /* Keep sending data until we have the requested number of
1520 * files in the upcoming file-lists. */
1521 if (cur_flist->next) {
1522 flist = first_flist->prev; /* the newest flist */
1523 future_cnt = flist->ndx_end - cur_flist->next->ndx_start + 1;
1526 while (future_cnt < at_least) {
1527 struct file_struct *file = dir_flist->sorted[send_dir_ndx];
1528 int dir_ndx, dstart = dir_count;
1531 flist = flist_new(0, "send_extra_file_list");
1532 start_write = stats.total_written;
1536 dir_ndx = F_NDX(file);
1539 dir_ndx = send_dir_ndx;
1540 write_ndx(f, NDX_FLIST_OFFSET - dir_ndx);
1541 flist->parent_ndx = dir_ndx;
1543 send1extra(f, file, flist);
1544 dp = F_DIRNODE_P(file);
1546 /* If there are any duplicate directory names that follow, we
1547 * send all the dirs together in one file-list. The dir_flist
1548 * tree links all the child subdirs onto the last dup dir. */
1549 while ((dir_ndx = DIR_NEXT_SIBLING(dp)) >= 0
1550 && dir_flist->sorted[dir_ndx]->flags & FLAG_DUPLICATE) {
1551 send_dir_ndx = dir_ndx;
1552 file = dir_flist->sorted[dir_ndx];
1553 send1extra(f, file, flist);
1554 dp = F_DIRNODE_P(file);
1560 if (need_unsorted_flist) {
1561 if (!(flist->sorted = new_array(struct file_struct *, flist->used)))
1562 out_of_memory("send_extra_file_list");
1563 memcpy(flist->sorted, flist->files,
1564 flist->used * sizeof (struct file_struct*));
1567 flist->sorted = flist->files;
1569 clean_flist(flist, 0);
1571 flist->ndx_end = flist->ndx_start + flist->used - 1
1572 - (dir_count - dstart);
1574 add_dirs_to_tree(send_dir_ndx, flist, dir_count - dstart);
1575 flist_done_allocating(flist);
1577 file_total += flist->used;
1578 future_cnt += flist->used;
1579 stats.flist_size += stats.total_written - start_write;
1580 stats.num_files += flist->used;
1582 output_flist(flist);
1584 if (DIR_FIRST_CHILD(dp) >= 0) {
1585 send_dir_ndx = DIR_FIRST_CHILD(dp);
1588 while (DIR_NEXT_SIBLING(dp) < 0) {
1589 if ((send_dir_ndx = DIR_PARENT(dp)) < 0) {
1590 write_ndx(f, NDX_FLIST_EOF);
1592 change_local_filter_dir(NULL, 0, 0);
1596 file = dir_flist->sorted[send_dir_ndx];
1597 dp = F_DIRNODE_P(file);
1599 send_dir_ndx = DIR_NEXT_SIBLING(dp);
1604 if (io_error != save_io_error && !ignore_errors)
1605 send_msg_int(MSG_IO_ERROR, io_error);
1608 struct file_list *send_file_list(int f, int argc, char *argv[])
1610 static const char *lastdir;
1611 static int lastdir_len = -1;
1615 char lastpath[MAXPATHLEN] = "";
1616 struct file_list *flist;
1617 struct timeval start_tv, end_tv;
1620 int flags, disable_buffering;
1622 rprintf(FLOG, "building file list\n");
1623 if (show_filelist_p())
1624 start_filelist_progress("building file list");
1625 else if (inc_recurse && verbose && !am_server)
1626 rprintf(FCLIENT, "sending incremental file list\n");
1628 start_write = stats.total_written;
1629 gettimeofday(&start_tv, NULL);
1631 #ifdef SUPPORT_HARD_LINKS
1632 if (preserve_hard_links && protocol_version >= 30 && !cur_flist)
1636 flist = cur_flist = flist_new(0, "send_file_list");
1638 dir_flist = flist_new(FLIST_TEMP, "send_file_list");
1639 flags = FLAG_DIVERT_DIRS;
1641 dir_flist = cur_flist;
1645 disable_buffering = io_start_buffering_out(f);
1646 if (filesfrom_fd >= 0) {
1647 if (argv[0] && !push_dir(argv[0], 0)) {
1648 rsyserr(FERROR, errno, "push_dir %s failed in %s",
1649 full_fname(argv[0]), curr_dir);
1650 exit_cleanup(RERR_FILESELECT);
1656 char fbuf[MAXPATHLEN];
1661 if (read_filesfrom_line(filesfrom_fd, fbuf) == 0)
1663 sanitize_path(fbuf, fbuf, "", 0, NULL);
1667 strlcpy(fbuf, *argv++, MAXPATHLEN);
1669 sanitize_path(fbuf, fbuf, "", 0, NULL);
1673 if (relative_paths) {
1674 /* We clean up fbuf below. */
1676 } else if (!len || fbuf[len - 1] == '/') {
1677 if (len == 2 && fbuf[0] == '.') {
1678 /* Turn "./" into just "." rather than "./." */
1681 if (len + 1 >= MAXPATHLEN)
1682 overflow_exit("send_file_list");
1687 } else if (len > 1 && fbuf[len-1] == '.' && fbuf[len-2] == '.'
1688 && (len == 2 || fbuf[len-3] == '/')) {
1689 if (len + 2 >= MAXPATHLEN)
1690 overflow_exit("send_file_list");
1696 is_dot_dir = fbuf[len-1] == '.'
1697 && (len == 1 || fbuf[len-2] == '/');
1702 if (!relative_paths) {
1703 p = strrchr(fbuf, '/');
1710 len -= p - fbuf + 1;
1715 if ((p = strstr(fbuf, "/./")) != NULL) {
1721 len -= p - fbuf + 3;
1725 /* Get rid of trailing "/" and "/.". */
1727 if (fn[len - 1] == '/') {
1729 if (!--len && !dir) {
1734 else if (len >= 2 && fn[len - 1] == '.'
1735 && fn[len - 2] == '/') {
1737 if (!(len -= 2) && !dir) {
1744 if (len == 1 && fn[0] == '/')
1747 /* Reject a ".." dir in the active part of the path. */
1748 for (p = fn; (p = strstr(p, "..")) != NULL; p += 2) {
1749 if ((p[2] == '/' || p[2] == '\0')
1750 && (p == fn || p[-1] == '/')) {
1752 "found \"..\" dir in relative path: %s\n",
1754 exit_cleanup(RERR_SYNTAX);
1764 dirlen = dir ? strlen(dir) : 0;
1765 if (dirlen != lastdir_len || memcmp(lastdir, dir, dirlen) != 0) {
1766 if (!push_pathname(dir ? strdup(dir) : NULL, dirlen))
1769 lastdir_len = pathname_len;
1770 } else if (!push_pathname(lastdir, lastdir_len)) {
1772 io_error |= IOERR_GENERAL;
1773 rsyserr(FERROR, errno, "push_dir %s failed in %s",
1774 full_fname(dir), curr_dir);
1779 memmove(fbuf, fn, len + 1);
1781 if (link_stat(fbuf, &st, copy_dirlinks) != 0) {
1782 io_error |= IOERR_GENERAL;
1783 rsyserr(FERROR, errno, "link_stat %s failed",
1788 if (S_ISDIR(st.st_mode) && !xfer_dirs) {
1789 rprintf(FINFO, "skipping directory %s\n", fbuf);
1793 if (implied_dirs && (p=strrchr(fbuf,'/')) && p != fbuf) {
1794 /* Send the implied directories at the start of the
1795 * source spec, so we get their permissions right. */
1796 char *lp = lastpath, *slash = fbuf;
1798 /* Skip any initial directories in our path that we
1799 * have in common with lastpath. */
1800 for (fn = fbuf; *fn && *lp == *fn; lp++, fn++) {
1805 if (fn != p || (*lp && *lp != '/')) {
1806 int save_copy_links = copy_links;
1807 int save_xfer_dirs = xfer_dirs;
1808 int dir_flags = inc_recurse ? FLAG_DIVERT_DIRS : 0;
1809 copy_links |= copy_unsafe_links;
1811 while ((slash = strchr(slash+1, '/')) != 0) {
1813 send_file_name(f, flist, fbuf, NULL,
1814 dir_flags, ALL_FILTERS);
1817 copy_links = save_copy_links;
1818 xfer_dirs = save_xfer_dirs;
1820 strlcpy(lastpath, fbuf, sizeof lastpath);
1825 if (one_file_system)
1826 filesystem_dev = st.st_dev;
1828 if (recurse || (xfer_dirs && is_dot_dir)) {
1829 struct file_struct *file;
1830 int top_flags = FLAG_TOP_DIR | FLAG_XFER_DIR | flags;
1831 file = send_file_name(f, flist, fbuf, &st,
1832 top_flags, ALL_FILTERS);
1833 if (file && !inc_recurse)
1834 send_if_directory(f, flist, file, fbuf, len, flags);
1836 send_file_name(f, flist, fbuf, &st, flags, ALL_FILTERS);
1839 gettimeofday(&end_tv, NULL);
1840 stats.flist_buildtime = (int64)(end_tv.tv_sec - start_tv.tv_sec) * 1000
1841 + (end_tv.tv_usec - start_tv.tv_usec) / 1000;
1842 if (stats.flist_buildtime == 0)
1843 stats.flist_buildtime = 1;
1846 write_byte(f, 0); /* Indicate end of file list */
1848 #ifdef SUPPORT_HARD_LINKS
1849 if (preserve_hard_links && protocol_version >= 30 && !inc_recurse)
1853 if (show_filelist_p())
1854 finish_filelist_progress(flist);
1856 gettimeofday(&end_tv, NULL);
1857 stats.flist_xfertime = (int64)(end_tv.tv_sec - start_tv.tv_sec) * 1000
1858 + (end_tv.tv_usec - start_tv.tv_usec) / 1000;
1860 /* When converting names, both sides keep an unsorted file-list array
1861 * because the names will differ on the sending and receiving sides
1862 * (both sides will use the unsorted index number for each item). */
1864 /* Sort the list without removing any duplicates. This allows the
1865 * receiving side to ask for whatever name it kept. For incremental
1866 * recursion mode, the sender marks duplicate dirs so that it can
1867 * send them together in a single file-list. */
1869 if (need_unsorted_flist) {
1871 if (!(flist->sorted = new_array(struct file_struct *, flist->used)))
1872 out_of_memory("send_file_list");
1873 memcpy(flist->sorted, flist->files,
1874 flist->used * sizeof (struct file_struct*));
1875 clean_flist(flist, 0);
1877 flist->sorted = flist->files;
1879 flist->high = flist->used - 1;
1884 flist->sorted = flist->files;
1885 clean_flist(flist, 0);
1887 file_total += flist->used;
1889 /* We don't subtract dir_count for the first send since we
1890 * might have one or more dot dirs which need to get sent. */
1891 flist->ndx_end = flist->ndx_start + flist->used - 1;
1893 if (!numeric_ids && !inc_recurse)
1896 /* send the io_error flag */
1897 if (protocol_version < 30)
1898 write_int(f, ignore_errors ? 0 : io_error);
1899 else if (io_error && !ignore_errors)
1900 send_msg_int(MSG_IO_ERROR, io_error);
1902 if (disable_buffering)
1903 io_end_buffering_out();
1905 stats.flist_size = stats.total_written - start_write;
1906 stats.num_files = flist->used;
1909 output_flist(flist);
1912 rprintf(FINFO, "send_file_list done\n");
1915 add_dirs_to_tree(-1, flist, dir_count);
1916 flist_done_allocating(flist);
1917 if (send_dir_ndx < 0) {
1918 write_ndx(f, NDX_FLIST_EOF);
1921 else if (file_total == 1) {
1922 /* If we're creating incremental file-lists and there
1923 * was just 1 item in the first file-list, send 1 more
1924 * file-list to check if this is a 1-file xfer. */
1925 send_extra_file_list(f, 1);
1932 struct file_list *recv_file_list(int f)
1934 struct file_list *flist;
1939 rprintf(FLOG, "receiving file list\n");
1940 if (show_filelist_p())
1941 start_filelist_progress("receiving file list");
1942 else if (inc_recurse && verbose && !am_server && !first_flist)
1943 rprintf(FCLIENT, "receiving incremental file list\n");
1945 start_read = stats.total_read;
1947 flist = flist_new(0, "recv_file_list");
1949 #ifdef SUPPORT_HARD_LINKS
1950 if (preserve_hard_links && protocol_version < 30)
1955 if (flist->ndx_start == 0)
1956 dir_flist = flist_new(FLIST_TEMP, "recv_file_list");
1957 dstart = dir_flist->used;
1963 while ((flags = read_byte(f)) != 0) {
1964 struct file_struct *file;
1966 flist_expand(flist, 1);
1968 if (protocol_version >= 28 && (flags & XMIT_EXTENDED_FLAGS))
1969 flags |= read_byte(f) << 8;
1970 file = recv_file_entry(flist, flags, f);
1972 if (inc_recurse && S_ISDIR(file->mode)) {
1973 flist_expand(dir_flist, 1);
1974 dir_flist->files[dir_flist->used++] = file;
1977 flist->files[flist->used++] = file;
1979 maybe_emit_filelist_progress(flist->used);
1982 rprintf(FINFO, "recv_file_name(%s)\n",
1983 f_name(file, NULL));
1986 file_total += flist->used;
1988 flist->ndx_end = flist->ndx_start + flist->used - 1;
1989 if (inc_recurse && flist->ndx_start)
1990 flist->ndx_end -= dir_flist->used - dstart;
1993 rprintf(FINFO, "received %d names\n", flist->used);
1995 if (show_filelist_p())
1996 finish_filelist_progress(flist);
1999 if (need_unsorted_flist) {
2000 /* Create an extra array of index pointers that we can sort for
2001 * the generator's use (for wading through the files in sorted
2002 * order and for calling flist_find()). We keep the "files"
2003 * list unsorted for our exchange of index numbers with the
2004 * other side (since their names may not sort the same). */
2005 if (!(flist->sorted = new_array(struct file_struct *, flist->used)))
2006 out_of_memory("recv_file_list");
2007 memcpy(flist->sorted, flist->files,
2008 flist->used * sizeof (struct file_struct*));
2009 if (inc_recurse && dir_flist->used > dstart) {
2010 dir_flist->sorted = realloc_array(dir_flist->sorted,
2011 struct file_struct *,
2013 memcpy(dir_flist->sorted + dstart, dir_flist->files + dstart,
2014 (dir_flist->used - dstart) * sizeof (struct file_struct*));
2015 fsort(dir_flist->sorted + dstart, dir_flist->used - dstart);
2020 flist->sorted = flist->files;
2021 if (inc_recurse && dir_flist->used > dstart) {
2022 dir_flist->sorted = dir_flist->files;
2023 fsort(dir_flist->sorted + dstart, dir_flist->used - dstart);
2028 flist_done_allocating(flist);
2030 recv_id_list(f, flist);
2032 clean_flist(flist, relative_paths);
2034 if (protocol_version < 30) {
2035 /* Recv the io_error flag */
2039 io_error |= read_int(f);
2043 output_flist(flist);
2047 for (i = flist->low; i <= flist->high; i++)
2048 list_file_entry(flist->files[i]);
2052 rprintf(FINFO, "recv_file_list done\n");
2054 stats.flist_size += stats.total_read - start_read;
2055 stats.num_files += flist->used;
2060 /* This is only used once by the receiver if the very first file-list
2061 * has exactly one item in it. */
2062 void recv_additional_file_list(int f)
2064 struct file_list *flist;
2065 int ndx = read_ndx(f);
2066 if (ndx == NDX_FLIST_EOF) {
2068 change_local_filter_dir(NULL, 0, 0);
2070 ndx = NDX_FLIST_OFFSET - ndx;
2071 if (ndx < 0 || ndx >= dir_flist->used) {
2072 ndx = NDX_FLIST_OFFSET - ndx;
2074 "[%s] Invalid dir index: %d (%d - %d)\n",
2075 who_am_i(), ndx, NDX_FLIST_OFFSET,
2076 NDX_FLIST_OFFSET - dir_flist->used + 1);
2077 exit_cleanup(RERR_PROTOCOL);
2080 rprintf(FINFO, "[%s] receiving flist for dir %d\n",
2083 flist = recv_file_list(f);
2084 flist->parent_ndx = ndx;
2088 /* Search for an identically-named item in the file list. Note that the
2089 * items must agree in their directory-ness, or no match is returned. */
2090 int flist_find(struct file_list *flist, struct file_struct *f)
2092 int low = flist->low, high = flist->high;
2093 int diff, mid, mid_up;
2095 while (low <= high) {
2096 mid = (low + high) / 2;
2097 if (F_IS_ACTIVE(flist->sorted[mid]))
2100 /* Scan for the next non-empty entry using the cached
2101 * distance values. If the value isn't fully up-to-
2102 * date, update it. */
2103 mid_up = mid + F_DEPTH(flist->sorted[mid]);
2104 if (!F_IS_ACTIVE(flist->sorted[mid_up])) {
2106 mid_up += F_DEPTH(flist->sorted[mid_up]);
2107 } while (!F_IS_ACTIVE(flist->sorted[mid_up]));
2108 F_DEPTH(flist->sorted[mid]) = mid_up - mid;
2110 if (mid_up > high) {
2111 /* If there's nothing left above us, set high to
2112 * a non-empty entry below us and continue. */
2113 high = mid - (int)flist->sorted[mid]->len32;
2114 if (!F_IS_ACTIVE(flist->sorted[high])) {
2116 high -= (int)flist->sorted[high]->len32;
2117 } while (!F_IS_ACTIVE(flist->sorted[high]));
2118 flist->sorted[mid]->len32 = mid - high;
2123 diff = f_name_cmp(flist->sorted[mid_up], f);
2125 if (protocol_version < 29
2126 && S_ISDIR(flist->sorted[mid_up]->mode)
2127 != S_ISDIR(f->mode))
2140 * Free up any resources a file_struct has allocated
2141 * and clear the file.
2143 void clear_file(struct file_struct *file)
2145 /* The +1 zeros out the first char of the basename. */
2146 memset(file, 0, FILE_STRUCT_LEN + 1);
2147 /* In an empty entry, F_DEPTH() is an offset to the next non-empty
2148 * entry. Likewise for len32 in the opposite direction. We assume
2149 * that we're alone for now since flist_find() will adjust the counts
2150 * it runs into that aren't up-to-date. */
2151 file->len32 = F_DEPTH(file) = 1;
2154 /* Allocate a new file list. */
2155 struct file_list *flist_new(int flags, char *msg)
2157 struct file_list *flist;
2159 flist = new(struct file_list);
2163 memset(flist, 0, sizeof flist[0]);
2165 if (flags & FLIST_TEMP) {
2166 if (!(flist->file_pool = pool_create(SMALL_EXTENT, 0,
2167 out_of_memory, POOL_INTERN)))
2170 /* This is a doubly linked list with prev looping back to
2171 * the end of the list, but the last next pointer is NULL. */
2173 flist->file_pool = pool_create(NORMAL_EXTENT, 0,
2174 out_of_memory, POOL_INTERN);
2175 if (!flist->file_pool)
2178 first_flist = cur_flist = flist->prev = flist;
2180 flist->file_pool = first_flist->file_pool;
2182 flist->ndx_start = first_flist->prev->ndx_end + 2;
2184 flist->prev = first_flist->prev;
2185 flist->prev->next = first_flist->prev = flist;
2187 flist->pool_boundary = pool_boundary(flist->file_pool, 0);
2194 /* Free up all elements in a flist. */
2195 void flist_free(struct file_list *flist)
2198 /* Was FLIST_TEMP dir-list. */
2199 } else if (flist == flist->prev) {
2200 first_flist = cur_flist = NULL;
2204 if (flist == cur_flist)
2205 cur_flist = flist->next;
2206 if (flist == first_flist)
2207 first_flist = first_flist->next;
2209 flist->prev->next = flist->next;
2211 flist->next = first_flist;
2213 flist->next->prev = flist->prev;
2214 file_total -= flist->used;
2218 if (!flist->prev || !flist_cnt)
2219 pool_destroy(flist->file_pool);
2221 pool_free_old(flist->file_pool, flist->pool_boundary);
2223 if (flist->sorted && flist->sorted != flist->files)
2224 free(flist->sorted);
2229 /* This routine ensures we don't have any duplicate names in our file list.
2230 * duplicate names can cause corruption because of the pipelining. */
2231 static void clean_flist(struct file_list *flist, int strip_root)
2233 char fbuf[MAXPATHLEN];
2238 if (flist->used == 0) {
2244 fsort(flist->sorted, flist->used);
2246 if (!am_sender || inc_recurse) {
2247 for (i = prev_i = 0; i < flist->used; i++) {
2248 if (F_IS_ACTIVE(flist->sorted[i])) {
2253 flist->low = prev_i;
2255 i = prev_i = flist->used - 1;
2259 while (++i < flist->used) {
2261 struct file_struct *file = flist->sorted[i];
2263 if (!F_IS_ACTIVE(file))
2265 if (f_name_cmp(file, flist->sorted[prev_i]) == 0)
2267 else if (protocol_version >= 29 && S_ISDIR(file->mode)) {
2268 int save_mode = file->mode;
2269 /* Make sure that this directory doesn't duplicate a
2270 * non-directory earlier in the list. */
2271 flist->high = prev_i;
2272 file->mode = S_IFREG;
2273 j = flist_find(flist, file);
2274 file->mode = save_mode;
2279 /* If one is a dir and the other is not, we want to
2280 * keep the dir because it might have contents in the
2282 if (S_ISDIR(file->mode)) {
2283 struct file_struct *fp = flist->sorted[j];
2284 if (!S_ISDIR(fp->mode))
2292 flist->sorted[drop]->flags |= FLAG_DUPLICATE;
2296 "removing duplicate name %s from file list (%d)\n",
2297 f_name(file, fbuf), drop + flist->ndx_start);
2299 /* Make sure we don't lose track of a user-specified
2301 flist->sorted[keep]->flags |= flist->sorted[drop]->flags
2302 & (FLAG_TOP_DIR|FLAG_XFER_DIR);
2304 clear_file(flist->sorted[drop]);
2308 if (flist->low == drop) {
2310 j < i && !F_IS_ACTIVE(flist->sorted[j]);
2319 flist->high = prev_i;
2322 /* We need to strip off the leading slashes for relative
2323 * paths, but this must be done _after_ the sorting phase. */
2324 for (i = flist->low; i <= flist->high; i++) {
2325 struct file_struct *file = flist->sorted[i];
2329 while (*file->dirname == '/')
2331 if (!*file->dirname)
2332 file->dirname = NULL;
2336 if (prune_empty_dirs && !am_sender) {
2337 int j, prev_depth = 0;
2339 prev_i = 0; /* It's OK that this isn't really true. */
2341 for (i = flist->low; i <= flist->high; i++) {
2342 struct file_struct *fp, *file = flist->sorted[i];
2344 /* This temporarily abuses the F_DEPTH() value for a
2345 * directory that is in a chain that might get pruned.
2346 * We restore the old value if it gets a reprieve. */
2347 if (S_ISDIR(file->mode) && F_DEPTH(file)) {
2348 /* Dump empty dirs when coming back down. */
2349 for (j = prev_depth; j >= F_DEPTH(file); j--) {
2350 fp = flist->sorted[prev_i];
2351 if (F_DEPTH(fp) >= 0)
2353 prev_i = -F_DEPTH(fp)-1;
2356 prev_depth = F_DEPTH(file);
2357 if (is_excluded(f_name(file, fbuf), 1,
2359 /* Keep dirs through this dir. */
2360 for (j = prev_depth-1; ; j--) {
2361 fp = flist->sorted[prev_i];
2362 if (F_DEPTH(fp) >= 0)
2364 prev_i = -F_DEPTH(fp)-1;
2368 F_DEPTH(file) = -prev_i-1;
2371 /* Keep dirs through this non-dir. */
2372 for (j = prev_depth; ; j--) {
2373 fp = flist->sorted[prev_i];
2374 if (F_DEPTH(fp) >= 0)
2376 prev_i = -F_DEPTH(fp)-1;
2381 /* Dump all remaining empty dirs. */
2383 struct file_struct *fp = flist->sorted[prev_i];
2384 if (F_DEPTH(fp) >= 0)
2386 prev_i = -F_DEPTH(fp)-1;
2390 for (i = flist->low; i <= flist->high; i++) {
2391 if (F_IS_ACTIVE(flist->sorted[i]))
2395 for (i = flist->high; i >= flist->low; i--) {
2396 if (F_IS_ACTIVE(flist->sorted[i]))
2403 static void output_flist(struct file_list *flist)
2405 char uidbuf[16], gidbuf[16], depthbuf[16];
2406 struct file_struct *file;
2407 const char *root, *dir, *slash, *name, *trail;
2408 const char *who = who_am_i();
2411 rprintf(FINFO, "[%s] flist start=%d, end=%d, used=%d, low=%d, high=%d\n",
2412 who, flist->ndx_start, flist->ndx_end, flist->used, flist->low, flist->high);
2413 for (i = 0; i < flist->used; i++) {
2414 file = flist->sorted[i];
2415 if ((am_root || am_sender) && uid_ndx) {
2416 snprintf(uidbuf, sizeof uidbuf, " uid=%u",
2421 static char parens[] = "(\0)\0\0\0";
2422 char *pp = parens + (file->flags & FLAG_SKIP_GROUP ? 0 : 3);
2423 snprintf(gidbuf, sizeof gidbuf, " gid=%s%u%s",
2424 pp, F_GROUP(file), pp + 2);
2428 snprintf(depthbuf, sizeof depthbuf, "%d", F_DEPTH(file));
2429 if (F_IS_ACTIVE(file)) {
2430 root = am_sender ? NS(F_PATHNAME(file)) : depthbuf;
2431 if ((dir = file->dirname) == NULL)
2435 name = file->basename;
2436 trail = S_ISDIR(file->mode) ? "/" : "";
2438 root = dir = slash = name = trail = "";
2440 "[%s] i=%d %s %s%s%s%s mode=0%o len=%.0f%s%s flags=%x\n",
2441 who, i + flist->ndx_start,
2442 root, dir, slash, name, trail,
2443 (int)file->mode, (double)F_LENGTH(file),
2444 uidbuf, gidbuf, file->flags);
2448 enum fnc_state { s_DIR, s_SLASH, s_BASE, s_TRAILING };
2449 enum fnc_type { t_PATH, t_ITEM };
2451 /* Compare the names of two file_struct entities, similar to how strcmp()
2452 * would do if it were operating on the joined strings.
2454 * Some differences beginning with protocol_version 29: (1) directory names
2455 * are compared with an assumed trailing slash so that they compare in a
2456 * way that would cause them to sort immediately prior to any content they
2457 * may have; (2) a directory of any name compares after a non-directory of
2458 * any name at the same depth; (3) a directory with name "." compares prior
2459 * to anything else. These changes mean that a directory and a non-dir
2460 * with the same name will not compare as equal (protocol_version >= 29).
2462 * The dirname component can be an empty string, but the basename component
2463 * cannot (and never is in the current codebase). The basename component
2464 * may be NULL (for a removed item), in which case it is considered to be
2465 * after any existing item. */
2466 int f_name_cmp(struct file_struct *f1, struct file_struct *f2)
2469 const uchar *c1, *c2;
2470 enum fnc_state state1, state2;
2471 enum fnc_type type1, type2;
2472 enum fnc_type t_path = protocol_version >= 29 ? t_PATH : t_ITEM;
2474 if (!f1 || !F_IS_ACTIVE(f1)) {
2475 if (!f2 || !F_IS_ACTIVE(f2))
2479 if (!f2 || !F_IS_ACTIVE(f2))
2482 c1 = (uchar*)f1->dirname;
2483 c2 = (uchar*)f2->dirname;
2487 type1 = S_ISDIR(f1->mode) ? t_path : t_ITEM;
2488 c1 = (const uchar*)f1->basename;
2489 if (type1 == t_PATH && *c1 == '.' && !c1[1]) {
2491 state1 = s_TRAILING;
2500 type2 = S_ISDIR(f2->mode) ? t_path : t_ITEM;
2501 c2 = (const uchar*)f2->basename;
2502 if (type2 == t_PATH && *c2 == '.' && !c2[1]) {
2504 state2 = s_TRAILING;
2514 return type1 == t_PATH ? 1 : -1;
2524 type1 = S_ISDIR(f1->mode) ? t_path : t_ITEM;
2525 c1 = (const uchar*)f1->basename;
2526 if (type1 == t_PATH && *c1 == '.' && !c1[1]) {
2528 state1 = s_TRAILING;
2534 state1 = s_TRAILING;
2535 if (type1 == t_PATH) {
2544 if (*c2 && type1 != type2)
2545 return type1 == t_PATH ? 1 : -1;
2554 type2 = S_ISDIR(f2->mode) ? t_path : t_ITEM;
2555 c2 = (const uchar*)f2->basename;
2556 if (type2 == t_PATH && *c2 == '.' && !c2[1]) {
2558 state2 = s_TRAILING;
2564 state2 = s_TRAILING;
2565 if (type2 == t_PATH) {
2577 return type1 == t_PATH ? 1 : -1;
2579 } while ((dif = (int)*c1++ - (int)*c2++) == 0);
2584 char *f_name_buf(void)
2586 static char names[5][MAXPATHLEN];
2587 static unsigned int n;
2589 n = (n + 1) % (sizeof names / sizeof names[0]);
2594 /* Return a copy of the full filename of a flist entry, using the indicated
2595 * buffer or one of 5 static buffers if fbuf is NULL. No size-checking is
2596 * done because we checked the size when creating the file_struct entry.
2598 char *f_name(struct file_struct *f, char *fbuf)
2600 if (!f || !F_IS_ACTIVE(f))
2604 fbuf = f_name_buf();
2607 int len = strlen(f->dirname);
2608 memcpy(fbuf, f->dirname, len);
2610 strlcpy(fbuf + len + 1, f->basename, MAXPATHLEN - (len + 1));
2612 strlcpy(fbuf, f->basename, MAXPATHLEN);
2617 /* Do a non-recursive scan of the named directory, possibly ignoring all
2618 * exclude rules except for the daemon's. If "dlen" is >=0, it is the length
2619 * of the dirname string, and also indicates that "dirname" is a MAXPATHLEN
2620 * buffer (the functions we call will append names onto the end, but the old
2621 * dir value will be restored on exit). */
2622 struct file_list *get_dirlist(char *dirname, int dlen, int ignore_filter_rules)
2624 struct file_list *dirlist;
2625 char dirbuf[MAXPATHLEN];
2626 int save_recurse = recurse;
2627 int save_xfer_dirs = xfer_dirs;
2628 int save_prune_empty_dirs = prune_empty_dirs;
2631 dlen = strlcpy(dirbuf, dirname, MAXPATHLEN);
2632 if (dlen >= MAXPATHLEN)
2637 dirlist = flist_new(FLIST_TEMP, "get_dirlist");
2641 send_directory(ignore_filter_rules ? -2 : -1, dirlist, dirname, dlen, 0);
2642 xfer_dirs = save_xfer_dirs;
2643 recurse = save_recurse;
2645 flist_count_offset += dirlist->used;
2647 prune_empty_dirs = 0;
2648 dirlist->sorted = dirlist->files;
2649 clean_flist(dirlist, 0);
2650 prune_empty_dirs = save_prune_empty_dirs;
2653 output_flist(dirlist);