2 Copyright (C) Andrew Tridgell 1996
3 Copyright (C) Paul Mackerras 1996
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /* generate and receive file lists */
24 extern struct stats stats;
28 extern int always_checksum;
30 extern int cvs_exclude;
34 extern int one_file_system;
35 extern int make_backups;
36 extern int preserve_links;
37 extern int preserve_hard_links;
38 extern int preserve_perms;
39 extern int preserve_devices;
40 extern int preserve_uid;
41 extern int preserve_gid;
42 extern int preserve_times;
43 extern int relative_paths;
44 extern int copy_links;
45 extern int copy_unsafe_links;
46 extern int remote_version;
48 extern int sanitize_paths;
50 static char topsrcname[MAXPATHLEN];
52 static struct exclude_struct **local_exclude_list;
54 static struct file_struct null_file;
56 static void clean_flist(struct file_list *flist, int strip_root);
58 static struct string_area *string_area_new(int size)
60 struct string_area *a;
62 if (size <= 0) size = ARENA_SIZE;
63 a = malloc(sizeof(*a));
64 if (!a) out_of_memory("string_area_new");
65 a->current = a->base = malloc(size);
66 if (!a->current) out_of_memory("string_area_new buffer");
67 a->end = a->base + size;
73 static void string_area_free(struct string_area *a)
75 struct string_area *next;
77 for ( ; a ; a = next) {
83 static char *string_area_malloc(struct string_area **ap, int size)
86 struct string_area *a;
88 /* does the request fit into the current space? */
90 if (a->current + size >= a->end) {
91 /* no; get space, move new string_area to front of the list */
92 a = string_area_new(size > ARENA_SIZE ? size : ARENA_SIZE);
97 /* have space; do the "allocation." */
103 static char *string_area_strdup(struct string_area **ap, const char *src)
105 char* dest = string_area_malloc(ap, strlen(src) + 1);
106 return strcpy(dest, src);
109 static void list_file_entry(struct file_struct *f)
111 char perms[11] = "----------";
112 char *perm_map = "rwxrwxrwx";
116 /* this can happen if duplicate names were removed */
120 if (f->mode & (1<<i)) perms[9-i] = perm_map[8-i];
122 if (S_ISLNK(f->mode)) perms[0] = 'l';
123 if (S_ISDIR(f->mode)) perms[0] = 'd';
124 if (S_ISBLK(f->mode)) perms[0] = 'b';
125 if (S_ISCHR(f->mode)) perms[0] = 'c';
126 if (S_ISSOCK(f->mode)) perms[0] = 's';
127 if (S_ISFIFO(f->mode)) perms[0] = 'p';
129 if (preserve_links && S_ISLNK(f->mode)) {
130 rprintf(FINFO,"%s %11.0f %s %s -> %s\n",
132 (double)f->length, timestring(f->modtime),
135 rprintf(FINFO,"%s %11.0f %s %s\n",
137 (double)f->length, timestring(f->modtime), f_name(f));
142 int readlink_stat(const char *Path, STRUCT_STAT *Buffer, char *Linkbuf)
146 return do_stat(Path, Buffer);
148 if (do_lstat(Path, Buffer) == -1) {
151 if (S_ISLNK(Buffer->st_mode)) {
152 if (readlink((char *) Path, Linkbuf, MAXPATHLEN-1) == -1) {
156 if (copy_unsafe_links && (topsrcname[0] != '\0') &&
157 unsafe_symlink(Linkbuf, topsrcname)) {
158 return do_stat(Path, Buffer);
163 return do_stat(Path, Buffer);
167 int link_stat(const char *Path, STRUCT_STAT *Buffer)
171 return do_stat(Path, Buffer);
173 return do_lstat(Path, Buffer);
176 return do_stat(Path, Buffer);
181 This function is used to check if a file should be included/excluded
182 from the list of files based on its name and type etc
184 static int match_file_name(char *fname,STRUCT_STAT *st)
186 if (check_exclude(fname,local_exclude_list,st)) {
192 /* used by the one_file_system code */
193 static dev_t filesystem_dev;
195 static void set_filesystem(char *fname)
198 if (link_stat(fname,&st) != 0) return;
199 filesystem_dev = st.st_dev;
203 static int to_wire_mode(mode_t mode)
205 if (S_ISLNK(mode) && (_S_IFLNK != 0120000)) {
206 return (mode & ~(_S_IFMT)) | 0120000;
211 static mode_t from_wire_mode(int mode)
213 if ((mode & (_S_IFMT)) == 0120000 && (_S_IFLNK != 0120000)) {
214 return (mode & ~(_S_IFMT)) | _S_IFLNK;
220 static void send_directory(int f,struct file_list *flist,char *dir);
222 static char *flist_dir;
225 static void send_file_entry(struct file_struct *file,int f,unsigned base_flags)
228 static time_t last_time;
229 static mode_t last_mode;
230 static dev_t last_rdev;
231 static uid_t last_uid;
232 static gid_t last_gid;
233 static char lastname[MAXPATHLEN];
244 fname = f_name(file);
248 if (file->mode == last_mode) flags |= SAME_MODE;
249 if (file->rdev == last_rdev) flags |= SAME_RDEV;
250 if (file->uid == last_uid) flags |= SAME_UID;
251 if (file->gid == last_gid) flags |= SAME_GID;
252 if (file->modtime == last_time) flags |= SAME_TIME;
254 for (l1=0;lastname[l1] && (fname[l1] == lastname[l1]) && (l1 < 255);l1++) ;
255 l2 = strlen(fname) - l1;
257 if (l1 > 0) flags |= SAME_NAME;
258 if (l2 > 255) flags |= LONG_NAME;
260 /* we must make sure we don't send a zero flags byte or the other
261 end will terminate the flist transfer */
262 if (flags == 0 && !S_ISDIR(file->mode)) flags |= FLAG_DELETE;
263 if (flags == 0) flags |= LONG_NAME;
266 if (flags & SAME_NAME)
268 if (flags & LONG_NAME)
272 write_buf(f,fname+l1,l2);
274 write_longint(f,file->length);
275 if (!(flags & SAME_TIME))
276 write_int(f,(int)file->modtime);
277 if (!(flags & SAME_MODE))
278 write_int(f,to_wire_mode(file->mode));
279 if (preserve_uid && !(flags & SAME_UID)) {
281 write_int(f,(int)file->uid);
283 if (preserve_gid && !(flags & SAME_GID)) {
285 write_int(f,(int)file->gid);
287 if (preserve_devices && IS_DEVICE(file->mode) && !(flags & SAME_RDEV))
288 write_int(f,(int)file->rdev);
291 if (preserve_links && S_ISLNK(file->mode)) {
292 write_int(f,strlen(file->link));
293 write_buf(f,file->link,strlen(file->link));
297 #if SUPPORT_HARD_LINKS
298 if (preserve_hard_links && S_ISREG(file->mode)) {
299 write_int(f,(int)file->dev);
300 write_int(f,(int)file->inode);
304 if (always_checksum) {
305 if (remote_version < 21) {
306 write_buf(f,file->sum,2);
308 write_buf(f,file->sum,MD4_SUM_LENGTH);
312 last_mode = file->mode;
313 last_rdev = file->rdev;
314 last_uid = file->uid;
315 last_gid = file->gid;
316 last_time = file->modtime;
318 strlcpy(lastname,fname,MAXPATHLEN);
319 lastname[MAXPATHLEN-1] = 0;
324 static void receive_file_entry(struct file_struct **fptr,
325 unsigned flags,int f)
327 static time_t last_time;
328 static mode_t last_mode;
329 static dev_t last_rdev;
330 static uid_t last_uid;
331 static gid_t last_gid;
332 static char lastname[MAXPATHLEN];
333 char thisname[MAXPATHLEN];
336 struct file_struct *file;
338 if (flags & SAME_NAME)
341 if (flags & LONG_NAME)
346 file = (struct file_struct *)malloc(sizeof(*file));
347 if (!file) out_of_memory("receive_file_entry");
348 memset((char *)file, 0, sizeof(*file));
351 if (l2 >= MAXPATHLEN-l1) {
352 rprintf(FERROR,"overflow: flags=0x%x l1=%d l2=%d lastname=%s\n",
353 flags, l1, l2, lastname);
354 overflow("receive_file_entry");
357 strlcpy(thisname,lastname,l1+1);
358 read_sbuf(f,&thisname[l1],l2);
361 strlcpy(lastname,thisname,MAXPATHLEN);
362 lastname[MAXPATHLEN-1] = 0;
364 clean_fname(thisname);
366 if (sanitize_paths) {
367 sanitize_path(thisname, NULL);
370 if ((p = strrchr(thisname,'/'))) {
371 static char *lastdir;
373 if (lastdir && strcmp(thisname, lastdir)==0) {
374 file->dirname = lastdir;
376 file->dirname = strdup(thisname);
377 lastdir = file->dirname;
379 file->basename = strdup(p+1);
381 file->dirname = NULL;
382 file->basename = strdup(thisname);
385 if (!file->basename) out_of_memory("receive_file_entry 1");
389 file->length = read_longint(f);
390 file->modtime = (flags & SAME_TIME) ? last_time : (time_t)read_int(f);
391 file->mode = (flags & SAME_MODE) ? last_mode : from_wire_mode(read_int(f));
393 file->uid = (flags & SAME_UID) ? last_uid : (uid_t)read_int(f);
395 file->gid = (flags & SAME_GID) ? last_gid : (gid_t)read_int(f);
396 if (preserve_devices && IS_DEVICE(file->mode))
397 file->rdev = (flags & SAME_RDEV) ? last_rdev : (dev_t)read_int(f);
399 if (preserve_links && S_ISLNK(file->mode)) {
401 file->link = (char *)malloc(l+1);
402 if (!file->link) out_of_memory("receive_file_entry 2");
403 read_sbuf(f,file->link,l);
404 if (sanitize_paths) {
405 sanitize_path(file->link, file->dirname);
409 #if SUPPORT_HARD_LINKS
410 if (preserve_hard_links && S_ISREG(file->mode)) {
411 file->dev = read_int(f);
412 file->inode = read_int(f);
416 if (always_checksum) {
417 file->sum = (char *)malloc(MD4_SUM_LENGTH);
418 if (!file->sum) out_of_memory("md4 sum");
419 if (remote_version < 21) {
420 read_buf(f,file->sum,2);
422 read_buf(f,file->sum,MD4_SUM_LENGTH);
426 last_mode = file->mode;
427 last_rdev = file->rdev;
428 last_uid = file->uid;
429 last_gid = file->gid;
430 last_time = file->modtime;
432 if (!preserve_perms) {
433 extern int orig_umask;
434 /* set an appropriate set of permissions based on original
435 permissions and umask. This emulates what GNU cp does */
436 file->mode &= ~orig_umask;
441 /* determine if a file in a different filesstem should be skipped
442 when one_file_system is set. We bascally only want to include
443 the mount points - but they can be hard to find! */
444 static int skip_filesystem(char *fname, STRUCT_STAT *st)
447 char *p = strrchr(fname, '/');
449 /* skip all but directories */
450 if (!S_ISDIR(st->st_mode)) return 1;
452 /* if its not a subdirectory then allow */
456 if (link_stat(fname, &st2)) {
462 return (st2.st_dev != filesystem_dev);
465 #define STRDUP(ap, p) (ap ? string_area_strdup(ap, p) : strdup(p))
466 #define MALLOC(ap, i) (ap ? string_area_malloc(ap, i) : malloc(i))
468 /* create a file_struct for a named file */
469 struct file_struct *make_file(int f, char *fname, struct string_area **ap,
472 struct file_struct *file;
474 char sum[SUM_LENGTH];
476 char cleaned_name[MAXPATHLEN];
477 char linkbuf[MAXPATHLEN];
478 extern int delete_excluded;
479 extern int module_id;
481 strlcpy(cleaned_name, fname, MAXPATHLEN);
482 cleaned_name[MAXPATHLEN-1] = 0;
483 clean_fname(cleaned_name);
484 if (sanitize_paths) {
485 sanitize_path(cleaned_name, NULL);
487 fname = cleaned_name;
489 memset(sum,0,SUM_LENGTH);
491 if (readlink_stat(fname,&st,linkbuf) != 0) {
493 rprintf(FERROR,"readlink %s: %s\n",
494 fname,strerror(errno));
498 /* we use noexcludes from backup.c */
499 if (noexcludes) goto skip_excludes;
501 if (S_ISDIR(st.st_mode) && !recurse) {
502 rprintf(FINFO,"skipping directory %s\n",fname);
506 if (one_file_system && st.st_dev != filesystem_dev) {
507 if (skip_filesystem(fname, &st))
511 /* f is set to -1 when calculating deletion file list */
512 if (((f != -1) || !delete_excluded) && !match_file_name(fname,&st))
516 if (lp_ignore_nonreadable(module_id) && access(fname, R_OK) != 0)
522 rprintf(FINFO,"make_file(%d,%s)\n",f,fname);
524 file = (struct file_struct *)malloc(sizeof(*file));
525 if (!file) out_of_memory("make_file");
526 memset((char *)file,0,sizeof(*file));
528 if ((p = strrchr(fname,'/'))) {
529 static char *lastdir;
531 if (lastdir && strcmp(fname, lastdir)==0) {
532 file->dirname = lastdir;
534 file->dirname = strdup(fname);
535 lastdir = file->dirname;
537 file->basename = STRDUP(ap, p+1);
540 file->dirname = NULL;
541 file->basename = STRDUP(ap, fname);
544 file->modtime = st.st_mtime;
545 file->length = st.st_size;
546 file->mode = st.st_mode;
547 file->uid = st.st_uid;
548 file->gid = st.st_gid;
549 file->dev = st.st_dev;
550 file->inode = st.st_ino;
552 file->rdev = st.st_rdev;
556 if (S_ISLNK(st.st_mode)) {
557 file->link = STRDUP(ap, linkbuf);
561 if (always_checksum) {
562 file->sum = (char *)MALLOC(ap, MD4_SUM_LENGTH);
563 if (!file->sum) out_of_memory("md4 sum");
564 /* drat. we have to provide a null checksum for non-regular
565 files in order to be compatible with earlier versions
567 if (S_ISREG(st.st_mode)) {
568 file_checksum(fname,file->sum,st.st_size);
570 memset(file->sum, 0, MD4_SUM_LENGTH);
575 static char *lastdir;
576 if (lastdir && strcmp(lastdir, flist_dir)==0) {
577 file->basedir = lastdir;
579 file->basedir = strdup(flist_dir);
580 lastdir = file->basedir;
583 file->basedir = NULL;
586 if (!S_ISDIR(st.st_mode))
587 stats.total_size += st.st_size;
594 void send_file_name(int f,struct file_list *flist,char *fname,
595 int recursive, unsigned base_flags)
597 struct file_struct *file;
599 file = make_file(f,fname, &flist->string_area, 0);
603 if (flist->count >= flist->malloced) {
604 if (flist->malloced < 1000)
605 flist->malloced += 1000;
607 flist->malloced *= 2;
608 flist->files = (struct file_struct **)realloc(flist->files,
609 sizeof(flist->files[0])*
612 out_of_memory("send_file_name");
615 if (strcmp(file->basename,"")) {
616 flist->files[flist->count++] = file;
617 send_file_entry(file,f,base_flags);
620 if (S_ISDIR(file->mode) && recursive) {
621 struct exclude_struct **last_exclude_list = local_exclude_list;
622 send_directory(f,flist,f_name(file));
623 local_exclude_list = last_exclude_list;
630 static void send_directory(int f,struct file_list *flist,char *dir)
634 char fname[MAXPATHLEN];
641 rprintf(FERROR,"opendir(%s): %s\n",
642 dir,strerror(errno));
646 strlcpy(fname,dir,MAXPATHLEN);
648 if (fname[l-1] != '/') {
649 if (l == MAXPATHLEN-1) {
651 rprintf(FERROR,"skipping long-named directory %s\n",fname);
655 strlcat(fname,"/", MAXPATHLEN);
658 p = fname + strlen(fname);
660 local_exclude_list = NULL;
663 if (strlen(fname) + strlen(".cvsignore") <= MAXPATHLEN-1) {
664 strcpy(p,".cvsignore");
665 local_exclude_list = make_exclude_list(fname,NULL,0,0);
668 rprintf(FINFO,"cannot cvs-exclude in long-named directory %s\n",fname);
672 for (di=readdir(d); di; di=readdir(d)) {
673 char *dname = d_name(di);
674 if (strcmp(dname,".")==0 ||
675 strcmp(dname,"..")==0)
677 strlcpy(p,dname,MAXPATHLEN-l);
678 send_file_name(f,flist,fname,recurse,0);
681 if (local_exclude_list) {
682 add_exclude_list("!", &local_exclude_list, 0);
689 struct file_list *send_file_list(int f,int argc,char *argv[])
693 char *p,*dir,*olddir;
694 char lastpath[MAXPATHLEN]="";
695 struct file_list *flist;
698 if (verbose && recurse && !am_server && f != -1) {
699 rprintf(FINFO,"building file list ... ");
701 rprintf(FINFO, "\n");
705 start_write = stats.total_written;
710 io_start_buffering(f);
713 for (i=0;i<argc;i++) {
714 char *fname = topsrcname;
716 strlcpy(fname,argv[i],MAXPATHLEN);
719 if (l != 1 && fname[l-1] == '/') {
720 if ((l == 2) && (fname[0] == '.')) {
721 /* Turn ./ into just . rather than ./.
722 This was put in to avoid a problem with
723 rsync -aR --delete from ./
724 The send_file_name() below of ./ was
725 mysteriously preventing deletes */
728 strlcat(fname,".",MAXPATHLEN);
732 if (link_stat(fname,&st) != 0) {
735 rprintf(FERROR,"link_stat %s : %s\n",fname,strerror(errno));
740 if (S_ISDIR(st.st_mode) && !recurse) {
741 rprintf(FINFO,"skipping directory %s\n",fname);
748 if (!relative_paths) {
749 p = strrchr(fname,'/');
758 } else if (f != -1 && (p=strrchr(fname,'/'))) {
759 /* this ensures we send the intermediate directories,
760 thus getting their permissions right */
762 if (strcmp(lastpath,fname)) {
763 strlcpy(lastpath, fname, sizeof(lastpath));
765 for (p=fname+1; (p=strchr(p,'/')); p++) {
766 int copy_links_saved = copy_links;
767 int recurse_saved = recurse;
769 copy_links = copy_unsafe_links;
770 /* set recurse to 1 to prevent make_file
771 from ignoring directory, but still
772 turn off the recursive parameter to
775 send_file_name(f, flist, fname, 0, 0);
776 copy_links = copy_links_saved;
777 recurse = recurse_saved;
789 olddir = push_dir(dir, 1);
793 rprintf(FERROR,"push_dir %s : %s\n",
794 dir,strerror(errno));
802 set_filesystem(fname);
804 send_file_name(f,flist,fname,recurse,FLAG_DELETE);
806 if (olddir != NULL) {
808 if (pop_dir(olddir) != 0) {
809 rprintf(FERROR,"pop_dir %s : %s\n",
810 dir,strerror(errno));
811 exit_cleanup(RERR_FILESELECT);
816 topsrcname[0] = '\0';
819 send_file_entry(NULL,f,0);
822 if (verbose && recurse && !am_server && f != -1)
823 rprintf(FINFO,"done\n");
825 clean_flist(flist, 0);
827 /* now send the uid/gid list. This was introduced in protocol
829 if (f != -1 && remote_version >= 15) {
833 /* if protocol version is >= 17 then send the io_error flag */
834 if (f != -1 && remote_version >= 17) {
835 extern int module_id;
836 write_int(f, lp_ignore_errors(module_id)? 0 : io_error);
841 stats.flist_size = stats.total_written - start_write;
842 stats.num_files = flist->count;
846 rprintf(FINFO,"send_file_list done\n");
852 struct file_list *recv_file_list(int f)
854 struct file_list *flist;
857 extern int list_only;
859 if (verbose && recurse && !am_server) {
860 rprintf(FINFO,"receiving file list ... ");
864 start_read = stats.total_read;
866 flist = (struct file_list *)malloc(sizeof(flist[0]));
871 flist->malloced=1000;
872 flist->files = (struct file_struct **)malloc(sizeof(flist->files[0])*
878 for (flags=read_byte(f); flags; flags=read_byte(f)) {
879 int i = flist->count;
881 if (i >= flist->malloced) {
882 if (flist->malloced < 1000)
883 flist->malloced += 1000;
885 flist->malloced *= 2;
886 flist->files =(struct file_struct **)realloc(flist->files,
887 sizeof(flist->files[0])*
893 receive_file_entry(&flist->files[i],flags,f);
895 if (S_ISREG(flist->files[i]->mode))
896 stats.total_size += flist->files[i]->length;
901 rprintf(FINFO,"recv_file_name(%s)\n",f_name(flist->files[i]));
906 rprintf(FINFO,"received %d names\n",flist->count);
908 clean_flist(flist, relative_paths);
910 if (verbose && recurse && !am_server) {
911 rprintf(FINFO,"done\n");
914 /* now recv the uid/gid list. This was introduced in protocol version 15 */
915 if (f != -1 && remote_version >= 15) {
916 recv_uid_list(f, flist);
919 /* if protocol version is >= 17 then recv the io_error flag */
920 if (f != -1 && remote_version >= 17) {
921 extern int module_id;
922 extern int ignore_errors;
923 if (lp_ignore_errors(module_id) || ignore_errors) {
926 io_error |= read_int(f);
932 for (i=0;i<flist->count;i++) {
933 list_file_entry(flist->files[i]);
939 rprintf(FINFO,"recv_file_list done\n");
941 stats.flist_size = stats.total_read - start_read;
942 stats.num_files = flist->count;
947 out_of_memory("recv_file_list");
948 return NULL; /* not reached */
952 int file_compare(struct file_struct **f1,struct file_struct **f2)
954 if (!(*f1)->basename && !(*f2)->basename) return 0;
955 if (!(*f1)->basename) return -1;
956 if (!(*f2)->basename) return 1;
957 if ((*f1)->dirname == (*f2)->dirname)
958 return u_strcmp((*f1)->basename, (*f2)->basename);
959 return u_strcmp(f_name(*f1),f_name(*f2));
963 int flist_find(struct file_list *flist,struct file_struct *f)
965 int low=0,high=flist->count-1;
967 if (flist->count <= 0) return -1;
969 while (low != high) {
970 int mid = (low+high)/2;
971 int ret = file_compare(&flist->files[flist_up(flist, mid)],&f);
972 if (ret == 0) return flist_up(flist, mid);
980 if (file_compare(&flist->files[flist_up(flist,low)],&f) == 0)
981 return flist_up(flist,low);
989 void free_file(struct file_struct *file)
992 if (file->basename) free(file->basename);
993 if (file->link) free(file->link);
994 if (file->sum) free(file->sum);
1000 * allocate a new file list
1002 struct file_list *flist_new()
1004 struct file_list *flist;
1006 flist = (struct file_list *)malloc(sizeof(flist[0]));
1007 if (!flist) out_of_memory("send_file_list");
1010 flist->malloced = 1000;
1011 flist->files = (struct file_struct **)malloc(sizeof(flist->files[0])*
1013 if (!flist->files) out_of_memory("send_file_list");
1015 flist->string_area = string_area_new(0);
1017 flist->string_area = NULL;
1022 * free up all elements in a flist
1024 void flist_free(struct file_list *flist)
1027 for (i=1;i<flist->count;i++) {
1028 if (!flist->string_area)
1029 free_file(flist->files[i]);
1030 free(flist->files[i]);
1032 memset((char *)flist->files, 0, sizeof(flist->files[0])*flist->count);
1034 if (flist->string_area)
1035 string_area_free(flist->string_area);
1036 memset((char *)flist, 0, sizeof(*flist));
1042 * This routine ensures we don't have any duplicate names in our file list.
1043 * duplicate names can cause corruption because of the pipelining
1045 static void clean_flist(struct file_list *flist, int strip_root)
1049 if (!flist || flist->count == 0)
1052 qsort(flist->files,flist->count,
1053 sizeof(flist->files[0]),
1054 (int (*)())file_compare);
1056 for (i=1;i<flist->count;i++) {
1057 if (flist->files[i]->basename &&
1058 flist->files[i-1]->basename &&
1059 strcmp(f_name(flist->files[i]),
1060 f_name(flist->files[i-1])) == 0) {
1061 if (verbose > 1 && !am_server)
1062 rprintf(FINFO,"removing duplicate name %s from file list %d\n",
1063 f_name(flist->files[i-1]),i-1);
1064 /* it's not great that the flist knows the semantics of the
1065 * file memory usage, but i'd rather not add a flag byte
1066 * to that struct. XXX can i use a bit in the flags field? */
1067 if (flist->string_area)
1068 flist->files[i][0] = null_file;
1070 free_file(flist->files[i]);
1075 /* we need to strip off the root directory in the case
1076 of relative paths, but this must be done _after_
1077 the sorting phase */
1078 for (i=0;i<flist->count;i++) {
1079 if (flist->files[i]->dirname &&
1080 flist->files[i]->dirname[0] == '/') {
1081 memmove(&flist->files[i]->dirname[0],
1082 &flist->files[i]->dirname[1],
1083 strlen(flist->files[i]->dirname));
1086 if (flist->files[i]->dirname &&
1087 !flist->files[i]->dirname[0]) {
1088 flist->files[i]->dirname = NULL;
1094 if (verbose <= 3) return;
1096 for (i=0;i<flist->count;i++) {
1097 rprintf(FINFO,"[%d] i=%d %s %s mode=0%o len=%.0f\n",
1099 NS(flist->files[i]->dirname),
1100 NS(flist->files[i]->basename),
1101 flist->files[i]->mode,
1102 (double)flist->files[i]->length);
1108 * return the full filename of a flist entry
1110 char *f_name(struct file_struct *f)
1112 static char names[10][MAXPATHLEN];
1116 if (!f || !f->basename) return NULL;
1121 strlcpy(p, f->dirname, MAXPATHLEN);
1122 strlcat(p, "/", MAXPATHLEN);
1123 strlcat(p, f->basename, MAXPATHLEN);
1125 strlcpy(p, f->basename, MAXPATHLEN);