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 ignore_perishable;
52 extern int non_perishable_cnt;
53 extern int prune_empty_dirs;
54 extern int copy_links;
55 extern int copy_unsafe_links;
56 extern int protocol_version;
57 extern int sanitize_paths;
58 extern struct stats stats;
59 extern struct file_list *the_file_list;
61 extern char curr_dir[MAXPATHLEN];
63 extern struct chmod_mode_struct *chmod_modes;
65 extern struct filter_list_struct filter_list;
66 extern struct filter_list_struct server_filter_list;
70 dev_t filesystem_dev; /* used to implement -x */
71 unsigned int file_struct_len;
73 static char empty_sum[MD4_SUM_LENGTH];
74 static int flist_count_offset;
76 static void clean_flist(struct file_list *flist, int strip_root, int no_dups);
77 static void output_flist(struct file_list *flist);
83 /* Figure out how big the file_struct is without trailing padding */
84 file_struct_len = offsetof(struct file_struct, flags) + sizeof f.flags;
85 checksum_len = protocol_version < 21 ? 2 : MD4_SUM_LENGTH;
88 static int show_filelist_p(void)
90 return verbose && xfer_dirs && !am_server;
93 static void start_filelist_progress(char *kind)
95 rprintf(FCLIENT, "%s ... ", kind);
96 if (verbose > 1 || do_progress)
97 rprintf(FCLIENT, "\n");
101 static void emit_filelist_progress(int count)
103 rprintf(FCLIENT, " %d files...\r", count);
106 static void maybe_emit_filelist_progress(int count)
108 if (do_progress && show_filelist_p() && (count % 100) == 0)
109 emit_filelist_progress(count);
112 static void finish_filelist_progress(const struct file_list *flist)
115 /* This overwrites the progress line */
116 rprintf(FINFO, "%d file%sto consider\n",
117 flist->count, flist->count == 1 ? " " : "s ");
119 rprintf(FINFO, "done\n");
122 void show_flist_stats(void)
127 static void list_file_entry(struct file_struct *f)
129 char permbuf[PERMSTRING_SIZE];
132 /* this can happen if duplicate names were removed */
136 permstring(permbuf, f->mode);
139 if (preserve_links && S_ISLNK(f->mode)) {
140 rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
142 (double)f->length, timestring(f->modtime),
143 f_name(f, NULL), f->u.link);
147 rprintf(FINFO, "%s %11.0f %s %s\n",
149 (double)f->length, timestring(f->modtime),
154 /* Stat either a symlink or its referent, depending on the settings of
155 * copy_links, copy_unsafe_links, etc. Returns -1 on error, 0 on success.
157 * If path is the name of a symlink, then the linkbuf buffer (which must hold
158 * MAXPATHLEN chars) will be set to the symlink's target string.
160 * The stat structure pointed to by stp will contain information about the
161 * link or the referent as appropriate, if they exist. */
162 static int readlink_stat(const char *path, STRUCT_STAT *stp, char *linkbuf)
165 if (link_stat(path, stp, copy_dirlinks) < 0)
167 if (S_ISLNK(stp->st_mode)) {
168 int llen = readlink(path, linkbuf, MAXPATHLEN - 1);
171 linkbuf[llen] = '\0';
172 if (copy_unsafe_links && unsafe_symlink(linkbuf, path)) {
174 rprintf(FINFO,"copying unsafe symlink \"%s\" -> \"%s\"\n",
177 return do_stat(path, stp);
182 return do_stat(path, stp);
186 int link_stat(const char *path, STRUCT_STAT *stp, int follow_dirlinks)
190 return do_stat(path, stp);
191 if (do_lstat(path, stp) < 0)
193 if (follow_dirlinks && S_ISLNK(stp->st_mode)) {
195 if (do_stat(path, &st) == 0 && S_ISDIR(st.st_mode))
200 return do_stat(path, stp);
204 /* This function is used to check if a file should be included/excluded
205 * from the list of files based on its name and type etc. The value of
206 * filter_level is set to either SERVER_FILTERS or ALL_FILTERS. */
207 static int is_excluded(char *fname, int is_dir, int filter_level)
209 #if 0 /* This currently never happens, so avoid a useless compare. */
210 if (filter_level == NO_FILTERS)
214 /* never exclude '.', even if somebody does --exclude '*' */
215 if (fname[0] == '.' && !fname[1])
217 /* Handle the -R version of the '.' dir. */
218 if (fname[0] == '/') {
219 int len = strlen(fname);
220 if (fname[len-1] == '.' && fname[len-2] == '/')
224 if (server_filter_list.head
225 && check_filter(&server_filter_list, fname, is_dir) < 0)
227 if (filter_level != ALL_FILTERS)
230 && check_filter(&filter_list, fname, is_dir) < 0)
235 static int to_wire_mode(mode_t mode)
238 #if _S_IFLNK != 0120000
240 return (mode & ~(_S_IFMT)) | 0120000;
246 static mode_t from_wire_mode(int mode)
248 #if _S_IFLNK != 0120000
249 if ((mode & (_S_IFMT)) == 0120000)
250 return (mode & ~(_S_IFMT)) | _S_IFLNK;
255 static void send_directory(int f, struct file_list *flist,
256 char *fbuf, int len);
258 static char *flist_dir;
259 static int flist_dir_len;
263 * Make sure @p flist is big enough to hold at least @p flist->count
266 void flist_expand(struct file_list *flist)
268 struct file_struct **new_ptr;
270 if (flist->count < flist->malloced)
273 if (flist->malloced < FLIST_START)
274 flist->malloced = FLIST_START;
275 else if (flist->malloced >= FLIST_LINEAR)
276 flist->malloced += FLIST_LINEAR;
278 flist->malloced *= 2;
281 * In case count jumped or we are starting the list
282 * with a known size just set it.
284 if (flist->malloced < flist->count)
285 flist->malloced = flist->count;
287 new_ptr = realloc_array(flist->files, struct file_struct *,
290 if (verbose >= 2 && flist->malloced != FLIST_START) {
291 rprintf(FCLIENT, "[%s] expand file_list to %.0f bytes, did%s move\n",
293 (double)sizeof flist->files[0] * flist->malloced,
294 (new_ptr == flist->files) ? " not" : "");
297 flist->files = new_ptr;
300 out_of_memory("flist_expand");
303 static void send_file_entry(struct file_struct *file, int f)
305 unsigned short flags;
306 static time_t modtime;
310 static uint32 rdev_major;
313 static char lastname[MAXPATHLEN];
314 char fname[MAXPATHLEN];
322 modtime = 0, mode = 0;
323 dev = 0, rdev = MAKEDEV(0, 0);
332 flags = file->flags & XMIT_TOP_DIR;
334 if (file->mode == mode)
335 flags |= XMIT_SAME_MODE;
338 if ((preserve_devices && IS_DEVICE(mode))
339 || (preserve_specials && IS_SPECIAL(mode))) {
340 if (protocol_version < 28) {
341 if (file->u.rdev == rdev)
342 flags |= XMIT_SAME_RDEV_pre28;
347 if ((uint32)major(rdev) == rdev_major)
348 flags |= XMIT_SAME_RDEV_MAJOR;
350 rdev_major = major(rdev);
351 if ((uint32)minor(rdev) <= 0xFFu)
352 flags |= XMIT_RDEV_MINOR_IS_SMALL;
354 } else if (protocol_version < 28)
355 rdev = MAKEDEV(0, 0);
356 if (file->uid == uid)
357 flags |= XMIT_SAME_UID;
360 if (file->gid == gid)
361 flags |= XMIT_SAME_GID;
364 if (file->modtime == modtime)
365 flags |= XMIT_SAME_TIME;
367 modtime = file->modtime;
369 #ifdef SUPPORT_HARD_LINKS
370 if (file->link_u.idev) {
371 if (file->F_DEV == dev) {
372 if (protocol_version >= 28)
373 flags |= XMIT_SAME_DEV;
376 flags |= XMIT_HAS_IDEV_DATA;
381 lastname[l1] && (fname[l1] == lastname[l1]) && (l1 < 255);
383 l2 = strlen(fname+l1);
386 flags |= XMIT_SAME_NAME;
388 flags |= XMIT_LONG_NAME;
390 /* We must make sure we don't send a zero flag byte or the
391 * other end will terminate the flist transfer. Note that
392 * the use of XMIT_TOP_DIR on a non-dir has no meaning, so
393 * it's harmless way to add a bit to the first flag byte. */
394 if (protocol_version >= 28) {
395 if (!flags && !S_ISDIR(mode))
396 flags |= XMIT_TOP_DIR;
397 if ((flags & 0xFF00) || !flags) {
398 flags |= XMIT_EXTENDED_FLAGS;
399 write_byte(f, flags);
400 write_byte(f, flags >> 8);
402 write_byte(f, flags);
405 flags |= S_ISDIR(mode) ? XMIT_LONG_NAME : XMIT_TOP_DIR;
406 write_byte(f, flags);
408 if (flags & XMIT_SAME_NAME)
410 if (flags & XMIT_LONG_NAME)
414 write_buf(f, fname + l1, l2);
416 write_longint(f, file->length);
417 if (!(flags & XMIT_SAME_TIME))
418 write_int(f, modtime);
419 if (!(flags & XMIT_SAME_MODE))
420 write_int(f, to_wire_mode(mode));
421 if (preserve_uid && !(flags & XMIT_SAME_UID)) {
426 if (preserve_gid && !(flags & XMIT_SAME_GID)) {
431 if ((preserve_devices && IS_DEVICE(mode))
432 || (preserve_specials && IS_SPECIAL(mode))) {
433 if (protocol_version < 28) {
434 if (!(flags & XMIT_SAME_RDEV_pre28))
435 write_int(f, (int)rdev);
437 if (!(flags & XMIT_SAME_RDEV_MAJOR))
438 write_int(f, major(rdev));
439 if (flags & XMIT_RDEV_MINOR_IS_SMALL)
440 write_byte(f, minor(rdev));
442 write_int(f, minor(rdev));
447 if (preserve_links && S_ISLNK(mode)) {
448 int len = strlen(file->u.link);
450 write_buf(f, file->u.link, len);
454 #ifdef SUPPORT_HARD_LINKS
455 if (file->link_u.idev) {
456 if (protocol_version < 26) {
457 /* 32-bit dev_t and ino_t */
459 write_int(f, file->F_INODE);
461 /* 64-bit dev_t and ino_t */
462 if (!(flags & XMIT_SAME_DEV))
463 write_longint(f, dev);
464 write_longint(f, file->F_INODE);
469 if (always_checksum && (S_ISREG(mode) || protocol_version < 28)) {
474 /* Prior to 28, we sent a useless set of nulls. */
477 write_buf(f, sum, checksum_len);
480 strlcpy(lastname, fname, MAXPATHLEN);
483 static struct file_struct *receive_file_entry(struct file_list *flist,
484 unsigned short flags, int f)
486 static time_t modtime;
490 static uint32 rdev_major;
493 static char lastname[MAXPATHLEN], *lastdir;
494 static int lastdir_depth, lastdir_len = -1;
495 static unsigned int del_hier_name_len = 0;
496 static int in_del_hier = 0;
497 char thisname[MAXPATHLEN];
498 unsigned int l1 = 0, l2 = 0;
499 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
501 char *basename, *dirname, *bp;
502 struct file_struct *file;
505 modtime = 0, mode = 0;
506 dev = 0, rdev = MAKEDEV(0, 0);
515 if (flags & XMIT_SAME_NAME)
518 if (flags & XMIT_LONG_NAME)
523 if (l2 >= MAXPATHLEN - l1) {
525 "overflow: flags=0x%x l1=%d l2=%d lastname=%s\n",
526 flags, l1, l2, lastname);
527 overflow_exit("receive_file_entry");
530 strlcpy(thisname, lastname, l1 + 1);
531 read_sbuf(f, &thisname[l1], l2);
532 thisname[l1 + l2] = 0;
534 strlcpy(lastname, thisname, MAXPATHLEN);
536 clean_fname(thisname, 0);
539 sanitize_path(thisname, thisname, "", 0, NULL);
541 if ((basename = strrchr(thisname, '/')) != NULL) {
542 dirname_len = ++basename - thisname; /* counts future '\0' */
543 if (lastdir_len == dirname_len - 1
544 && strncmp(thisname, lastdir, lastdir_len) == 0) {
546 dirname_len = 0; /* indicates no copy is needed */
554 basename_len = strlen(basename) + 1; /* count the '\0' */
556 file_length = read_longint(f);
557 if (!(flags & XMIT_SAME_TIME))
558 modtime = (time_t)read_int(f);
559 if (!(flags & XMIT_SAME_MODE))
560 mode = from_wire_mode(read_int(f));
562 if (chmod_modes && !S_ISLNK(mode))
563 mode = tweak_mode(mode, chmod_modes);
565 if (preserve_uid && !(flags & XMIT_SAME_UID))
566 uid = (uid_t)read_int(f);
567 if (preserve_gid && !(flags & XMIT_SAME_GID))
568 gid = (gid_t)read_int(f);
570 if ((preserve_devices && IS_DEVICE(mode))
571 || (preserve_specials && IS_SPECIAL(mode))) {
572 if (protocol_version < 28) {
573 if (!(flags & XMIT_SAME_RDEV_pre28))
574 rdev = (dev_t)read_int(f);
577 if (!(flags & XMIT_SAME_RDEV_MAJOR))
578 rdev_major = read_int(f);
579 if (flags & XMIT_RDEV_MINOR_IS_SMALL)
580 rdev_minor = read_byte(f);
582 rdev_minor = read_int(f);
583 rdev = MAKEDEV(rdev_major, rdev_minor);
585 } else if (protocol_version < 28)
586 rdev = MAKEDEV(0, 0);
589 if (preserve_links && S_ISLNK(mode)) {
590 linkname_len = read_int(f) + 1; /* count the '\0' */
591 if (linkname_len <= 0 || linkname_len > MAXPATHLEN) {
592 rprintf(FERROR, "overflow: linkname_len=%d\n",
594 overflow_exit("receive_file_entry");
601 sum_len = always_checksum && S_ISREG(mode) ? MD4_SUM_LENGTH : 0;
603 alloc_len = file_struct_len + dirname_len + basename_len
604 + linkname_len + sum_len;
605 bp = pool_alloc(flist->file_pool, alloc_len, "receive_file_entry");
607 file = (struct file_struct *)bp;
608 memset(bp, 0, file_struct_len);
609 bp += file_struct_len;
611 file->modtime = modtime;
612 file->length = file_length;
618 file->dirname = lastdir = bp;
619 lastdir_len = dirname_len - 1;
620 memcpy(bp, dirname, dirname_len - 1);
623 lastdir_depth = count_dir_elements(lastdir);
624 file->dir.depth = lastdir_depth + 1;
625 } else if (dirname) {
626 file->dirname = dirname; /* we're reusing lastname */
627 file->dir.depth = lastdir_depth + 1;
632 if (basename_len == 1+1 && *basename == '.') /* +1 for '\0' */
634 if (flags & XMIT_TOP_DIR) {
635 in_del_hier = recurse;
636 del_hier_name_len = file->dir.depth == 0 ? 0 : l1 + l2;
637 if (relative_paths && del_hier_name_len > 2
638 && lastname[del_hier_name_len-1] == '.'
639 && lastname[del_hier_name_len-2] == '/')
640 del_hier_name_len -= 2;
641 file->flags |= FLAG_TOP_DIR | FLAG_DEL_HERE;
642 } else if (in_del_hier) {
643 if (!relative_paths || !del_hier_name_len
644 || (l1 >= del_hier_name_len
645 && lastname[del_hier_name_len] == '/'))
646 file->flags |= FLAG_DEL_HERE;
653 memcpy(bp, basename, basename_len);
656 if ((preserve_devices && IS_DEVICE(mode))
657 || (preserve_specials && IS_SPECIAL(mode)))
663 read_sbuf(f, bp, linkname_len - 1);
665 sanitize_path(bp, bp, "", lastdir_depth, NULL);
670 #ifdef SUPPORT_HARD_LINKS
671 if (preserve_hard_links && protocol_version < 28 && S_ISREG(mode))
672 flags |= XMIT_HAS_IDEV_DATA;
673 if (flags & XMIT_HAS_IDEV_DATA) {
675 if (protocol_version < 26) {
679 if (!(flags & XMIT_SAME_DEV))
680 dev = read_longint(f);
681 inode = read_longint(f);
683 if (flist->hlink_pool) {
684 file->link_u.idev = pool_talloc(flist->hlink_pool,
685 struct idev, 1, "inode_table");
686 file->F_INODE = inode;
692 if (always_checksum && (sum_len || protocol_version < 28)) {
695 file->u.sum = sum = bp;
698 /* Prior to 28, we get a useless set of nulls. */
701 read_buf(f, sum, checksum_len);
708 * Create a file_struct for a named file by reading its stat()
709 * information and performing extensive checks against global
712 * @return the new file, or NULL if there was an error or this file
713 * should be excluded.
715 * @todo There is a small optimization opportunity here to avoid
716 * stat()ing the file in some circumstances, which has a certain cost.
717 * We are called immediately after doing readdir(), and so we may
718 * already know the d_type of the file. We could for example avoid
719 * statting directories if we're not recursing, but this is not a very
720 * important case. Some systems may not have d_type.
722 struct file_struct *make_file(char *fname, struct file_list *flist,
723 STRUCT_STAT *stp, unsigned short flags,
726 static char *lastdir;
727 static int lastdir_len = -1;
728 struct file_struct *file;
730 char sum[SUM_LENGTH];
731 char thisname[MAXPATHLEN];
732 char linkname[MAXPATHLEN];
733 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
734 char *basename, *dirname, *bp;
736 if (!flist || !flist->count) /* Ignore lastdir when invalid. */
739 if (strlcpy(thisname, fname, sizeof thisname)
740 >= sizeof thisname - flist_dir_len) {
741 rprintf(FINFO, "skipping overly long name: %s\n", fname);
744 clean_fname(thisname, 0);
746 sanitize_path(thisname, thisname, "", 0, NULL);
748 memset(sum, 0, SUM_LENGTH);
750 if (stp && S_ISDIR(stp->st_mode)) {
751 st = *stp; /* Needed for "symlink/." with --relative. */
752 *linkname = '\0'; /* make IBM code checker happy */
753 } else if (readlink_stat(thisname, &st, linkname) != 0) {
754 int save_errno = errno;
755 /* See if file is excluded before reporting an error. */
756 if (filter_level != NO_FILTERS
757 && (is_excluded(thisname, 0, filter_level)
758 || is_excluded(thisname, 1, filter_level))) {
759 if (ignore_perishable && save_errno != ENOENT)
760 non_perishable_cnt++;
763 if (save_errno == ENOENT) {
765 /* Avoid "vanished" error if symlink points nowhere. */
766 if (copy_links && do_lstat(thisname, &st) == 0
767 && S_ISLNK(st.st_mode)) {
768 io_error |= IOERR_GENERAL;
769 rprintf(FERROR, "symlink has no referent: %s\n",
770 full_fname(thisname));
774 enum logcode c = am_daemon && protocol_version < 28
776 io_error |= IOERR_VANISHED;
777 rprintf(c, "file has vanished: %s\n",
778 full_fname(thisname));
781 io_error |= IOERR_GENERAL;
782 rsyserr(FERROR, save_errno, "readlink %s failed",
783 full_fname(thisname));
788 /* backup.c calls us with filter_level set to NO_FILTERS. */
789 if (filter_level == NO_FILTERS)
792 if (S_ISDIR(st.st_mode) && !xfer_dirs) {
793 rprintf(FINFO, "skipping directory %s\n", thisname);
797 /* We only care about directories because we need to avoid recursing
798 * into a mount-point directory, not to avoid copying a symlinked
799 * file if -L (or similar) was specified. */
800 if (one_file_system && st.st_dev != filesystem_dev
801 && S_ISDIR(st.st_mode)) {
802 if (one_file_system > 1) {
804 rprintf(FINFO, "skipping mount-point dir %s\n",
809 flags |= FLAG_MOUNT_POINT;
812 if (is_excluded(thisname, S_ISDIR(st.st_mode) != 0, filter_level)) {
813 if (ignore_perishable)
814 non_perishable_cnt++;
818 if (lp_ignore_nonreadable(module_id)) {
820 if (!S_ISLNK(st.st_mode))
822 if (access(thisname, R_OK) != 0)
829 rprintf(FINFO, "[%s] make_file(%s,*,%d)\n",
830 who_am_i(), thisname, filter_level);
833 if ((basename = strrchr(thisname, '/')) != NULL) {
834 dirname_len = ++basename - thisname; /* counts future '\0' */
835 if (lastdir_len == dirname_len - 1
836 && strncmp(thisname, lastdir, lastdir_len) == 0) {
838 dirname_len = 0; /* indicates no copy is needed */
846 basename_len = strlen(basename) + 1; /* count the '\0' */
849 linkname_len = S_ISLNK(st.st_mode) ? strlen(linkname) + 1 : 0;
854 sum_len = always_checksum && am_sender && S_ISREG(st.st_mode)
855 ? MD4_SUM_LENGTH : 0;
857 alloc_len = file_struct_len + dirname_len + basename_len
858 + linkname_len + sum_len;
860 bp = pool_alloc(flist->file_pool, alloc_len, "make_file");
862 if (!(bp = new_array(char, alloc_len)))
863 out_of_memory("make_file");
866 file = (struct file_struct *)bp;
867 memset(bp, 0, file_struct_len);
868 bp += file_struct_len;
871 file->modtime = st.st_mtime;
872 file->length = st.st_size;
873 file->mode = st.st_mode;
874 file->uid = st.st_uid;
875 file->gid = st.st_gid;
877 #ifdef SUPPORT_HARD_LINKS
878 if (flist && flist->hlink_pool) {
879 if (protocol_version < 28) {
880 if (S_ISREG(st.st_mode))
881 file->link_u.idev = pool_talloc(
882 flist->hlink_pool, struct idev, 1,
885 if (!S_ISDIR(st.st_mode) && st.st_nlink > 1)
886 file->link_u.idev = pool_talloc(
887 flist->hlink_pool, struct idev, 1,
891 if (file->link_u.idev) {
892 file->F_DEV = st.st_dev;
893 file->F_INODE = st.st_ino;
898 file->dirname = lastdir = bp;
899 lastdir_len = dirname_len - 1;
900 memcpy(bp, dirname, dirname_len - 1);
904 file->dirname = dirname;
907 memcpy(bp, basename, basename_len);
910 #ifdef HAVE_STRUCT_STAT_ST_RDEV
911 if ((preserve_devices && IS_DEVICE(st.st_mode))
912 || (preserve_specials && IS_SPECIAL(st.st_mode)))
913 file->u.rdev = st.st_rdev;
919 memcpy(bp, linkname, linkname_len);
926 file_checksum(thisname, bp, st.st_size);
930 file->dir.root = flist_dir;
932 /* This code is only used by the receiver when it is building
933 * a list of files for a delete pass. */
934 if (keep_dirlinks && linkname_len && flist) {
936 int save_mode = file->mode;
937 file->mode = S_IFDIR; /* Find a directory with our name. */
938 if (flist_find(the_file_list, file) >= 0
939 && do_stat(thisname, &st2) == 0 && S_ISDIR(st2.st_mode)) {
940 file->modtime = st2.st_mtime;
941 file->length = st2.st_size;
942 file->mode = st2.st_mode;
943 file->uid = st2.st_uid;
944 file->gid = st2.st_gid;
947 file->mode = save_mode;
950 if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))
951 stats.total_size += st.st_size;
956 static struct file_struct *send_file_name(int f, struct file_list *flist,
957 char *fname, STRUCT_STAT *stp,
958 unsigned short flags)
960 struct file_struct *file;
962 file = make_file(fname, flist, stp, flags,
963 f == -2 ? SERVER_FILTERS : ALL_FILTERS);
967 if (chmod_modes && !S_ISLNK(file->mode))
968 file->mode = tweak_mode(file->mode, chmod_modes);
970 maybe_emit_filelist_progress(flist->count + flist_count_offset);
974 if (file->basename[0]) {
975 flist->files[flist->count++] = file;
976 send_file_entry(file, f);
981 static void send_if_directory(int f, struct file_list *flist,
982 struct file_struct *file,
983 char *fbuf, unsigned int ol)
985 char is_dot_dir = fbuf[ol-1] == '.' && (ol == 1 || fbuf[ol-2] == '/');
987 if (S_ISDIR(file->mode)
988 && !(file->flags & FLAG_MOUNT_POINT) && f_name(file, fbuf)) {
990 unsigned int len = strlen(fbuf);
991 if (len > 1 && fbuf[len-1] == '/')
993 if (len >= MAXPATHLEN - 1) {
994 io_error |= IOERR_GENERAL;
995 rprintf(FERROR, "skipping long-named directory: %s\n",
999 save_filters = push_local_filters(fbuf, len);
1000 send_directory(f, flist, fbuf, len);
1001 pop_local_filters(save_filters);
1008 /* This function is normally called by the sender, but the receiving side also
1009 * calls it from get_dirlist() with f set to -1 so that we just construct the
1010 * file list in memory without sending it over the wire. Also, get_dirlist()
1011 * might call this with f set to -2, which also indicates that local filter
1012 * rules should be ignored. */
1013 static void send_directory(int f, struct file_list *flist,
1014 char *fbuf, int len)
1020 int start = flist->count;
1022 if (!(d = opendir(fbuf))) {
1023 io_error |= IOERR_GENERAL;
1024 rsyserr(FERROR, errno, "opendir %s failed", full_fname(fbuf));
1029 if (len != 1 || *fbuf != '/')
1032 remainder = MAXPATHLEN - (p - fbuf);
1034 for (errno = 0, di = readdir(d); di; errno = 0, di = readdir(d)) {
1035 char *dname = d_name(di);
1036 if (dname[0] == '.' && (dname[1] == '\0'
1037 || (dname[1] == '.' && dname[2] == '\0')))
1039 if (strlcpy(p, dname, remainder) >= remainder) {
1040 io_error |= IOERR_GENERAL;
1042 "cannot send long-named file %s\n",
1047 send_file_name(f, flist, fbuf, NULL, 0);
1053 io_error |= IOERR_GENERAL;
1054 rsyserr(FERROR, errno, "readdir(%s)", full_fname(fbuf));
1060 int i, end = flist->count - 1;
1061 for (i = start; i <= end; i++)
1062 send_if_directory(f, flist, flist->files[i], fbuf, len);
1066 struct file_list *send_file_list(int f, int argc, char *argv[])
1070 char *p, *dir, olddir[sizeof curr_dir];
1071 char lastpath[MAXPATHLEN] = "";
1072 struct file_list *flist;
1073 struct timeval start_tv, end_tv;
1077 rprintf(FLOG, "building file list\n");
1078 if (show_filelist_p())
1079 start_filelist_progress("building file list");
1081 start_write = stats.total_written;
1082 gettimeofday(&start_tv, NULL);
1084 flist = flist_new(WITH_HLINK, "send_file_list");
1086 io_start_buffering_out();
1087 if (filesfrom_fd >= 0) {
1088 if (argv[0] && !push_dir(argv[0], 0)) {
1089 rsyserr(FERROR, errno, "push_dir %s failed",
1090 full_fname(argv[0]));
1091 exit_cleanup(RERR_FILESELECT);
1097 char fbuf[MAXPATHLEN];
1102 if (read_filesfrom_line(filesfrom_fd, fbuf) == 0)
1104 sanitize_path(fbuf, fbuf, "", 0, NULL);
1108 strlcpy(fbuf, *argv++, MAXPATHLEN);
1110 sanitize_path(fbuf, fbuf, "", 0, NULL);
1114 if (relative_paths) {
1115 /* We clean up fbuf below. */
1117 } else if (!len || fbuf[len - 1] == '/') {
1118 if (len == 2 && fbuf[0] == '.') {
1119 /* Turn "./" into just "." rather than "./." */
1122 if (len + 1 >= MAXPATHLEN)
1123 overflow_exit("send_file_list");
1128 } else if (len > 1 && fbuf[len-1] == '.' && fbuf[len-2] == '.'
1129 && (len == 2 || fbuf[len-3] == '/')) {
1130 if (len + 2 >= MAXPATHLEN)
1131 overflow_exit("send_file_list");
1137 is_dot_dir = fbuf[len-1] == '.'
1138 && (len == 1 || fbuf[len-2] == '/');
1141 if (link_stat(fbuf, &st, copy_dirlinks) != 0) {
1142 io_error |= IOERR_GENERAL;
1143 rsyserr(FERROR, errno, "link_stat %s failed",
1148 if (S_ISDIR(st.st_mode) && !xfer_dirs) {
1149 rprintf(FINFO, "skipping directory %s\n", fbuf);
1156 if (!relative_paths) {
1157 p = strrchr(fbuf, '/');
1164 len -= p - fbuf + 1;
1169 if ((p = strstr(fbuf, "/./")) != NULL) {
1175 len -= p - fbuf + 3;
1179 /* Get rid of trailing "/" and "/.". */
1181 if (fn[len - 1] == '/') {
1183 if (!--len && !dir) {
1188 else if (len >= 2 && fn[len - 1] == '.'
1189 && fn[len - 2] == '/') {
1191 if (!(len -= 2) && !dir) {
1198 if (len == 1 && fn[0] == '/')
1201 /* Reject a ".." dir in the active part of the path. */
1202 for (p = fn; (p = strstr(p, "..")) != NULL; p += 2) {
1203 if ((p[2] == '/' || p[2] == '\0')
1204 && (p == fn || p[-1] == '/')) {
1206 "found \"..\" dir in relative path: %s\n",
1208 exit_cleanup(RERR_SYNTAX);
1219 static char *lastdir;
1220 static int lastdir_len;
1222 strlcpy(olddir, curr_dir, sizeof olddir);
1224 if (!push_dir(dir, 0)) {
1225 io_error |= IOERR_GENERAL;
1226 rsyserr(FERROR, errno, "push_dir %s failed",
1231 if (lastdir && strcmp(lastdir, dir) == 0) {
1232 flist_dir = lastdir;
1233 flist_dir_len = lastdir_len;
1235 flist_dir = lastdir = strdup(dir);
1236 flist_dir_len = lastdir_len = strlen(dir);
1241 memmove(fbuf, fn, len + 1);
1243 if (implied_dirs && (p=strrchr(fbuf,'/')) && p != fbuf) {
1244 /* Send the implied directories at the start of the
1245 * source spec, so we get their permissions right. */
1246 char *lp = lastpath, *slash = fbuf;
1248 /* Skip any initial directories in our path that we
1249 * have in common with lastpath. */
1250 for (fn = fbuf; *fn && *lp == *fn; lp++, fn++) {
1255 if (fn != p || (*lp && *lp != '/')) {
1256 int save_copy_links = copy_links;
1257 int save_xfer_dirs = xfer_dirs;
1258 copy_links |= copy_unsafe_links;
1260 while ((slash = strchr(slash+1, '/')) != 0) {
1262 send_file_name(f, flist, fbuf, NULL, 0);
1265 copy_links = save_copy_links;
1266 xfer_dirs = save_xfer_dirs;
1268 strlcpy(lastpath, fbuf, sizeof lastpath);
1273 if (one_file_system)
1274 filesystem_dev = st.st_dev;
1276 if (recurse || (xfer_dirs && is_dot_dir)) {
1277 struct file_struct *file;
1278 file = send_file_name(f, flist, fbuf, &st, FLAG_TOP_DIR);
1280 send_if_directory(f, flist, file, fbuf, len);
1282 send_file_name(f, flist, fbuf, &st, 0);
1287 if (!pop_dir(olddir)) {
1288 rsyserr(FERROR, errno, "pop_dir %s failed",
1289 full_fname(olddir));
1290 exit_cleanup(RERR_FILESELECT);
1295 gettimeofday(&end_tv, NULL);
1296 stats.flist_buildtime = (int64)(end_tv.tv_sec - start_tv.tv_sec) * 1000
1297 + (end_tv.tv_usec - start_tv.tv_usec) / 1000;
1298 if (stats.flist_buildtime == 0)
1299 stats.flist_buildtime = 1;
1302 send_file_entry(NULL, f);
1304 if (show_filelist_p())
1305 finish_filelist_progress(flist);
1307 gettimeofday(&end_tv, NULL);
1308 stats.flist_xfertime = (int64)(end_tv.tv_sec - start_tv.tv_sec) * 1000
1309 + (end_tv.tv_usec - start_tv.tv_usec) / 1000;
1311 if (flist->hlink_pool) {
1312 pool_destroy(flist->hlink_pool);
1313 flist->hlink_pool = NULL;
1316 /* Sort the list without removing any duplicates. This allows the
1317 * receiving side to ask for any name they like, which gives us the
1318 * flexibility to change the way we unduplicate names in the future
1319 * without causing a compatibility problem with older versions. */
1320 clean_flist(flist, 0, 0);
1324 /* send the io_error flag */
1325 write_int(f, lp_ignore_errors(module_id) ? 0 : io_error);
1328 stats.flist_size = stats.total_written - start_write;
1329 stats.num_files = flist->count;
1332 output_flist(flist);
1335 rprintf(FINFO, "send_file_list done\n");
1340 struct file_list *recv_file_list(int f)
1342 struct file_list *flist;
1343 unsigned short flags;
1346 rprintf(FLOG, "receiving file list\n");
1347 if (show_filelist_p())
1348 start_filelist_progress("receiving file list");
1350 start_read = stats.total_read;
1352 flist = flist_new(WITH_HLINK, "recv_file_list");
1355 flist->malloced = 1000;
1356 flist->files = new_array(struct file_struct *, flist->malloced);
1360 while ((flags = read_byte(f)) != 0) {
1361 struct file_struct *file;
1363 flist_expand(flist);
1365 if (protocol_version >= 28 && (flags & XMIT_EXTENDED_FLAGS))
1366 flags |= read_byte(f) << 8;
1367 file = receive_file_entry(flist, flags, f);
1369 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
1370 stats.total_size += file->length;
1372 flist->files[flist->count++] = file;
1374 maybe_emit_filelist_progress(flist->count);
1377 rprintf(FINFO, "recv_file_name(%s)\n",
1378 f_name(file, NULL));
1381 receive_file_entry(NULL, 0, 0); /* Signal that we're done. */
1384 rprintf(FINFO, "received %d names\n", flist->count);
1386 if (show_filelist_p())
1387 finish_filelist_progress(flist);
1389 clean_flist(flist, relative_paths, 1);
1392 recv_uid_list(f, flist);
1394 /* Recv the io_error flag */
1395 if (lp_ignore_errors(module_id) || ignore_errors)
1398 io_error |= read_int(f);
1402 output_flist(flist);
1406 for (i = 0; i < flist->count; i++)
1407 list_file_entry(flist->files[i]);
1411 rprintf(FINFO, "recv_file_list done\n");
1413 stats.flist_size = stats.total_read - start_read;
1414 stats.num_files = flist->count;
1419 out_of_memory("recv_file_list");
1420 return NULL; /* not reached */
1423 static int file_compare(struct file_struct **file1, struct file_struct **file2)
1425 return f_name_cmp(*file1, *file2);
1428 /* Search for an identically-named item in the file list. Note that the
1429 * items must agree in their directory-ness, or no match is returned. */
1430 int flist_find(struct file_list *flist, struct file_struct *f)
1432 int low = flist->low, high = flist->high;
1433 int diff, mid, mid_up;
1435 while (low <= high) {
1436 mid = (low + high) / 2;
1437 if (flist->files[mid]->basename)
1440 /* Scan for the next non-empty entry using the cached
1441 * distance values. If the value isn't fully up-to-
1442 * date, update it. */
1443 mid_up = mid + flist->files[mid]->dir.depth;
1444 if (!flist->files[mid_up]->basename) {
1446 mid_up += flist->files[mid_up]->dir.depth;
1447 } while (!flist->files[mid_up]->basename);
1448 flist->files[mid]->dir.depth = mid_up - mid;
1450 if (mid_up > high) {
1451 /* If there's nothing left above us, set high to
1452 * a non-empty entry below us and continue. */
1453 high = mid - flist->files[mid]->length;
1454 if (!flist->files[high]->basename) {
1456 high -= flist->files[high]->length;
1457 } while (!flist->files[high]->basename);
1458 flist->files[mid]->length = mid - high;
1463 diff = f_name_cmp(flist->files[mid_up], f);
1465 if (protocol_version < 29
1466 && S_ISDIR(flist->files[mid_up]->mode)
1467 != S_ISDIR(f->mode))
1480 * Free up any resources a file_struct has allocated
1481 * and clear the file.
1483 void clear_file(struct file_struct *file, struct file_list *flist)
1485 if (flist->hlink_pool && file->link_u.idev)
1486 pool_free(flist->hlink_pool, 0, file->link_u.idev);
1487 memset(file, 0, file_struct_len);
1488 /* In an empty entry, dir.depth is an offset to the next non-empty
1489 * entry. Likewise for length in the opposite direction. We assume
1490 * that we're alone for now since flist_find() will adjust the counts
1491 * it runs into that aren't up-to-date. */
1492 file->length = file->dir.depth = 1;
1496 * allocate a new file list
1498 struct file_list *flist_new(int with_hlink, char *msg)
1500 struct file_list *flist;
1502 flist = new(struct file_list);
1506 memset(flist, 0, sizeof (struct file_list));
1508 if (!(flist->file_pool = pool_create(FILE_EXTENT, 0,
1509 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_DEL_HERE);
1601 clear_file(flist->files[drop], flist);
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;
1650 clear_file(fp, flist);
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;
1683 clear_file(fp, flist);
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", (long)file->uid);
1712 if (preserve_gid && file->gid != GID_NONE)
1713 snprintf(gidbuf, sizeof gidbuf, " gid=%ld", (long)file->gid);
1717 snprintf(depthbuf, sizeof depthbuf, "%d", file->dir.depth);
1718 rprintf(FINFO, "[%s] i=%d %s %s%s%s%s mode=0%o len=%.0f%s%s flags=%x\n",
1719 who, i, am_sender ? NS(file->dir.root) : depthbuf,
1720 file->dirname ? file->dirname : "",
1721 file->dirname ? "/" : "", NS(file->basename),
1722 S_ISDIR(file->mode) ? "/" : "", (int)file->mode,
1723 (double)file->length, uidbuf, gidbuf, file->flags);
1727 enum fnc_state { s_DIR, s_SLASH, s_BASE, s_TRAILING };
1728 enum fnc_type { t_PATH, t_ITEM };
1730 /* Compare the names of two file_struct entities, similar to how strcmp()
1731 * would do if it were operating on the joined strings.
1733 * Some differences beginning with protocol_version 29: (1) directory names
1734 * are compared with an assumed trailing slash so that they compare in a
1735 * way that would cause them to sort immediately prior to any content they
1736 * may have; (2) a directory of any name compares after a non-directory of
1737 * any name at the same depth; (3) a directory with name "." compares prior
1738 * to anything else. These changes mean that a directory and a non-dir
1739 * with the same name will not compare as equal (protocol_version >= 29).
1741 * The dirname component can be an empty string, but the basename component
1742 * cannot (and never is in the current codebase). The basename component
1743 * may be NULL (for a removed item), in which case it is considered to be
1744 * after any existing item. */
1745 int f_name_cmp(struct file_struct *f1, struct file_struct *f2)
1748 const uchar *c1, *c2;
1749 enum fnc_state state1, state2;
1750 enum fnc_type type1, type2;
1751 enum fnc_type t_path = protocol_version >= 29 ? t_PATH : t_ITEM;
1753 if (!f1 || !f1->basename) {
1754 if (!f2 || !f2->basename)
1758 if (!f2 || !f2->basename)
1761 c1 = (uchar*)f1->dirname;
1762 c2 = (uchar*)f2->dirname;
1766 type1 = S_ISDIR(f1->mode) ? t_path : t_ITEM;
1767 c1 = (uchar*)f1->basename;
1768 if (type1 == t_PATH && *c1 == '.' && !c1[1]) {
1770 state1 = s_TRAILING;
1779 type2 = S_ISDIR(f2->mode) ? t_path : t_ITEM;
1780 c2 = (uchar*)f2->basename;
1781 if (type2 == t_PATH && *c2 == '.' && !c2[1]) {
1783 state2 = s_TRAILING;
1793 return type1 == t_PATH ? 1 : -1;
1803 type1 = S_ISDIR(f1->mode) ? t_path : t_ITEM;
1804 c1 = (uchar*)f1->basename;
1805 if (type1 == t_PATH && *c1 == '.' && !c1[1]) {
1807 state1 = s_TRAILING;
1813 state1 = s_TRAILING;
1814 if (type1 == t_PATH) {
1823 if (*c2 && type1 != type2)
1824 return type1 == t_PATH ? 1 : -1;
1833 type2 = S_ISDIR(f2->mode) ? t_path : t_ITEM;
1834 c2 = (uchar*)f2->basename;
1835 if (type2 == t_PATH && *c2 == '.' && !c2[1]) {
1837 state2 = s_TRAILING;
1843 state2 = s_TRAILING;
1844 if (type2 == t_PATH) {
1856 return type1 == t_PATH ? 1 : -1;
1858 } while ((dif = (int)*c1++ - (int)*c2++) == 0);
1863 /* Return a copy of the full filename of a flist entry, using the indicated
1864 * buffer or one of 5 static buffers if fbuf is NULL. No size-checking is
1865 * done because we checked the size when creating the file_struct entry.
1867 char *f_name(struct file_struct *f, char *fbuf)
1869 if (!f || !f->basename)
1873 static char names[5][MAXPATHLEN];
1874 static unsigned int n;
1876 n = (n + 1) % (sizeof names / sizeof names[0]);
1882 int len = strlen(f->dirname);
1883 memcpy(fbuf, f->dirname, len);
1885 strlcpy(fbuf + len + 1, f->basename, MAXPATHLEN - (len + 1));
1887 strlcpy(fbuf, f->basename, MAXPATHLEN);
1892 /* Do a non-recursive scan of the named directory, possibly ignoring all
1893 * exclude rules except for the daemon's. If "dlen" is >=0, it is the length
1894 * of the dirname string, and also indicates that "dirname" is a MAXPATHLEN
1895 * buffer (the functions we call will append names onto the end, but the old
1896 * dir value will be restored on exit). */
1897 struct file_list *get_dirlist(char *dirname, int dlen,
1898 int ignore_filter_rules)
1900 struct file_list *dirlist;
1901 char dirbuf[MAXPATHLEN];
1902 int save_recurse = recurse;
1903 int save_xfer_dirs = xfer_dirs;
1906 dlen = strlcpy(dirbuf, dirname, MAXPATHLEN);
1907 if (dlen >= MAXPATHLEN)
1912 dirlist = flist_new(WITHOUT_HLINK, "get_dirlist");
1916 send_directory(ignore_filter_rules ? -2 : -1, dirlist, dirname, dlen);
1917 xfer_dirs = save_xfer_dirs;
1918 recurse = save_recurse;
1920 flist_count_offset += dirlist->count;
1922 clean_flist(dirlist, 0, 0);
1925 output_flist(dirlist);