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, 2003, 2004, 2005, 2006 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 as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
32 extern int do_progress;
33 extern int always_checksum;
35 extern int ignore_errors;
36 extern int numeric_ids;
39 extern int filesfrom_fd;
40 extern int one_file_system;
41 extern int copy_dirlinks;
42 extern int keep_dirlinks;
43 extern int preserve_links;
44 extern int preserve_hard_links;
45 extern int preserve_devices;
46 extern int preserve_specials;
47 extern int preserve_uid;
48 extern int preserve_gid;
49 extern int relative_paths;
50 extern int implied_dirs;
51 extern int flist_extra_ndx;
52 extern int ignore_perishable;
53 extern int non_perishable_cnt;
54 extern int prune_empty_dirs;
55 extern int copy_links;
56 extern int copy_unsafe_links;
57 extern int protocol_version;
58 extern int sanitize_paths;
59 extern struct stats stats;
60 extern struct file_list *the_file_list;
62 extern char curr_dir[MAXPATHLEN];
64 extern struct chmod_mode_struct *chmod_modes;
66 extern struct filter_list_struct filter_list;
67 extern struct filter_list_struct server_filter_list;
71 dev_t filesystem_dev; /* used to implement -x */
74 /* The tmp_* vars are used as a cache area by make_file() to store data
75 * that the sender doesn't need to remember in its file list. The data
76 * will survive just long enough to be used by send_file_entry(). */
77 static dev_t tmp_rdev;
78 static struct idev tmp_idev;
79 static char tmp_sum[MD4_SUM_LENGTH];
81 static char empty_sum[MD4_SUM_LENGTH];
82 static int flist_count_offset;
84 static void clean_flist(struct file_list *flist, int strip_root, int no_dups);
85 static void output_flist(struct file_list *flist);
91 /* Figure out how big the file_struct is without trailing padding */
92 file_struct_len = offsetof(struct file_struct, flags) + sizeof f.flags;
93 checksum_len = protocol_version < 21 ? 2 : MD4_SUM_LENGTH;
96 static int show_filelist_p(void)
98 return verbose && xfer_dirs && !am_server;
101 static void start_filelist_progress(char *kind)
103 rprintf(FCLIENT, "%s ... ", kind);
104 if (verbose > 1 || do_progress)
105 rprintf(FCLIENT, "\n");
109 static void emit_filelist_progress(int count)
111 rprintf(FCLIENT, " %d files...\r", count);
114 static void maybe_emit_filelist_progress(int count)
116 if (do_progress && show_filelist_p() && (count % 100) == 0)
117 emit_filelist_progress(count);
120 static void finish_filelist_progress(const struct file_list *flist)
123 /* This overwrites the progress line */
124 rprintf(FINFO, "%d file%sto consider\n",
125 flist->count, flist->count == 1 ? " " : "s ");
127 rprintf(FINFO, "done\n");
130 void show_flist_stats(void)
135 static void list_file_entry(struct file_struct *f)
137 char permbuf[PERMSTRING_SIZE];
140 /* this can happen if duplicate names were removed */
144 permstring(permbuf, f->mode);
147 if (preserve_links && S_ISLNK(f->mode)) {
148 rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
150 (double)f->length, timestring(f->modtime),
151 f_name(f, NULL), F_SYMLINK(f));
155 rprintf(FINFO, "%s %11.0f %s %s\n",
157 (double)f->length, timestring(f->modtime),
162 /* Stat either a symlink or its referent, depending on the settings of
163 * copy_links, copy_unsafe_links, etc. Returns -1 on error, 0 on success.
165 * If path is the name of a symlink, then the linkbuf buffer (which must hold
166 * MAXPATHLEN chars) will be set to the symlink's target string.
168 * The stat structure pointed to by stp will contain information about the
169 * link or the referent as appropriate, if they exist. */
170 static int readlink_stat(const char *path, STRUCT_STAT *stp, char *linkbuf)
173 if (link_stat(path, stp, copy_dirlinks) < 0)
175 if (S_ISLNK(stp->st_mode)) {
176 int llen = readlink(path, linkbuf, MAXPATHLEN - 1);
179 linkbuf[llen] = '\0';
180 if (copy_unsafe_links && unsafe_symlink(linkbuf, path)) {
182 rprintf(FINFO,"copying unsafe symlink \"%s\" -> \"%s\"\n",
185 return do_stat(path, stp);
190 return do_stat(path, stp);
194 int link_stat(const char *path, STRUCT_STAT *stp, int follow_dirlinks)
198 return do_stat(path, stp);
199 if (do_lstat(path, stp) < 0)
201 if (follow_dirlinks && S_ISLNK(stp->st_mode)) {
203 if (do_stat(path, &st) == 0 && S_ISDIR(st.st_mode))
208 return do_stat(path, stp);
212 /* This function is used to check if a file should be included/excluded
213 * from the list of files based on its name and type etc. The value of
214 * filter_level is set to either SERVER_FILTERS or ALL_FILTERS. */
215 static int is_excluded(char *fname, int is_dir, int filter_level)
217 #if 0 /* This currently never happens, so avoid a useless compare. */
218 if (filter_level == NO_FILTERS)
222 /* never exclude '.', even if somebody does --exclude '*' */
223 if (fname[0] == '.' && !fname[1])
225 /* Handle the -R version of the '.' dir. */
226 if (fname[0] == '/') {
227 int len = strlen(fname);
228 if (fname[len-1] == '.' && fname[len-2] == '/')
232 if (server_filter_list.head
233 && check_filter(&server_filter_list, fname, is_dir) < 0)
235 if (filter_level != ALL_FILTERS)
238 && check_filter(&filter_list, fname, is_dir) < 0)
243 static int to_wire_mode(mode_t mode)
246 #if _S_IFLNK != 0120000
248 return (mode & ~(_S_IFMT)) | 0120000;
254 static mode_t from_wire_mode(int mode)
256 #if _S_IFLNK != 0120000
257 if ((mode & (_S_IFMT)) == 0120000)
258 return (mode & ~(_S_IFMT)) | _S_IFLNK;
263 static void send_directory(int f, struct file_list *flist,
264 char *fbuf, int len);
266 static const char *flist_dir;
267 static int flist_dir_len;
271 * Make sure @p flist is big enough to hold at least @p flist->count
274 void flist_expand(struct file_list *flist)
276 struct file_struct **new_ptr;
278 if (flist->count < flist->malloced)
281 if (flist->malloced < FLIST_START)
282 flist->malloced = FLIST_START;
283 else if (flist->malloced >= FLIST_LINEAR)
284 flist->malloced += FLIST_LINEAR;
286 flist->malloced *= 2;
289 * In case count jumped or we are starting the list
290 * with a known size just set it.
292 if (flist->malloced < flist->count)
293 flist->malloced = flist->count;
295 new_ptr = realloc_array(flist->files, struct file_struct *,
298 if (verbose >= 2 && flist->malloced != FLIST_START) {
299 rprintf(FCLIENT, "[%s] expand file_list to %.0f bytes, did%s move\n",
301 (double)sizeof flist->files[0] * flist->malloced,
302 (new_ptr == flist->files) ? " not" : "");
305 flist->files = new_ptr;
308 out_of_memory("flist_expand");
311 static void send_file_entry(struct file_struct *file, int f)
313 unsigned short flags;
314 static time_t modtime;
318 static uint32 rdev_major;
321 static char lastname[MAXPATHLEN];
322 char fname[MAXPATHLEN];
330 modtime = 0, mode = 0;
331 dev = 0, rdev = MAKEDEV(0, 0);
340 flags = file->flags & FLAG_TOP_DIR; /* FLAG_TOP_DIR == XMIT_TOP_DIR */
342 if (file->mode == mode)
343 flags |= XMIT_SAME_MODE;
346 if ((preserve_devices && IS_DEVICE(mode))
347 || (preserve_specials && IS_SPECIAL(mode))) {
348 if (protocol_version < 28) {
349 if (tmp_rdev == rdev)
350 flags |= XMIT_SAME_RDEV_pre28;
355 if ((uint32)major(rdev) == rdev_major)
356 flags |= XMIT_SAME_RDEV_MAJOR;
358 rdev_major = major(rdev);
359 if ((uint32)minor(rdev) <= 0xFFu)
360 flags |= XMIT_RDEV_MINOR_IS_SMALL;
362 } else if (protocol_version < 28)
363 rdev = MAKEDEV(0, 0);
365 if (F_UID(file) == uid)
366 flags |= XMIT_SAME_UID;
371 if (F_GID(file) == gid)
372 flags |= XMIT_SAME_GID;
376 if (file->modtime == modtime)
377 flags |= XMIT_SAME_TIME;
379 modtime = file->modtime;
381 #ifdef SUPPORT_HARD_LINKS
382 if (tmp_idev.dev != 0) {
383 if (tmp_idev.dev == dev) {
384 if (protocol_version >= 28)
385 flags |= XMIT_SAME_DEV;
388 flags |= XMIT_HAS_IDEV_DATA;
393 lastname[l1] && (fname[l1] == lastname[l1]) && (l1 < 255);
395 l2 = strlen(fname+l1);
398 flags |= XMIT_SAME_NAME;
400 flags |= XMIT_LONG_NAME;
402 /* We must make sure we don't send a zero flag byte or the
403 * other end will terminate the flist transfer. Note that
404 * the use of XMIT_TOP_DIR on a non-dir has no meaning, so
405 * it's harmless way to add a bit to the first flag byte. */
406 if (protocol_version >= 28) {
407 if (!flags && !S_ISDIR(mode))
408 flags |= XMIT_TOP_DIR;
409 if ((flags & 0xFF00) || !flags) {
410 flags |= XMIT_EXTENDED_FLAGS;
411 write_shortint(f, flags);
413 write_byte(f, flags);
416 flags |= S_ISDIR(mode) ? XMIT_LONG_NAME : XMIT_TOP_DIR;
417 write_byte(f, flags);
419 if (flags & XMIT_SAME_NAME)
421 if (flags & XMIT_LONG_NAME)
425 write_buf(f, fname + l1, l2);
427 write_longint(f, file->length);
428 if (!(flags & XMIT_SAME_TIME))
429 write_int(f, modtime);
430 if (!(flags & XMIT_SAME_MODE))
431 write_int(f, to_wire_mode(mode));
432 if (preserve_uid && !(flags & XMIT_SAME_UID)) {
437 if (preserve_gid && !(flags & XMIT_SAME_GID)) {
442 if ((preserve_devices && IS_DEVICE(mode))
443 || (preserve_specials && IS_SPECIAL(mode))) {
444 if (protocol_version < 28) {
445 if (!(flags & XMIT_SAME_RDEV_pre28))
446 write_int(f, (int)rdev);
448 if (!(flags & XMIT_SAME_RDEV_MAJOR))
449 write_int(f, major(rdev));
450 if (flags & XMIT_RDEV_MINOR_IS_SMALL)
451 write_byte(f, minor(rdev));
453 write_int(f, minor(rdev));
458 if (preserve_links && S_ISLNK(mode)) {
459 const char *sl = F_SYMLINK(file);
460 int len = strlen(sl);
462 write_buf(f, sl, len);
466 #ifdef SUPPORT_HARD_LINKS
467 if (tmp_idev.dev != 0) {
468 if (protocol_version < 26) {
469 /* 32-bit dev_t and ino_t */
470 write_int(f, (int32)dev);
471 write_int(f, (int32)tmp_idev.ino);
473 /* 64-bit dev_t and ino_t */
474 if (!(flags & XMIT_SAME_DEV))
475 write_longint(f, dev);
476 write_longint(f, tmp_idev.ino);
481 if (always_checksum && (S_ISREG(mode) || protocol_version < 28)) {
486 /* Prior to 28, we sent a useless set of nulls. */
489 write_buf(f, sum, checksum_len);
492 strlcpy(lastname, fname, MAXPATHLEN);
495 static struct file_struct *recv_file_entry(struct file_list *flist,
496 unsigned short flags, int f)
498 static time_t modtime;
502 static uint32 rdev_major;
505 static char lastname[MAXPATHLEN], *lastdir;
506 static int lastdir_depth, lastdir_len = -1;
507 static unsigned int del_hier_name_len = 0;
508 static int in_del_hier = 0;
509 char thisname[MAXPATHLEN];
510 unsigned int l1 = 0, l2 = 0;
511 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
512 int extra_len = (flist_extra_ndx-1) * sizeof (union flist_extras);
514 char *basename, *dirname, *bp;
515 struct file_struct *file;
518 modtime = 0, mode = 0;
519 dev = 0, rdev = MAKEDEV(0, 0);
528 if (flags & XMIT_SAME_NAME)
531 if (flags & XMIT_LONG_NAME)
536 if (l2 >= MAXPATHLEN - l1) {
538 "overflow: flags=0x%x l1=%d l2=%d lastname=%s [%s]\n",
539 flags, l1, l2, lastname, who_am_i());
540 overflow_exit("recv_file_entry");
543 strlcpy(thisname, lastname, l1 + 1);
544 read_sbuf(f, &thisname[l1], l2);
545 thisname[l1 + l2] = 0;
547 strlcpy(lastname, thisname, MAXPATHLEN);
549 clean_fname(thisname, 0);
552 sanitize_path(thisname, thisname, "", 0, NULL);
554 if ((basename = strrchr(thisname, '/')) != NULL) {
555 dirname_len = ++basename - thisname; /* counts future '\0' */
556 if (lastdir_len == dirname_len - 1
557 && strncmp(thisname, lastdir, lastdir_len) == 0) {
559 dirname_len = 0; /* indicates no copy is needed */
567 basename_len = strlen(basename) + 1; /* count the '\0' */
569 file_length = read_longint(f);
570 if (!(flags & XMIT_SAME_TIME))
571 modtime = (time_t)read_int(f);
572 if (!(flags & XMIT_SAME_MODE))
573 mode = from_wire_mode(read_int(f));
575 if (chmod_modes && !S_ISLNK(mode))
576 mode = tweak_mode(mode, chmod_modes);
578 if (preserve_uid && !(flags & XMIT_SAME_UID))
579 uid = (uid_t)read_int(f);
580 if (preserve_gid && !(flags & XMIT_SAME_GID))
581 gid = (gid_t)read_int(f);
583 if ((preserve_devices && IS_DEVICE(mode))
584 || (preserve_specials && IS_SPECIAL(mode))) {
585 if (protocol_version < 28) {
586 if (!(flags & XMIT_SAME_RDEV_pre28))
587 rdev = (dev_t)read_int(f);
590 if (!(flags & XMIT_SAME_RDEV_MAJOR))
591 rdev_major = read_int(f);
592 if (flags & XMIT_RDEV_MINOR_IS_SMALL)
593 rdev_minor = read_byte(f);
595 rdev_minor = read_int(f);
596 rdev = MAKEDEV(rdev_major, rdev_minor);
598 extra_len += 2 * sizeof (union flist_extras);
599 } else if (protocol_version < 28)
600 rdev = MAKEDEV(0, 0);
603 if (preserve_links && S_ISLNK(mode)) {
604 linkname_len = read_int(f) + 1; /* count the '\0' */
605 if (linkname_len <= 0 || linkname_len > MAXPATHLEN) {
606 rprintf(FERROR, "overflow: linkname_len=%d\n",
608 overflow_exit("recv_file_entry");
615 #ifdef SUPPORT_HARD_LINKS
616 if (preserve_hard_links && protocol_version < 28 && S_ISREG(mode))
617 flags |= XMIT_HAS_IDEV_DATA;
618 if (flags & XMIT_HAS_IDEV_DATA) {
619 extra_len += sizeof (union flist_extras);
620 assert(flist->hlink_pool != NULL);
624 sum_len = always_checksum && S_ISREG(mode) ? MD4_SUM_LENGTH : 0;
626 alloc_len = file_struct_len + dirname_len + basename_len
627 + linkname_len + sum_len + extra_len;
628 bp = pool_alloc(flist->file_pool, alloc_len, "recv_file_entry");
630 memset(bp, 0, file_struct_len + extra_len);
632 file = (struct file_struct *)bp;
633 bp += file_struct_len + linkname_len + sum_len;
635 #ifdef SUPPORT_HARD_LINKS
636 if (flags & XMIT_HAS_IDEV_DATA)
637 file->flags |= FLAG_HLINK_INFO;
639 file->modtime = modtime;
640 file->length = file_length;
648 file->dirname = lastdir = bp;
649 lastdir_len = dirname_len - 1;
650 memcpy(bp, dirname, dirname_len - 1);
653 lastdir_depth = count_dir_elements(lastdir);
654 file->dir.depth = lastdir_depth + 1;
655 } else if (dirname) {
656 file->dirname = dirname; /* we're reusing lastname */
657 file->dir.depth = lastdir_depth + 1;
662 if (basename_len == 1+1 && *basename == '.') /* +1 for '\0' */
664 if (flags & XMIT_TOP_DIR) {
665 in_del_hier = recurse;
666 del_hier_name_len = file->dir.depth == 0 ? 0 : l1 + l2;
667 if (relative_paths && del_hier_name_len > 2
668 && lastname[del_hier_name_len-1] == '.'
669 && lastname[del_hier_name_len-2] == '/')
670 del_hier_name_len -= 2;
671 file->flags |= FLAG_TOP_DIR | FLAG_XFER_DIR;
672 } else if (in_del_hier) {
673 if (!relative_paths || !del_hier_name_len
674 || (l1 >= del_hier_name_len
675 && lastname[del_hier_name_len] == '/'))
676 file->flags |= FLAG_XFER_DIR;
683 memcpy(bp, basename, basename_len);
686 if ((preserve_devices && IS_DEVICE(mode))
687 || (preserve_specials && IS_SPECIAL(mode))) {
688 F_DMAJOR(file) = major(rdev);
689 F_DMINOR(file) = minor(rdev);
694 bp = F_SYMLINK(file);
695 read_sbuf(f, bp, linkname_len - 1);
697 sanitize_path(bp, bp, "", lastdir_depth, NULL);
701 #ifdef SUPPORT_HARD_LINKS
702 if (flags & XMIT_HAS_IDEV_DATA) {
703 struct idev *idevp = pool_talloc(flist->hlink_pool, struct idev,
705 F_IDEV(file) = idevp;
706 if (protocol_version < 26) {
707 idevp->dev = read_int(f);
708 idevp->ino = read_int(f);
710 if (!(flags & XMIT_SAME_DEV))
711 dev = read_longint(f);
713 idevp->ino = read_longint(f);
718 if (always_checksum && (sum_len || protocol_version < 28)) {
722 /* Prior to 28, we get a useless set of nulls. */
725 read_buf(f, bp, checksum_len);
732 * Create a file_struct for a named file by reading its stat()
733 * information and performing extensive checks against global
736 * @return the new file, or NULL if there was an error or this file
737 * should be excluded.
739 * @todo There is a small optimization opportunity here to avoid
740 * stat()ing the file in some circumstances, which has a certain cost.
741 * We are called immediately after doing readdir(), and so we may
742 * already know the d_type of the file. We could for example avoid
743 * statting directories if we're not recursing, but this is not a very
744 * important case. Some systems may not have d_type.
746 struct file_struct *make_file(const char *fname, struct file_list *flist,
747 STRUCT_STAT *stp, int flags, int filter_level)
749 static char *lastdir;
750 static int lastdir_len = -1;
751 struct file_struct *file;
753 char thisname[MAXPATHLEN];
754 char linkname[MAXPATHLEN];
755 int alloc_len, basename_len, dirname_len, linkname_len;
756 int extra_len = (flist_extra_ndx-1) * sizeof (union flist_extras);
757 char *basename, *dirname, *bp;
759 if (!flist || !flist->count) /* Ignore lastdir when invalid. */
762 if (strlcpy(thisname, fname, sizeof thisname)
763 >= sizeof thisname - flist_dir_len) {
764 rprintf(FINFO, "skipping overly long name: %s\n", fname);
767 clean_fname(thisname, 0);
769 sanitize_path(thisname, thisname, "", 0, NULL);
771 if (stp && S_ISDIR(stp->st_mode)) {
772 st = *stp; /* Needed for "symlink/." with --relative. */
773 *linkname = '\0'; /* make IBM code checker happy */
774 } else if (readlink_stat(thisname, &st, linkname) != 0) {
775 int save_errno = errno;
776 /* See if file is excluded before reporting an error. */
777 if (filter_level != NO_FILTERS
778 && (is_excluded(thisname, 0, filter_level)
779 || is_excluded(thisname, 1, filter_level))) {
780 if (ignore_perishable && save_errno != ENOENT)
781 non_perishable_cnt++;
784 if (save_errno == ENOENT) {
786 /* Avoid "vanished" error if symlink points nowhere. */
787 if (copy_links && do_lstat(thisname, &st) == 0
788 && S_ISLNK(st.st_mode)) {
789 io_error |= IOERR_GENERAL;
790 rprintf(FERROR, "symlink has no referent: %s\n",
791 full_fname(thisname));
795 enum logcode c = am_daemon && protocol_version < 28
797 io_error |= IOERR_VANISHED;
798 rprintf(c, "file has vanished: %s\n",
799 full_fname(thisname));
802 io_error |= IOERR_GENERAL;
803 rsyserr(FERROR, save_errno, "readlink %s failed",
804 full_fname(thisname));
809 /* backup.c calls us with filter_level set to NO_FILTERS. */
810 if (filter_level == NO_FILTERS)
813 if (S_ISDIR(st.st_mode) && !xfer_dirs) {
814 rprintf(FINFO, "skipping directory %s\n", thisname);
818 /* -x only affects directories because we need to avoid recursing
819 * into a mount-point directory, not to avoid copying a symlinked
820 * file if -L (or similar) was specified. */
821 if (one_file_system && st.st_dev != filesystem_dev
822 && S_ISDIR(st.st_mode)) {
823 if (one_file_system > 1) {
825 rprintf(FINFO, "skipping mount-point dir %s\n",
830 flags |= FLAG_MOUNT_DIR;
833 if (is_excluded(thisname, S_ISDIR(st.st_mode) != 0, filter_level)) {
834 if (ignore_perishable)
835 non_perishable_cnt++;
839 if (lp_ignore_nonreadable(module_id)) {
841 if (!S_ISLNK(st.st_mode))
843 if (access(thisname, R_OK) != 0)
850 rprintf(FINFO, "[%s] make_file(%s,*,%d)\n",
851 who_am_i(), thisname, filter_level);
854 if ((basename = strrchr(thisname, '/')) != NULL) {
855 dirname_len = ++basename - thisname; /* counts future '\0' */
856 if (lastdir_len == dirname_len - 1
857 && strncmp(thisname, lastdir, lastdir_len) == 0) {
859 dirname_len = 0; /* indicates no copy is needed */
867 basename_len = strlen(basename) + 1; /* count the '\0' */
870 linkname_len = S_ISLNK(st.st_mode) ? strlen(linkname) + 1 : 0;
875 alloc_len = file_struct_len + dirname_len + basename_len
876 + linkname_len + extra_len;
878 bp = pool_alloc(flist->file_pool, alloc_len, "make_file");
880 if (!(bp = new_array(char, alloc_len)))
881 out_of_memory("make_file");
884 memset(bp, 0, file_struct_len + extra_len);
886 file = (struct file_struct *)bp;
887 bp += file_struct_len + linkname_len;
889 #ifdef SUPPORT_HARD_LINKS
890 if (preserve_hard_links && flist) {
891 if (protocol_version >= 28
892 ? (!S_ISDIR(st.st_mode) && st.st_nlink > 1)
893 : S_ISREG(st.st_mode)) {
894 tmp_idev.dev = st.st_dev;
895 tmp_idev.ino = st.st_ino;
897 tmp_idev.dev = tmp_idev.ino = 0;
902 file->modtime = st.st_mtime;
903 file->length = st.st_size;
904 file->mode = st.st_mode;
906 F_UID(file) = st.st_uid;
908 F_GID(file) = st.st_gid;
911 file->dirname = lastdir = bp;
912 lastdir_len = dirname_len - 1;
913 memcpy(bp, dirname, dirname_len - 1);
917 file->dirname = dirname;
920 memcpy(bp, basename, basename_len);
923 #ifdef HAVE_STRUCT_STAT_ST_RDEV
924 if ((preserve_devices && IS_DEVICE(st.st_mode))
925 || (preserve_specials && IS_SPECIAL(st.st_mode)))
926 tmp_rdev = st.st_rdev;
931 memcpy(F_SYMLINK(file), linkname, linkname_len);
934 if (always_checksum && am_sender && S_ISREG(st.st_mode))
935 file_checksum(thisname, tmp_sum, st.st_size);
937 file->dir.root = flist_dir;
939 /* This code is only used by the receiver when it is building
940 * a list of files for a delete pass. */
941 if (keep_dirlinks && linkname_len && flist) {
943 int save_mode = file->mode;
944 file->mode = S_IFDIR; /* Find a directory with our name. */
945 if (flist_find(the_file_list, file) >= 0
946 && do_stat(thisname, &st2) == 0 && S_ISDIR(st2.st_mode)) {
947 file->modtime = st2.st_mtime;
948 file->length = st2.st_size;
949 file->mode = st2.st_mode;
951 F_UID(file) = st2.st_uid;
953 F_GID(file) = st2.st_gid;
955 file->mode = save_mode;
958 if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))
959 stats.total_size += st.st_size;
961 if (basename_len == 0+1)
967 /* Only called for temporary file_struct entries. */
968 void unmake_file(struct file_struct *file)
970 union flist_extras *start = (union flist_extras *)file
971 - (flist_extra_ndx - 1);
975 static struct file_struct *send_file_name(int f, struct file_list *flist,
976 char *fname, STRUCT_STAT *stp,
977 unsigned short flags)
979 struct file_struct *file;
981 file = make_file(fname, flist, stp, flags,
982 f == -2 ? SERVER_FILTERS : ALL_FILTERS);
986 if (chmod_modes && !S_ISLNK(file->mode))
987 file->mode = tweak_mode(file->mode, chmod_modes);
989 maybe_emit_filelist_progress(flist->count + flist_count_offset);
992 flist->files[flist->count++] = file;
993 send_file_entry(file, f);
997 static void send_if_directory(int f, struct file_list *flist,
998 struct file_struct *file,
999 char *fbuf, unsigned int ol)
1001 char is_dot_dir = fbuf[ol-1] == '.' && (ol == 1 || fbuf[ol-2] == '/');
1003 if (S_ISDIR(file->mode)
1004 && !(file->flags & FLAG_MOUNT_DIR) && f_name(file, fbuf)) {
1006 unsigned int len = strlen(fbuf);
1007 if (len > 1 && fbuf[len-1] == '/')
1009 if (len >= MAXPATHLEN - 1) {
1010 io_error |= IOERR_GENERAL;
1011 rprintf(FERROR, "skipping long-named directory: %s\n",
1015 save_filters = push_local_filters(fbuf, len);
1016 send_directory(f, flist, fbuf, len);
1017 pop_local_filters(save_filters);
1024 /* This function is normally called by the sender, but the receiving side also
1025 * calls it from get_dirlist() with f set to -1 so that we just construct the
1026 * file list in memory without sending it over the wire. Also, get_dirlist()
1027 * might call this with f set to -2, which also indicates that local filter
1028 * rules should be ignored. */
1029 static void send_directory(int f, struct file_list *flist,
1030 char *fbuf, int len)
1036 int start = flist->count;
1038 if (!(d = opendir(fbuf))) {
1039 io_error |= IOERR_GENERAL;
1040 rsyserr(FERROR, errno, "opendir %s failed", full_fname(fbuf));
1045 if (len != 1 || *fbuf != '/')
1048 remainder = MAXPATHLEN - (p - fbuf);
1050 for (errno = 0, di = readdir(d); di; errno = 0, di = readdir(d)) {
1051 char *dname = d_name(di);
1052 if (dname[0] == '.' && (dname[1] == '\0'
1053 || (dname[1] == '.' && dname[2] == '\0')))
1055 if (strlcpy(p, dname, remainder) >= remainder) {
1056 io_error |= IOERR_GENERAL;
1058 "cannot send long-named file %s\n",
1063 send_file_name(f, flist, fbuf, NULL, 0);
1069 io_error |= IOERR_GENERAL;
1070 rsyserr(FERROR, errno, "readdir(%s)", full_fname(fbuf));
1076 int i, end = flist->count - 1;
1077 for (i = start; i <= end; i++)
1078 send_if_directory(f, flist, flist->files[i], fbuf, len);
1082 struct file_list *send_file_list(int f, int argc, char *argv[])
1086 char *p, *dir, olddir[sizeof curr_dir];
1087 char lastpath[MAXPATHLEN] = "";
1088 struct file_list *flist;
1089 struct timeval start_tv, end_tv;
1093 rprintf(FLOG, "building file list\n");
1094 if (show_filelist_p())
1095 start_filelist_progress("building file list");
1097 start_write = stats.total_written;
1098 gettimeofday(&start_tv, NULL);
1100 flist = flist_new(0, "send_file_list");
1102 io_start_buffering_out();
1103 if (filesfrom_fd >= 0) {
1104 if (argv[0] && !push_dir(argv[0], 0)) {
1105 rsyserr(FERROR, errno, "push_dir %s failed",
1106 full_fname(argv[0]));
1107 exit_cleanup(RERR_FILESELECT);
1113 char fbuf[MAXPATHLEN];
1118 if (read_filesfrom_line(filesfrom_fd, fbuf) == 0)
1120 sanitize_path(fbuf, fbuf, "", 0, NULL);
1124 strlcpy(fbuf, *argv++, MAXPATHLEN);
1126 sanitize_path(fbuf, fbuf, "", 0, NULL);
1130 if (relative_paths) {
1131 /* We clean up fbuf below. */
1133 } else if (!len || fbuf[len - 1] == '/') {
1134 if (len == 2 && fbuf[0] == '.') {
1135 /* Turn "./" into just "." rather than "./." */
1138 if (len + 1 >= MAXPATHLEN)
1139 overflow_exit("send_file_list");
1144 } else if (len > 1 && fbuf[len-1] == '.' && fbuf[len-2] == '.'
1145 && (len == 2 || fbuf[len-3] == '/')) {
1146 if (len + 2 >= MAXPATHLEN)
1147 overflow_exit("send_file_list");
1153 is_dot_dir = fbuf[len-1] == '.'
1154 && (len == 1 || fbuf[len-2] == '/');
1157 if (link_stat(fbuf, &st, copy_dirlinks) != 0) {
1158 io_error |= IOERR_GENERAL;
1159 rsyserr(FERROR, errno, "link_stat %s failed",
1164 if (S_ISDIR(st.st_mode) && !xfer_dirs) {
1165 rprintf(FINFO, "skipping directory %s\n", fbuf);
1172 if (!relative_paths) {
1173 p = strrchr(fbuf, '/');
1180 len -= p - fbuf + 1;
1185 if ((p = strstr(fbuf, "/./")) != NULL) {
1191 len -= p - fbuf + 3;
1195 /* Get rid of trailing "/" and "/.". */
1197 if (fn[len - 1] == '/') {
1199 if (!--len && !dir) {
1204 else if (len >= 2 && fn[len - 1] == '.'
1205 && fn[len - 2] == '/') {
1207 if (!(len -= 2) && !dir) {
1214 if (len == 1 && fn[0] == '/')
1217 /* Reject a ".." dir in the active part of the path. */
1218 for (p = fn; (p = strstr(p, "..")) != NULL; p += 2) {
1219 if ((p[2] == '/' || p[2] == '\0')
1220 && (p == fn || p[-1] == '/')) {
1222 "found \"..\" dir in relative path: %s\n",
1224 exit_cleanup(RERR_SYNTAX);
1235 static const char *lastdir;
1236 static int lastdir_len;
1238 strlcpy(olddir, curr_dir, sizeof olddir);
1240 if (!push_dir(dir, 0)) {
1241 io_error |= IOERR_GENERAL;
1242 rsyserr(FERROR, errno, "push_dir %s failed",
1247 if (lastdir && strcmp(lastdir, dir) == 0) {
1248 flist_dir = lastdir;
1249 flist_dir_len = lastdir_len;
1251 flist_dir = lastdir = strdup(dir);
1252 flist_dir_len = lastdir_len = strlen(dir);
1257 memmove(fbuf, fn, len + 1);
1259 if (implied_dirs && (p=strrchr(fbuf,'/')) && p != fbuf) {
1260 /* Send the implied directories at the start of the
1261 * source spec, so we get their permissions right. */
1262 char *lp = lastpath, *slash = fbuf;
1264 /* Skip any initial directories in our path that we
1265 * have in common with lastpath. */
1266 for (fn = fbuf; *fn && *lp == *fn; lp++, fn++) {
1271 if (fn != p || (*lp && *lp != '/')) {
1272 int save_copy_links = copy_links;
1273 int save_xfer_dirs = xfer_dirs;
1274 copy_links |= copy_unsafe_links;
1276 while ((slash = strchr(slash+1, '/')) != 0) {
1278 send_file_name(f, flist, fbuf, NULL, 0);
1281 copy_links = save_copy_links;
1282 xfer_dirs = save_xfer_dirs;
1284 strlcpy(lastpath, fbuf, sizeof lastpath);
1289 if (one_file_system)
1290 filesystem_dev = st.st_dev;
1292 if (recurse || (xfer_dirs && is_dot_dir)) {
1293 struct file_struct *file;
1294 file = send_file_name(f, flist, fbuf, &st, FLAG_TOP_DIR);
1296 send_if_directory(f, flist, file, fbuf, len);
1298 send_file_name(f, flist, fbuf, &st, 0);
1303 if (!pop_dir(olddir)) {
1304 rsyserr(FERROR, errno, "pop_dir %s failed",
1305 full_fname(olddir));
1306 exit_cleanup(RERR_FILESELECT);
1311 gettimeofday(&end_tv, NULL);
1312 stats.flist_buildtime = (int64)(end_tv.tv_sec - start_tv.tv_sec) * 1000
1313 + (end_tv.tv_usec - start_tv.tv_usec) / 1000;
1314 if (stats.flist_buildtime == 0)
1315 stats.flist_buildtime = 1;
1318 send_file_entry(NULL, f);
1320 if (show_filelist_p())
1321 finish_filelist_progress(flist);
1323 gettimeofday(&end_tv, NULL);
1324 stats.flist_xfertime = (int64)(end_tv.tv_sec - start_tv.tv_sec) * 1000
1325 + (end_tv.tv_usec - start_tv.tv_usec) / 1000;
1327 /* Sort the list without removing any duplicates. This allows the
1328 * receiving side to ask for any name they like, which gives us the
1329 * flexibility to change the way we unduplicate names in the future
1330 * without causing a compatibility problem with older versions. */
1331 clean_flist(flist, 0, 0);
1336 /* send the io_error flag */
1337 write_int(f, lp_ignore_errors(module_id) ? 0 : io_error);
1340 stats.flist_size = stats.total_written - start_write;
1341 stats.num_files = flist->count;
1344 output_flist(flist);
1347 rprintf(FINFO, "send_file_list done\n");
1352 struct file_list *recv_file_list(int f)
1354 struct file_list *flist;
1355 unsigned short flags;
1358 rprintf(FLOG, "receiving file list\n");
1359 if (show_filelist_p())
1360 start_filelist_progress("receiving file list");
1362 start_read = stats.total_read;
1364 flist = flist_new(WITH_HLINK, "recv_file_list");
1367 while ((flags = read_byte(f)) != 0) {
1368 struct file_struct *file;
1370 flist_expand(flist);
1372 if (protocol_version >= 28 && (flags & XMIT_EXTENDED_FLAGS))
1373 flags |= read_byte(f) << 8;
1374 file = recv_file_entry(flist, flags, f);
1376 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
1377 stats.total_size += file->length;
1379 flist->files[flist->count++] = file;
1381 maybe_emit_filelist_progress(flist->count);
1384 rprintf(FINFO, "recv_file_name(%s)\n",
1385 f_name(file, NULL));
1388 recv_file_entry(NULL, 0, 0); /* Signal that we're done. */
1391 rprintf(FINFO, "received %d names\n", flist->count);
1393 if (show_filelist_p())
1394 finish_filelist_progress(flist);
1396 clean_flist(flist, relative_paths, 1);
1399 recv_uid_list(f, flist);
1401 /* Recv the io_error flag */
1402 if (lp_ignore_errors(module_id) || ignore_errors)
1405 io_error |= read_int(f);
1409 output_flist(flist);
1413 for (i = 0; i < flist->count; i++)
1414 list_file_entry(flist->files[i]);
1418 rprintf(FINFO, "recv_file_list done\n");
1420 stats.flist_size = stats.total_read - start_read;
1421 stats.num_files = flist->count;
1426 static int file_compare(struct file_struct **file1, struct file_struct **file2)
1428 return f_name_cmp(*file1, *file2);
1431 /* Search for an identically-named item in the file list. Note that the
1432 * items must agree in their directory-ness, or no match is returned. */
1433 int flist_find(struct file_list *flist, struct file_struct *f)
1435 int low = flist->low, high = flist->high;
1436 int diff, mid, mid_up;
1438 while (low <= high) {
1439 mid = (low + high) / 2;
1440 if (flist->files[mid]->basename)
1443 /* Scan for the next non-empty entry using the cached
1444 * distance values. If the value isn't fully up-to-
1445 * date, update it. */
1446 mid_up = mid + flist->files[mid]->dir.depth;
1447 if (!flist->files[mid_up]->basename) {
1449 mid_up += flist->files[mid_up]->dir.depth;
1450 } while (!flist->files[mid_up]->basename);
1451 flist->files[mid]->dir.depth = mid_up - mid;
1453 if (mid_up > high) {
1454 /* If there's nothing left above us, set high to
1455 * a non-empty entry below us and continue. */
1456 high = mid - (int)flist->files[mid]->length;
1457 if (!flist->files[high]->basename) {
1459 high -= (int)flist->files[high]->length;
1460 } while (!flist->files[high]->basename);
1461 flist->files[mid]->length = mid - high;
1466 diff = f_name_cmp(flist->files[mid_up], f);
1468 if (protocol_version < 29
1469 && S_ISDIR(flist->files[mid_up]->mode)
1470 != S_ISDIR(f->mode))
1483 * Free up any resources a file_struct has allocated
1484 * and clear the file.
1486 void clear_file(struct file_struct *file)
1488 memset(file, 0, file_struct_len);
1489 /* In an empty entry, dir.depth is an offset to the next non-empty
1490 * entry. Likewise for length in the opposite direction. We assume
1491 * that we're alone for now since flist_find() will adjust the counts
1492 * it runs into that aren't up-to-date. */
1493 file->length = file->dir.depth = 1;
1497 * allocate a new file list
1499 struct file_list *flist_new(int with_hlink, char *msg)
1501 struct file_list *flist;
1503 flist = new(struct file_list);
1507 memset(flist, 0, sizeof flist[0]);
1509 if (!(flist->file_pool = pool_create(FILE_EXTENT, 0, out_of_memory, POOL_INTERN)))
1512 #ifdef SUPPORT_HARD_LINKS
1513 if (with_hlink && preserve_hard_links) {
1514 if (!(flist->hlink_pool = pool_create(HLINK_EXTENT,
1515 sizeof (struct idev), out_of_memory, POOL_INTERN)))
1524 * free up all elements in a flist
1526 void flist_free(struct file_list *flist)
1528 pool_destroy(flist->file_pool);
1529 pool_destroy(flist->hlink_pool);
1535 * This routine ensures we don't have any duplicate names in our file list.
1536 * duplicate names can cause corruption because of the pipelining
1538 static void clean_flist(struct file_list *flist, int strip_root, int no_dups)
1540 char fbuf[MAXPATHLEN];
1545 if (flist->count == 0) {
1550 qsort(flist->files, flist->count,
1551 sizeof flist->files[0], (int (*)())file_compare);
1553 for (i = no_dups? 0 : flist->count; i < flist->count; i++) {
1554 if (flist->files[i]->basename) {
1559 flist->low = prev_i;
1560 while (++i < flist->count) {
1562 struct file_struct *file = flist->files[i];
1564 if (!file->basename)
1566 if (f_name_cmp(file, flist->files[prev_i]) == 0)
1568 else if (protocol_version >= 29 && S_ISDIR(file->mode)) {
1569 int save_mode = file->mode;
1570 /* Make sure that this directory doesn't duplicate a
1571 * non-directory earlier in the list. */
1572 flist->high = prev_i;
1573 file->mode = S_IFREG;
1574 j = flist_find(flist, file);
1575 file->mode = save_mode;
1579 struct file_struct *fp = flist->files[j];
1581 /* If one is a dir and the other is not, we want to
1582 * keep the dir because it might have contents in the
1584 if (S_ISDIR(file->mode) != S_ISDIR(fp->mode)) {
1585 if (S_ISDIR(file->mode))
1591 if (verbose > 1 && !am_server) {
1593 "removing duplicate name %s from file list (%d)\n",
1594 f_name(file, fbuf), drop);
1596 /* Make sure we don't lose track of a user-specified
1598 flist->files[keep]->flags |= flist->files[drop]->flags
1599 & (FLAG_TOP_DIR|FLAG_XFER_DIR);
1601 clear_file(flist->files[drop]);
1604 if (flist->low == drop) {
1606 j < i && !flist->files[j]->basename;
1615 flist->high = no_dups ? prev_i : flist->count - 1;
1618 /* We need to strip off the leading slashes for relative
1619 * paths, but this must be done _after_ the sorting phase. */
1620 for (i = flist->low; i <= flist->high; i++) {
1621 struct file_struct *file = flist->files[i];
1625 while (*file->dirname == '/')
1627 if (!*file->dirname)
1628 file->dirname = NULL;
1632 if (prune_empty_dirs && no_dups) {
1633 int j, prev_depth = 0;
1635 prev_i = 0; /* It's OK that this isn't really true. */
1637 for (i = flist->low; i <= flist->high; i++) {
1638 struct file_struct *fp, *file = flist->files[i];
1640 /* This temporarily abuses the dir.depth value for a
1641 * directory that is in a chain that might get pruned.
1642 * We restore the old value if it gets a reprieve. */
1643 if (S_ISDIR(file->mode) && file->dir.depth) {
1644 /* Dump empty dirs when coming back down. */
1645 for (j = prev_depth; j >= file->dir.depth; j--) {
1646 fp = flist->files[prev_i];
1647 if (fp->dir.depth >= 0)
1649 prev_i = -fp->dir.depth-1;
1652 prev_depth = file->dir.depth;
1653 if (is_excluded(f_name(file, fbuf), 1,
1655 /* Keep dirs through this dir. */
1656 for (j = prev_depth-1; ; j--) {
1657 fp = flist->files[prev_i];
1658 if (fp->dir.depth >= 0)
1660 prev_i = -fp->dir.depth-1;
1664 file->dir.depth = -prev_i-1;
1667 /* Keep dirs through this non-dir. */
1668 for (j = prev_depth; ; j--) {
1669 fp = flist->files[prev_i];
1670 if (fp->dir.depth >= 0)
1672 prev_i = -fp->dir.depth-1;
1677 /* Dump empty all remaining empty dirs. */
1679 struct file_struct *fp = flist->files[prev_i];
1680 if (fp->dir.depth >= 0)
1682 prev_i = -fp->dir.depth-1;
1686 for (i = flist->low; i <= flist->high; i++) {
1687 if (flist->files[i]->basename)
1691 for (i = flist->high; i >= flist->low; i--) {
1692 if (flist->files[i]->basename)
1699 static void output_flist(struct file_list *flist)
1701 char uidbuf[16], gidbuf[16], depthbuf[16];
1702 struct file_struct *file;
1703 const char *who = who_am_i();
1706 for (i = 0; i < flist->count; i++) {
1707 file = flist->files[i];
1708 if ((am_root || am_sender) && preserve_uid) {
1709 snprintf(uidbuf, sizeof uidbuf, " uid=%ld",
1713 if (preserve_gid && F_GID(file) != GID_NONE) {
1714 snprintf(gidbuf, sizeof gidbuf, " gid=%ld",
1719 snprintf(depthbuf, sizeof depthbuf, "%d", file->dir.depth);
1720 rprintf(FINFO, "[%s] i=%d %s %s%s%s%s mode=0%o len=%.0f%s%s flags=%x\n",
1721 who, i, am_sender ? NS(file->dir.root) : depthbuf,
1722 file->dirname ? file->dirname : "",
1723 file->dirname ? "/" : "", NS(file->basename),
1724 S_ISDIR(file->mode) ? "/" : "", (int)file->mode,
1725 (double)file->length, uidbuf, gidbuf, file->flags);
1729 enum fnc_state { s_DIR, s_SLASH, s_BASE, s_TRAILING };
1730 enum fnc_type { t_PATH, t_ITEM };
1732 /* Compare the names of two file_struct entities, similar to how strcmp()
1733 * would do if it were operating on the joined strings.
1735 * Some differences beginning with protocol_version 29: (1) directory names
1736 * are compared with an assumed trailing slash so that they compare in a
1737 * way that would cause them to sort immediately prior to any content they
1738 * may have; (2) a directory of any name compares after a non-directory of
1739 * any name at the same depth; (3) a directory with name "." compares prior
1740 * to anything else. These changes mean that a directory and a non-dir
1741 * with the same name will not compare as equal (protocol_version >= 29).
1743 * The dirname component can be an empty string, but the basename component
1744 * cannot (and never is in the current codebase). The basename component
1745 * may be NULL (for a removed item), in which case it is considered to be
1746 * after any existing item. */
1747 int f_name_cmp(struct file_struct *f1, struct file_struct *f2)
1750 const uchar *c1, *c2;
1751 enum fnc_state state1, state2;
1752 enum fnc_type type1, type2;
1753 enum fnc_type t_path = protocol_version >= 29 ? t_PATH : t_ITEM;
1755 if (!f1 || !f1->basename) {
1756 if (!f2 || !f2->basename)
1760 if (!f2 || !f2->basename)
1763 c1 = (uchar*)f1->dirname;
1764 c2 = (uchar*)f2->dirname;
1768 type1 = S_ISDIR(f1->mode) ? t_path : t_ITEM;
1769 c1 = (uchar*)f1->basename;
1770 if (type1 == t_PATH && *c1 == '.' && !c1[1]) {
1772 state1 = s_TRAILING;
1781 type2 = S_ISDIR(f2->mode) ? t_path : t_ITEM;
1782 c2 = (uchar*)f2->basename;
1783 if (type2 == t_PATH && *c2 == '.' && !c2[1]) {
1785 state2 = s_TRAILING;
1795 return type1 == t_PATH ? 1 : -1;
1805 type1 = S_ISDIR(f1->mode) ? t_path : t_ITEM;
1806 c1 = (uchar*)f1->basename;
1807 if (type1 == t_PATH && *c1 == '.' && !c1[1]) {
1809 state1 = s_TRAILING;
1815 state1 = s_TRAILING;
1816 if (type1 == t_PATH) {
1825 if (*c2 && type1 != type2)
1826 return type1 == t_PATH ? 1 : -1;
1835 type2 = S_ISDIR(f2->mode) ? t_path : t_ITEM;
1836 c2 = (uchar*)f2->basename;
1837 if (type2 == t_PATH && *c2 == '.' && !c2[1]) {
1839 state2 = s_TRAILING;
1845 state2 = s_TRAILING;
1846 if (type2 == t_PATH) {
1858 return type1 == t_PATH ? 1 : -1;
1860 } while ((dif = (int)*c1++ - (int)*c2++) == 0);
1865 /* Return a copy of the full filename of a flist entry, using the indicated
1866 * buffer or one of 5 static buffers if fbuf is NULL. No size-checking is
1867 * done because we checked the size when creating the file_struct entry.
1869 char *f_name(struct file_struct *f, char *fbuf)
1871 if (!f || !f->basename)
1875 static char names[5][MAXPATHLEN];
1876 static unsigned int n;
1878 n = (n + 1) % (sizeof names / sizeof names[0]);
1884 int len = strlen(f->dirname);
1885 memcpy(fbuf, f->dirname, len);
1887 strlcpy(fbuf + len + 1, f->basename, MAXPATHLEN - (len + 1));
1889 strlcpy(fbuf, f->basename, MAXPATHLEN);
1894 /* Do a non-recursive scan of the named directory, possibly ignoring all
1895 * exclude rules except for the daemon's. If "dlen" is >=0, it is the length
1896 * of the dirname string, and also indicates that "dirname" is a MAXPATHLEN
1897 * buffer (the functions we call will append names onto the end, but the old
1898 * dir value will be restored on exit). */
1899 struct file_list *get_dirlist(char *dirname, int dlen,
1900 int ignore_filter_rules)
1902 struct file_list *dirlist;
1903 char dirbuf[MAXPATHLEN];
1904 int save_recurse = recurse;
1905 int save_xfer_dirs = xfer_dirs;
1908 dlen = strlcpy(dirbuf, dirname, MAXPATHLEN);
1909 if (dlen >= MAXPATHLEN)
1914 dirlist = flist_new(WITHOUT_HLINK, "get_dirlist");
1918 send_directory(ignore_filter_rules ? -2 : -1, dirlist, dirname, dlen);
1919 xfer_dirs = save_xfer_dirs;
1920 recurse = save_recurse;
1922 flist_count_offset += dirlist->count;
1924 clean_flist(dirlist, 0, 0);
1927 output_flist(dirlist);