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 const 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_shortint(f, flags);
401 write_byte(f, flags);
404 flags |= S_ISDIR(mode) ? XMIT_LONG_NAME : XMIT_TOP_DIR;
405 write_byte(f, flags);
407 if (flags & XMIT_SAME_NAME)
409 if (flags & XMIT_LONG_NAME)
413 write_buf(f, fname + l1, l2);
415 write_longint(f, file->length);
416 if (!(flags & XMIT_SAME_TIME))
417 write_int(f, modtime);
418 if (!(flags & XMIT_SAME_MODE))
419 write_int(f, to_wire_mode(mode));
420 if (preserve_uid && !(flags & XMIT_SAME_UID)) {
425 if (preserve_gid && !(flags & XMIT_SAME_GID)) {
430 if ((preserve_devices && IS_DEVICE(mode))
431 || (preserve_specials && IS_SPECIAL(mode))) {
432 if (protocol_version < 28) {
433 if (!(flags & XMIT_SAME_RDEV_pre28))
434 write_int(f, (int)rdev);
436 if (!(flags & XMIT_SAME_RDEV_MAJOR))
437 write_int(f, major(rdev));
438 if (flags & XMIT_RDEV_MINOR_IS_SMALL)
439 write_byte(f, minor(rdev));
441 write_int(f, minor(rdev));
446 if (preserve_links && S_ISLNK(mode)) {
447 int len = strlen(file->u.link);
449 write_buf(f, file->u.link, len);
453 #ifdef SUPPORT_HARD_LINKS
454 if (file->link_u.idev) {
455 if (protocol_version < 26) {
456 /* 32-bit dev_t and ino_t */
457 write_int(f, (int32)dev);
458 write_int(f, (int32)file->F_INODE);
460 /* 64-bit dev_t and ino_t */
461 if (!(flags & XMIT_SAME_DEV))
462 write_longint(f, dev);
463 write_longint(f, file->F_INODE);
468 if (always_checksum && (S_ISREG(mode) || protocol_version < 28)) {
473 /* Prior to 28, we sent a useless set of nulls. */
476 write_buf(f, sum, checksum_len);
479 strlcpy(lastname, fname, MAXPATHLEN);
482 static struct file_struct *receive_file_entry(struct file_list *flist,
483 unsigned short flags, int f)
485 static time_t modtime;
489 static uint32 rdev_major;
492 static char lastname[MAXPATHLEN], *lastdir;
493 static int lastdir_depth, lastdir_len = -1;
494 static unsigned int del_hier_name_len = 0;
495 static int in_del_hier = 0;
496 char thisname[MAXPATHLEN];
497 unsigned int l1 = 0, l2 = 0;
498 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
500 char *basename, *dirname, *bp;
501 struct file_struct *file;
504 modtime = 0, mode = 0;
505 dev = 0, rdev = MAKEDEV(0, 0);
514 if (flags & XMIT_SAME_NAME)
517 if (flags & XMIT_LONG_NAME)
522 if (l2 >= MAXPATHLEN - l1) {
524 "overflow: flags=0x%x l1=%d l2=%d lastname=%s\n",
525 flags, l1, l2, lastname);
526 overflow_exit("receive_file_entry");
529 strlcpy(thisname, lastname, l1 + 1);
530 read_sbuf(f, &thisname[l1], l2);
531 thisname[l1 + l2] = 0;
533 strlcpy(lastname, thisname, MAXPATHLEN);
535 clean_fname(thisname, 0);
538 sanitize_path(thisname, thisname, "", 0, NULL);
540 if ((basename = strrchr(thisname, '/')) != NULL) {
541 dirname_len = ++basename - thisname; /* counts future '\0' */
542 if (lastdir_len == dirname_len - 1
543 && strncmp(thisname, lastdir, lastdir_len) == 0) {
545 dirname_len = 0; /* indicates no copy is needed */
553 basename_len = strlen(basename) + 1; /* count the '\0' */
555 file_length = read_longint(f);
556 if (!(flags & XMIT_SAME_TIME))
557 modtime = (time_t)read_int(f);
558 if (!(flags & XMIT_SAME_MODE))
559 mode = from_wire_mode(read_int(f));
561 if (chmod_modes && !S_ISLNK(mode))
562 mode = tweak_mode(mode, chmod_modes);
564 if (preserve_uid && !(flags & XMIT_SAME_UID))
565 uid = (uid_t)read_int(f);
566 if (preserve_gid && !(flags & XMIT_SAME_GID))
567 gid = (gid_t)read_int(f);
569 if ((preserve_devices && IS_DEVICE(mode))
570 || (preserve_specials && IS_SPECIAL(mode))) {
571 if (protocol_version < 28) {
572 if (!(flags & XMIT_SAME_RDEV_pre28))
573 rdev = (dev_t)read_int(f);
576 if (!(flags & XMIT_SAME_RDEV_MAJOR))
577 rdev_major = read_int(f);
578 if (flags & XMIT_RDEV_MINOR_IS_SMALL)
579 rdev_minor = read_byte(f);
581 rdev_minor = read_int(f);
582 rdev = MAKEDEV(rdev_major, rdev_minor);
584 } else if (protocol_version < 28)
585 rdev = MAKEDEV(0, 0);
588 if (preserve_links && S_ISLNK(mode)) {
589 linkname_len = read_int(f) + 1; /* count the '\0' */
590 if (linkname_len <= 0 || linkname_len > MAXPATHLEN) {
591 rprintf(FERROR, "overflow: linkname_len=%d\n",
593 overflow_exit("receive_file_entry");
600 sum_len = always_checksum && S_ISREG(mode) ? MD4_SUM_LENGTH : 0;
602 alloc_len = file_struct_len + dirname_len + basename_len
603 + linkname_len + sum_len;
604 bp = pool_alloc(flist->file_pool, alloc_len, "receive_file_entry");
606 file = (struct file_struct *)bp;
607 memset(bp, 0, file_struct_len);
608 bp += file_struct_len;
610 file->modtime = modtime;
611 file->length = file_length;
617 file->dirname = lastdir = bp;
618 lastdir_len = dirname_len - 1;
619 memcpy(bp, dirname, dirname_len - 1);
622 lastdir_depth = count_dir_elements(lastdir);
623 file->dir.depth = lastdir_depth + 1;
624 } else if (dirname) {
625 file->dirname = dirname; /* we're reusing lastname */
626 file->dir.depth = lastdir_depth + 1;
631 if (basename_len == 1+1 && *basename == '.') /* +1 for '\0' */
633 if (flags & XMIT_TOP_DIR) {
634 in_del_hier = recurse;
635 del_hier_name_len = file->dir.depth == 0 ? 0 : l1 + l2;
636 if (relative_paths && del_hier_name_len > 2
637 && lastname[del_hier_name_len-1] == '.'
638 && lastname[del_hier_name_len-2] == '/')
639 del_hier_name_len -= 2;
640 file->flags |= FLAG_TOP_DIR | FLAG_DEL_HERE;
641 } else if (in_del_hier) {
642 if (!relative_paths || !del_hier_name_len
643 || (l1 >= del_hier_name_len
644 && lastname[del_hier_name_len] == '/'))
645 file->flags |= FLAG_DEL_HERE;
652 memcpy(bp, basename, basename_len);
655 if ((preserve_devices && IS_DEVICE(mode))
656 || (preserve_specials && IS_SPECIAL(mode)))
662 read_sbuf(f, bp, linkname_len - 1);
664 sanitize_path(bp, bp, "", lastdir_depth, NULL);
669 #ifdef SUPPORT_HARD_LINKS
670 if (preserve_hard_links && protocol_version < 28 && S_ISREG(mode))
671 flags |= XMIT_HAS_IDEV_DATA;
672 if (flags & XMIT_HAS_IDEV_DATA) {
674 if (protocol_version < 26) {
678 if (!(flags & XMIT_SAME_DEV))
679 dev = read_longint(f);
680 inode = read_longint(f);
682 if (flist->hlink_pool) {
683 file->link_u.idev = pool_talloc(flist->hlink_pool,
684 struct idev, 1, "inode_table");
685 file->F_INODE = inode;
691 if (always_checksum && (sum_len || protocol_version < 28)) {
694 file->u.sum = sum = bp;
697 /* Prior to 28, we get a useless set of nulls. */
700 read_buf(f, sum, checksum_len);
707 * Create a file_struct for a named file by reading its stat()
708 * information and performing extensive checks against global
711 * @return the new file, or NULL if there was an error or this file
712 * should be excluded.
714 * @todo There is a small optimization opportunity here to avoid
715 * stat()ing the file in some circumstances, which has a certain cost.
716 * We are called immediately after doing readdir(), and so we may
717 * already know the d_type of the file. We could for example avoid
718 * statting directories if we're not recursing, but this is not a very
719 * important case. Some systems may not have d_type.
721 struct file_struct *make_file(const char *fname, struct file_list *flist,
722 STRUCT_STAT *stp, unsigned short flags,
725 static char *lastdir;
726 static int lastdir_len = -1;
727 struct file_struct *file;
729 char sum[SUM_LENGTH];
730 char thisname[MAXPATHLEN];
731 char linkname[MAXPATHLEN];
732 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
733 char *basename, *dirname, *bp;
735 if (!flist || !flist->count) /* Ignore lastdir when invalid. */
738 if (strlcpy(thisname, fname, sizeof thisname)
739 >= sizeof thisname - flist_dir_len) {
740 rprintf(FINFO, "skipping overly long name: %s\n", fname);
743 clean_fname(thisname, 0);
745 sanitize_path(thisname, thisname, "", 0, NULL);
747 memset(sum, 0, SUM_LENGTH);
749 if (stp && S_ISDIR(stp->st_mode)) {
750 st = *stp; /* Needed for "symlink/." with --relative. */
751 *linkname = '\0'; /* make IBM code checker happy */
752 } else if (readlink_stat(thisname, &st, linkname) != 0) {
753 int save_errno = errno;
754 /* See if file is excluded before reporting an error. */
755 if (filter_level != NO_FILTERS
756 && (is_excluded(thisname, 0, filter_level)
757 || is_excluded(thisname, 1, filter_level))) {
758 if (ignore_perishable && save_errno != ENOENT)
759 non_perishable_cnt++;
762 if (save_errno == ENOENT) {
764 /* Avoid "vanished" error if symlink points nowhere. */
765 if (copy_links && do_lstat(thisname, &st) == 0
766 && S_ISLNK(st.st_mode)) {
767 io_error |= IOERR_GENERAL;
768 rprintf(FERROR, "symlink has no referent: %s\n",
769 full_fname(thisname));
773 enum logcode c = am_daemon && protocol_version < 28
775 io_error |= IOERR_VANISHED;
776 rprintf(c, "file has vanished: %s\n",
777 full_fname(thisname));
780 io_error |= IOERR_GENERAL;
781 rsyserr(FERROR, save_errno, "readlink %s failed",
782 full_fname(thisname));
787 /* backup.c calls us with filter_level set to NO_FILTERS. */
788 if (filter_level == NO_FILTERS)
791 if (S_ISDIR(st.st_mode) && !xfer_dirs) {
792 rprintf(FINFO, "skipping directory %s\n", thisname);
796 /* -x only affects directories because we need to avoid recursing
797 * into a mount-point directory, not to avoid copying a symlinked
798 * file if -L (or similar) was specified. */
799 if (one_file_system && st.st_dev != filesystem_dev
800 && S_ISDIR(st.st_mode)) {
801 if (one_file_system > 1) {
803 rprintf(FINFO, "skipping mount-point dir %s\n",
808 flags |= FLAG_MOUNT_POINT;
811 if (is_excluded(thisname, S_ISDIR(st.st_mode) != 0, filter_level)) {
812 if (ignore_perishable)
813 non_perishable_cnt++;
817 if (lp_ignore_nonreadable(module_id)) {
819 if (!S_ISLNK(st.st_mode))
821 if (access(thisname, R_OK) != 0)
828 rprintf(FINFO, "[%s] make_file(%s,*,%d)\n",
829 who_am_i(), thisname, filter_level);
832 if ((basename = strrchr(thisname, '/')) != NULL) {
833 dirname_len = ++basename - thisname; /* counts future '\0' */
834 if (lastdir_len == dirname_len - 1
835 && strncmp(thisname, lastdir, lastdir_len) == 0) {
837 dirname_len = 0; /* indicates no copy is needed */
845 basename_len = strlen(basename) + 1; /* count the '\0' */
848 linkname_len = S_ISLNK(st.st_mode) ? strlen(linkname) + 1 : 0;
853 sum_len = always_checksum && am_sender && S_ISREG(st.st_mode)
854 ? MD4_SUM_LENGTH : 0;
856 alloc_len = file_struct_len + dirname_len + basename_len
857 + linkname_len + sum_len;
859 bp = pool_alloc(flist->file_pool, alloc_len, "make_file");
861 if (!(bp = new_array(char, alloc_len)))
862 out_of_memory("make_file");
865 file = (struct file_struct *)bp;
866 memset(bp, 0, file_struct_len);
867 bp += file_struct_len;
870 file->modtime = st.st_mtime;
871 file->length = st.st_size;
872 file->mode = st.st_mode;
873 file->uid = st.st_uid;
874 file->gid = st.st_gid;
876 #ifdef SUPPORT_HARD_LINKS
877 if (flist && flist->hlink_pool) {
878 if (protocol_version < 28) {
879 if (S_ISREG(st.st_mode))
880 file->link_u.idev = pool_talloc(
881 flist->hlink_pool, struct idev, 1,
884 if (!S_ISDIR(st.st_mode) && st.st_nlink > 1)
885 file->link_u.idev = pool_talloc(
886 flist->hlink_pool, struct idev, 1,
890 if (file->link_u.idev) {
891 file->F_DEV = st.st_dev;
892 file->F_INODE = st.st_ino;
897 file->dirname = lastdir = bp;
898 lastdir_len = dirname_len - 1;
899 memcpy(bp, dirname, dirname_len - 1);
903 file->dirname = dirname;
906 memcpy(bp, basename, basename_len);
909 #ifdef HAVE_STRUCT_STAT_ST_RDEV
910 if ((preserve_devices && IS_DEVICE(st.st_mode))
911 || (preserve_specials && IS_SPECIAL(st.st_mode)))
912 file->u.rdev = st.st_rdev;
918 memcpy(bp, linkname, linkname_len);
925 file_checksum(thisname, bp, st.st_size);
929 file->dir.root = flist_dir;
931 /* This code is only used by the receiver when it is building
932 * a list of files for a delete pass. */
933 if (keep_dirlinks && linkname_len && flist) {
935 int save_mode = file->mode;
936 file->mode = S_IFDIR; /* Find a directory with our name. */
937 if (flist_find(the_file_list, file) >= 0
938 && do_stat(thisname, &st2) == 0 && S_ISDIR(st2.st_mode)) {
939 file->modtime = st2.st_mtime;
940 file->length = st2.st_size;
941 file->mode = st2.st_mode;
942 file->uid = st2.st_uid;
943 file->gid = st2.st_gid;
946 file->mode = save_mode;
949 if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))
950 stats.total_size += st.st_size;
955 static struct file_struct *send_file_name(int f, struct file_list *flist,
956 char *fname, STRUCT_STAT *stp,
957 unsigned short flags)
959 struct file_struct *file;
961 file = make_file(fname, flist, stp, flags,
962 f == -2 ? SERVER_FILTERS : ALL_FILTERS);
966 if (chmod_modes && !S_ISLNK(file->mode))
967 file->mode = tweak_mode(file->mode, chmod_modes);
969 maybe_emit_filelist_progress(flist->count + flist_count_offset);
973 if (file->basename[0]) {
974 flist->files[flist->count++] = file;
975 send_file_entry(file, f);
980 static void send_if_directory(int f, struct file_list *flist,
981 struct file_struct *file,
982 char *fbuf, unsigned int ol)
984 char is_dot_dir = fbuf[ol-1] == '.' && (ol == 1 || fbuf[ol-2] == '/');
986 if (S_ISDIR(file->mode)
987 && !(file->flags & FLAG_MOUNT_POINT) && f_name(file, fbuf)) {
989 unsigned int len = strlen(fbuf);
990 if (len > 1 && fbuf[len-1] == '/')
992 if (len >= MAXPATHLEN - 1) {
993 io_error |= IOERR_GENERAL;
994 rprintf(FERROR, "skipping long-named directory: %s\n",
998 save_filters = push_local_filters(fbuf, len);
999 send_directory(f, flist, fbuf, len);
1000 pop_local_filters(save_filters);
1007 /* This function is normally called by the sender, but the receiving side also
1008 * calls it from get_dirlist() with f set to -1 so that we just construct the
1009 * file list in memory without sending it over the wire. Also, get_dirlist()
1010 * might call this with f set to -2, which also indicates that local filter
1011 * rules should be ignored. */
1012 static void send_directory(int f, struct file_list *flist,
1013 char *fbuf, int len)
1019 int start = flist->count;
1021 if (!(d = opendir(fbuf))) {
1022 io_error |= IOERR_GENERAL;
1023 rsyserr(FERROR, errno, "opendir %s failed", full_fname(fbuf));
1028 if (len != 1 || *fbuf != '/')
1031 remainder = MAXPATHLEN - (p - fbuf);
1033 for (errno = 0, di = readdir(d); di; errno = 0, di = readdir(d)) {
1034 char *dname = d_name(di);
1035 if (dname[0] == '.' && (dname[1] == '\0'
1036 || (dname[1] == '.' && dname[2] == '\0')))
1038 if (strlcpy(p, dname, remainder) >= remainder) {
1039 io_error |= IOERR_GENERAL;
1041 "cannot send long-named file %s\n",
1046 send_file_name(f, flist, fbuf, NULL, 0);
1052 io_error |= IOERR_GENERAL;
1053 rsyserr(FERROR, errno, "readdir(%s)", full_fname(fbuf));
1059 int i, end = flist->count - 1;
1060 for (i = start; i <= end; i++)
1061 send_if_directory(f, flist, flist->files[i], fbuf, len);
1065 struct file_list *send_file_list(int f, int argc, char *argv[])
1069 char *p, *dir, olddir[sizeof curr_dir];
1070 char lastpath[MAXPATHLEN] = "";
1071 struct file_list *flist;
1072 struct timeval start_tv, end_tv;
1076 rprintf(FLOG, "building file list\n");
1077 if (show_filelist_p())
1078 start_filelist_progress("building file list");
1080 start_write = stats.total_written;
1081 gettimeofday(&start_tv, NULL);
1083 flist = flist_new(WITH_HLINK, "send_file_list");
1085 io_start_buffering_out();
1086 if (filesfrom_fd >= 0) {
1087 if (argv[0] && !push_dir(argv[0], 0)) {
1088 rsyserr(FERROR, errno, "push_dir %s failed",
1089 full_fname(argv[0]));
1090 exit_cleanup(RERR_FILESELECT);
1096 char fbuf[MAXPATHLEN];
1101 if (read_filesfrom_line(filesfrom_fd, fbuf) == 0)
1103 sanitize_path(fbuf, fbuf, "", 0, NULL);
1107 strlcpy(fbuf, *argv++, MAXPATHLEN);
1109 sanitize_path(fbuf, fbuf, "", 0, NULL);
1113 if (relative_paths) {
1114 /* We clean up fbuf below. */
1116 } else if (!len || fbuf[len - 1] == '/') {
1117 if (len == 2 && fbuf[0] == '.') {
1118 /* Turn "./" into just "." rather than "./." */
1121 if (len + 1 >= MAXPATHLEN)
1122 overflow_exit("send_file_list");
1127 } else if (len > 1 && fbuf[len-1] == '.' && fbuf[len-2] == '.'
1128 && (len == 2 || fbuf[len-3] == '/')) {
1129 if (len + 2 >= MAXPATHLEN)
1130 overflow_exit("send_file_list");
1136 is_dot_dir = fbuf[len-1] == '.'
1137 && (len == 1 || fbuf[len-2] == '/');
1140 if (link_stat(fbuf, &st, copy_dirlinks) != 0) {
1141 io_error |= IOERR_GENERAL;
1142 rsyserr(FERROR, errno, "link_stat %s failed",
1147 if (S_ISDIR(st.st_mode) && !xfer_dirs) {
1148 rprintf(FINFO, "skipping directory %s\n", fbuf);
1155 if (!relative_paths) {
1156 p = strrchr(fbuf, '/');
1163 len -= p - fbuf + 1;
1168 if ((p = strstr(fbuf, "/./")) != NULL) {
1174 len -= p - fbuf + 3;
1178 /* Get rid of trailing "/" and "/.". */
1180 if (fn[len - 1] == '/') {
1182 if (!--len && !dir) {
1187 else if (len >= 2 && fn[len - 1] == '.'
1188 && fn[len - 2] == '/') {
1190 if (!(len -= 2) && !dir) {
1197 if (len == 1 && fn[0] == '/')
1200 /* Reject a ".." dir in the active part of the path. */
1201 for (p = fn; (p = strstr(p, "..")) != NULL; p += 2) {
1202 if ((p[2] == '/' || p[2] == '\0')
1203 && (p == fn || p[-1] == '/')) {
1205 "found \"..\" dir in relative path: %s\n",
1207 exit_cleanup(RERR_SYNTAX);
1218 static const char *lastdir;
1219 static int lastdir_len;
1221 strlcpy(olddir, curr_dir, sizeof olddir);
1223 if (!push_dir(dir, 0)) {
1224 io_error |= IOERR_GENERAL;
1225 rsyserr(FERROR, errno, "push_dir %s failed",
1230 if (lastdir && strcmp(lastdir, dir) == 0) {
1231 flist_dir = lastdir;
1232 flist_dir_len = lastdir_len;
1234 flist_dir = lastdir = strdup(dir);
1235 flist_dir_len = lastdir_len = strlen(dir);
1240 memmove(fbuf, fn, len + 1);
1242 if (implied_dirs && (p=strrchr(fbuf,'/')) && p != fbuf) {
1243 /* Send the implied directories at the start of the
1244 * source spec, so we get their permissions right. */
1245 char *lp = lastpath, *slash = fbuf;
1247 /* Skip any initial directories in our path that we
1248 * have in common with lastpath. */
1249 for (fn = fbuf; *fn && *lp == *fn; lp++, fn++) {
1254 if (fn != p || (*lp && *lp != '/')) {
1255 int save_copy_links = copy_links;
1256 int save_xfer_dirs = xfer_dirs;
1257 copy_links |= copy_unsafe_links;
1259 while ((slash = strchr(slash+1, '/')) != 0) {
1261 send_file_name(f, flist, fbuf, NULL, 0);
1264 copy_links = save_copy_links;
1265 xfer_dirs = save_xfer_dirs;
1267 strlcpy(lastpath, fbuf, sizeof lastpath);
1272 if (one_file_system)
1273 filesystem_dev = st.st_dev;
1275 if (recurse || (xfer_dirs && is_dot_dir)) {
1276 struct file_struct *file;
1277 file = send_file_name(f, flist, fbuf, &st, FLAG_TOP_DIR);
1279 send_if_directory(f, flist, file, fbuf, len);
1281 send_file_name(f, flist, fbuf, &st, 0);
1286 if (!pop_dir(olddir)) {
1287 rsyserr(FERROR, errno, "pop_dir %s failed",
1288 full_fname(olddir));
1289 exit_cleanup(RERR_FILESELECT);
1294 gettimeofday(&end_tv, NULL);
1295 stats.flist_buildtime = (int64)(end_tv.tv_sec - start_tv.tv_sec) * 1000
1296 + (end_tv.tv_usec - start_tv.tv_usec) / 1000;
1297 if (stats.flist_buildtime == 0)
1298 stats.flist_buildtime = 1;
1301 send_file_entry(NULL, f);
1303 if (show_filelist_p())
1304 finish_filelist_progress(flist);
1306 gettimeofday(&end_tv, NULL);
1307 stats.flist_xfertime = (int64)(end_tv.tv_sec - start_tv.tv_sec) * 1000
1308 + (end_tv.tv_usec - start_tv.tv_usec) / 1000;
1310 if (flist->hlink_pool) {
1311 pool_destroy(flist->hlink_pool);
1312 flist->hlink_pool = NULL;
1315 /* Sort the list without removing any duplicates. This allows the
1316 * receiving side to ask for any name they like, which gives us the
1317 * flexibility to change the way we unduplicate names in the future
1318 * without causing a compatibility problem with older versions. */
1319 clean_flist(flist, 0, 0);
1323 /* send the io_error flag */
1324 write_int(f, lp_ignore_errors(module_id) ? 0 : io_error);
1327 stats.flist_size = stats.total_written - start_write;
1328 stats.num_files = flist->count;
1331 output_flist(flist);
1334 rprintf(FINFO, "send_file_list done\n");
1339 struct file_list *recv_file_list(int f)
1341 struct file_list *flist;
1342 unsigned short flags;
1345 rprintf(FLOG, "receiving file list\n");
1346 if (show_filelist_p())
1347 start_filelist_progress("receiving file list");
1349 start_read = stats.total_read;
1351 flist = flist_new(WITH_HLINK, "recv_file_list");
1354 flist->malloced = 1000;
1355 flist->files = new_array(struct file_struct *, flist->malloced);
1359 while ((flags = read_byte(f)) != 0) {
1360 struct file_struct *file;
1362 flist_expand(flist);
1364 if (protocol_version >= 28 && (flags & XMIT_EXTENDED_FLAGS))
1365 flags |= read_byte(f) << 8;
1366 file = receive_file_entry(flist, flags, f);
1368 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
1369 stats.total_size += file->length;
1371 flist->files[flist->count++] = file;
1373 maybe_emit_filelist_progress(flist->count);
1376 rprintf(FINFO, "recv_file_name(%s)\n",
1377 f_name(file, NULL));
1380 receive_file_entry(NULL, 0, 0); /* Signal that we're done. */
1383 rprintf(FINFO, "received %d names\n", flist->count);
1385 if (show_filelist_p())
1386 finish_filelist_progress(flist);
1388 clean_flist(flist, relative_paths, 1);
1391 recv_uid_list(f, flist);
1393 /* Recv the io_error flag */
1394 if (lp_ignore_errors(module_id) || ignore_errors)
1397 io_error |= read_int(f);
1401 output_flist(flist);
1405 for (i = 0; i < flist->count; i++)
1406 list_file_entry(flist->files[i]);
1410 rprintf(FINFO, "recv_file_list done\n");
1412 stats.flist_size = stats.total_read - start_read;
1413 stats.num_files = flist->count;
1418 out_of_memory("recv_file_list");
1419 return NULL; /* not reached */
1422 static int file_compare(struct file_struct **file1, struct file_struct **file2)
1424 return f_name_cmp(*file1, *file2);
1427 /* Search for an identically-named item in the file list. Note that the
1428 * items must agree in their directory-ness, or no match is returned. */
1429 int flist_find(struct file_list *flist, struct file_struct *f)
1431 int low = flist->low, high = flist->high;
1432 int diff, mid, mid_up;
1434 while (low <= high) {
1435 mid = (low + high) / 2;
1436 if (flist->files[mid]->basename)
1439 /* Scan for the next non-empty entry using the cached
1440 * distance values. If the value isn't fully up-to-
1441 * date, update it. */
1442 mid_up = mid + flist->files[mid]->dir.depth;
1443 if (!flist->files[mid_up]->basename) {
1445 mid_up += flist->files[mid_up]->dir.depth;
1446 } while (!flist->files[mid_up]->basename);
1447 flist->files[mid]->dir.depth = mid_up - mid;
1449 if (mid_up > high) {
1450 /* If there's nothing left above us, set high to
1451 * a non-empty entry below us and continue. */
1452 high = mid - (int)flist->files[mid]->length;
1453 if (!flist->files[high]->basename) {
1455 high -= (int)flist->files[high]->length;
1456 } while (!flist->files[high]->basename);
1457 flist->files[mid]->length = mid - high;
1462 diff = f_name_cmp(flist->files[mid_up], f);
1464 if (protocol_version < 29
1465 && S_ISDIR(flist->files[mid_up]->mode)
1466 != S_ISDIR(f->mode))
1479 * Free up any resources a file_struct has allocated
1480 * and clear the file.
1482 void clear_file(struct file_struct *file, struct file_list *flist)
1484 if (flist->hlink_pool && file->link_u.idev)
1485 pool_free(flist->hlink_pool, 0, file->link_u.idev);
1486 memset(file, 0, file_struct_len);
1487 /* In an empty entry, dir.depth is an offset to the next non-empty
1488 * entry. Likewise for length in the opposite direction. We assume
1489 * that we're alone for now since flist_find() will adjust the counts
1490 * it runs into that aren't up-to-date. */
1491 file->length = file->dir.depth = 1;
1495 * allocate a new file list
1497 struct file_list *flist_new(int with_hlink, char *msg)
1499 struct file_list *flist;
1501 flist = new(struct file_list);
1505 memset(flist, 0, sizeof (struct file_list));
1507 if (!(flist->file_pool = pool_create(FILE_EXTENT, 0, out_of_memory, POOL_INTERN)))
1510 #ifdef SUPPORT_HARD_LINKS
1511 if (with_hlink && preserve_hard_links) {
1512 if (!(flist->hlink_pool = pool_create(HLINK_EXTENT,
1513 sizeof (struct idev), out_of_memory, POOL_INTERN)))
1522 * free up all elements in a flist
1524 void flist_free(struct file_list *flist)
1526 pool_destroy(flist->file_pool);
1527 pool_destroy(flist->hlink_pool);
1533 * This routine ensures we don't have any duplicate names in our file list.
1534 * duplicate names can cause corruption because of the pipelining
1536 static void clean_flist(struct file_list *flist, int strip_root, int no_dups)
1538 char fbuf[MAXPATHLEN];
1543 if (flist->count == 0) {
1548 qsort(flist->files, flist->count,
1549 sizeof flist->files[0], (int (*)())file_compare);
1551 for (i = no_dups? 0 : flist->count; i < flist->count; i++) {
1552 if (flist->files[i]->basename) {
1557 flist->low = prev_i;
1558 while (++i < flist->count) {
1560 struct file_struct *file = flist->files[i];
1562 if (!file->basename)
1564 if (f_name_cmp(file, flist->files[prev_i]) == 0)
1566 else if (protocol_version >= 29 && S_ISDIR(file->mode)) {
1567 int save_mode = file->mode;
1568 /* Make sure that this directory doesn't duplicate a
1569 * non-directory earlier in the list. */
1570 flist->high = prev_i;
1571 file->mode = S_IFREG;
1572 j = flist_find(flist, file);
1573 file->mode = save_mode;
1577 struct file_struct *fp = flist->files[j];
1579 /* If one is a dir and the other is not, we want to
1580 * keep the dir because it might have contents in the
1582 if (S_ISDIR(file->mode) != S_ISDIR(fp->mode)) {
1583 if (S_ISDIR(file->mode))
1589 if (verbose > 1 && !am_server) {
1591 "removing duplicate name %s from file list (%d)\n",
1592 f_name(file, fbuf), drop);
1594 /* Make sure we don't lose track of a user-specified
1596 flist->files[keep]->flags |= flist->files[drop]->flags
1597 & (FLAG_TOP_DIR|FLAG_DEL_HERE);
1599 clear_file(flist->files[drop], flist);
1602 if (flist->low == drop) {
1604 j < i && !flist->files[j]->basename;
1613 flist->high = no_dups ? prev_i : flist->count - 1;
1616 /* We need to strip off the leading slashes for relative
1617 * paths, but this must be done _after_ the sorting phase. */
1618 for (i = flist->low; i <= flist->high; i++) {
1619 struct file_struct *file = flist->files[i];
1623 while (*file->dirname == '/')
1625 if (!*file->dirname)
1626 file->dirname = NULL;
1630 if (prune_empty_dirs && no_dups) {
1631 int j, prev_depth = 0;
1633 prev_i = 0; /* It's OK that this isn't really true. */
1635 for (i = flist->low; i <= flist->high; i++) {
1636 struct file_struct *fp, *file = flist->files[i];
1638 /* This temporarily abuses the dir.depth value for a
1639 * directory that is in a chain that might get pruned.
1640 * We restore the old value if it gets a reprieve. */
1641 if (S_ISDIR(file->mode) && file->dir.depth) {
1642 /* Dump empty dirs when coming back down. */
1643 for (j = prev_depth; j >= file->dir.depth; j--) {
1644 fp = flist->files[prev_i];
1645 if (fp->dir.depth >= 0)
1647 prev_i = -fp->dir.depth-1;
1648 clear_file(fp, flist);
1650 prev_depth = file->dir.depth;
1651 if (is_excluded(f_name(file, fbuf), 1,
1653 /* Keep dirs through this dir. */
1654 for (j = prev_depth-1; ; j--) {
1655 fp = flist->files[prev_i];
1656 if (fp->dir.depth >= 0)
1658 prev_i = -fp->dir.depth-1;
1662 file->dir.depth = -prev_i-1;
1665 /* Keep dirs through this non-dir. */
1666 for (j = prev_depth; ; j--) {
1667 fp = flist->files[prev_i];
1668 if (fp->dir.depth >= 0)
1670 prev_i = -fp->dir.depth-1;
1675 /* Dump empty all remaining empty dirs. */
1677 struct file_struct *fp = flist->files[prev_i];
1678 if (fp->dir.depth >= 0)
1680 prev_i = -fp->dir.depth-1;
1681 clear_file(fp, flist);
1684 for (i = flist->low; i <= flist->high; i++) {
1685 if (flist->files[i]->basename)
1689 for (i = flist->high; i >= flist->low; i--) {
1690 if (flist->files[i]->basename)
1697 static void output_flist(struct file_list *flist)
1699 char uidbuf[16], gidbuf[16], depthbuf[16];
1700 struct file_struct *file;
1701 const char *who = who_am_i();
1704 for (i = 0; i < flist->count; i++) {
1705 file = flist->files[i];
1706 if ((am_root || am_sender) && preserve_uid)
1707 snprintf(uidbuf, sizeof uidbuf, " uid=%ld", (long)file->uid);
1710 if (preserve_gid && file->gid != GID_NONE)
1711 snprintf(gidbuf, sizeof gidbuf, " gid=%ld", (long)file->gid);
1715 snprintf(depthbuf, sizeof depthbuf, "%d", file->dir.depth);
1716 rprintf(FINFO, "[%s] i=%d %s %s%s%s%s mode=0%o len=%.0f%s%s flags=%x\n",
1717 who, i, am_sender ? NS(file->dir.root) : depthbuf,
1718 file->dirname ? file->dirname : "",
1719 file->dirname ? "/" : "", NS(file->basename),
1720 S_ISDIR(file->mode) ? "/" : "", (int)file->mode,
1721 (double)file->length, uidbuf, gidbuf, file->flags);
1725 enum fnc_state { s_DIR, s_SLASH, s_BASE, s_TRAILING };
1726 enum fnc_type { t_PATH, t_ITEM };
1728 /* Compare the names of two file_struct entities, similar to how strcmp()
1729 * would do if it were operating on the joined strings.
1731 * Some differences beginning with protocol_version 29: (1) directory names
1732 * are compared with an assumed trailing slash so that they compare in a
1733 * way that would cause them to sort immediately prior to any content they
1734 * may have; (2) a directory of any name compares after a non-directory of
1735 * any name at the same depth; (3) a directory with name "." compares prior
1736 * to anything else. These changes mean that a directory and a non-dir
1737 * with the same name will not compare as equal (protocol_version >= 29).
1739 * The dirname component can be an empty string, but the basename component
1740 * cannot (and never is in the current codebase). The basename component
1741 * may be NULL (for a removed item), in which case it is considered to be
1742 * after any existing item. */
1743 int f_name_cmp(struct file_struct *f1, struct file_struct *f2)
1746 const uchar *c1, *c2;
1747 enum fnc_state state1, state2;
1748 enum fnc_type type1, type2;
1749 enum fnc_type t_path = protocol_version >= 29 ? t_PATH : t_ITEM;
1751 if (!f1 || !f1->basename) {
1752 if (!f2 || !f2->basename)
1756 if (!f2 || !f2->basename)
1759 c1 = (uchar*)f1->dirname;
1760 c2 = (uchar*)f2->dirname;
1764 type1 = S_ISDIR(f1->mode) ? t_path : t_ITEM;
1765 c1 = (uchar*)f1->basename;
1766 if (type1 == t_PATH && *c1 == '.' && !c1[1]) {
1768 state1 = s_TRAILING;
1777 type2 = S_ISDIR(f2->mode) ? t_path : t_ITEM;
1778 c2 = (uchar*)f2->basename;
1779 if (type2 == t_PATH && *c2 == '.' && !c2[1]) {
1781 state2 = s_TRAILING;
1791 return type1 == t_PATH ? 1 : -1;
1801 type1 = S_ISDIR(f1->mode) ? t_path : t_ITEM;
1802 c1 = (uchar*)f1->basename;
1803 if (type1 == t_PATH && *c1 == '.' && !c1[1]) {
1805 state1 = s_TRAILING;
1811 state1 = s_TRAILING;
1812 if (type1 == t_PATH) {
1821 if (*c2 && type1 != type2)
1822 return type1 == t_PATH ? 1 : -1;
1831 type2 = S_ISDIR(f2->mode) ? t_path : t_ITEM;
1832 c2 = (uchar*)f2->basename;
1833 if (type2 == t_PATH && *c2 == '.' && !c2[1]) {
1835 state2 = s_TRAILING;
1841 state2 = s_TRAILING;
1842 if (type2 == t_PATH) {
1854 return type1 == t_PATH ? 1 : -1;
1856 } while ((dif = (int)*c1++ - (int)*c2++) == 0);
1861 /* Return a copy of the full filename of a flist entry, using the indicated
1862 * buffer or one of 5 static buffers if fbuf is NULL. No size-checking is
1863 * done because we checked the size when creating the file_struct entry.
1865 char *f_name(struct file_struct *f, char *fbuf)
1867 if (!f || !f->basename)
1871 static char names[5][MAXPATHLEN];
1872 static unsigned int n;
1874 n = (n + 1) % (sizeof names / sizeof names[0]);
1880 int len = strlen(f->dirname);
1881 memcpy(fbuf, f->dirname, len);
1883 strlcpy(fbuf + len + 1, f->basename, MAXPATHLEN - (len + 1));
1885 strlcpy(fbuf, f->basename, MAXPATHLEN);
1890 /* Do a non-recursive scan of the named directory, possibly ignoring all
1891 * exclude rules except for the daemon's. If "dlen" is >=0, it is the length
1892 * of the dirname string, and also indicates that "dirname" is a MAXPATHLEN
1893 * buffer (the functions we call will append names onto the end, but the old
1894 * dir value will be restored on exit). */
1895 struct file_list *get_dirlist(char *dirname, int dlen,
1896 int ignore_filter_rules)
1898 struct file_list *dirlist;
1899 char dirbuf[MAXPATHLEN];
1900 int save_recurse = recurse;
1901 int save_xfer_dirs = xfer_dirs;
1904 dlen = strlcpy(dirbuf, dirname, MAXPATHLEN);
1905 if (dlen >= MAXPATHLEN)
1910 dirlist = flist_new(WITHOUT_HLINK, "get_dirlist");
1914 send_directory(ignore_filter_rules ? -2 : -1, dirlist, dirname, dlen);
1915 xfer_dirs = save_xfer_dirs;
1916 recurse = save_recurse;
1918 flist_count_offset += dirlist->count;
1920 clean_flist(dirlist, 0, 0);
1923 output_flist(dirlist);