- DIR *d;
- struct dirent *di;
- char fname[MAXPATHLEN];
- int l;
- char *p;
-
- d = opendir(dir);
- if (!d) {
- fprintf(FERROR,"%s: %s\n",
- dir,strerror(errno));
- return;
- }
-
- strncpy(fname,dir,MAXPATHLEN-1);
- fname[MAXPATHLEN-1]=0;
- l = strlen(fname);
- if (fname[l-1] != '/') {
- if (l == MAXPATHLEN-1) {
- fprintf(FERROR,"skipping long-named directory %s\n",fname);
- closedir(d);
- return;
- }
- strcat(fname,"/");
- l++;
- }
- p = fname + strlen(fname);
-
- if (cvs_exclude) {
- if (strlen(fname) + strlen(".cvsignore") <= MAXPATHLEN-1) {
- strcpy(p,".cvsignore");
- local_exclude_list = make_exclude_list(fname,NULL,0);
- } else {
- fprintf(FERROR,"cannot cvs-exclude in long-named directory %s\n",fname);
- }
- }
-
- for (di=readdir(d); di; di=readdir(d)) {
- if (strcmp(di->d_name,".")==0 ||
- strcmp(di->d_name,"..")==0)
- continue;
- strncpy(p,di->d_name,MAXPATHLEN-(l+1));
- send_file_name(f,flist,fname);
- }
-
- closedir(d);
-}
-
-
-
-struct file_list *send_file_list(int f,int argc,char *argv[])
-{
- int i,l;
- struct stat st;
- char *p,*dir;
- char dbuf[MAXPATHLEN];
- struct file_list *flist;
-
- if (verbose && recurse && !am_server && f != -1) {
- fprintf(FINFO,"building file list ... ");
- fflush(FINFO);
- }
-
- flist = (struct file_list *)malloc(sizeof(flist[0]));
- if (!flist) out_of_memory("send_file_list");
-
- flist->count=0;
- flist->malloced = 100;
- flist->files = (struct file_struct *)malloc(sizeof(flist->files[0])*
- flist->malloced);
- if (!flist->files) out_of_memory("send_file_list");
-
- for (i=0;i<argc;i++) {
- char fname2[MAXPATHLEN];
- char *fname = fname2;
-
- strncpy(fname,argv[i],MAXPATHLEN-1);
- fname[MAXPATHLEN-1] = 0;
-
- l = strlen(fname);
- if (l != 1 && fname[l-1] == '/') {
- strcat(fname,".");
- }
-
- if (link_stat(fname,&st) != 0) {
- fprintf(FERROR,"%s : %s\n",fname,strerror(errno));
- continue;
- }
-
- if (S_ISDIR(st.st_mode) && !recurse) {
- fprintf(FERROR,"skipping directory %s\n",fname);
- continue;
- }
-
- dir = NULL;
-
- if (!relative_paths) {
- p = strrchr(fname,'/');
- if (p) {
- *p = 0;
- if (p == fname)
- dir = "/";
- else
- dir = fname;
- fname = p+1;
- }
- }
-
- if (!*fname)
- fname = ".";
-
- if (dir && *dir) {
- if (getcwd(dbuf,MAXPATHLEN-1) == NULL) {
- fprintf(FERROR,"getwd : %s\n",strerror(errno));
- exit_cleanup(1);
- }
- if (chdir(dir) != 0) {
- fprintf(FERROR,"chdir %s : %s\n",dir,strerror(errno));
- continue;
- }
- flist_dir = dir;
- if (one_file_system)
- set_filesystem(fname);
- send_file_name(f,flist,fname);
- flist_dir = NULL;
- if (chdir(dbuf) != 0) {
- fprintf(FERROR,"chdir %s : %s\n",dbuf,strerror(errno));
- exit_cleanup(1);
- }
- continue;
- }
-
- if (one_file_system)
- set_filesystem(fname);
- send_file_name(f,flist,fname);
- }
-
- if (f != -1) {
- send_file_entry(NULL,f);
- write_flush(f);
- }
-
- if (verbose && recurse && !am_server && f != -1)
- fprintf(FINFO,"done\n");
-
- clean_flist(flist);
-
- /* now send the uid/gid list. This was introduced in protocol version 15 */
- if (f != -1 && remote_version >= 15) {
- send_uid_list(f);
- }
-
- return flist;
+ DIR *d;
+ struct dirent *di;
+ char fname[MAXPATHLEN];
+ int l;
+ char *p;
+
+ d = opendir(dir);
+ if (!d) {
+ io_error = 1;
+ rprintf(FERROR, "opendir(%s): %s\n", dir, strerror(errno));
+ return;
+ }
+
+ strlcpy(fname, dir, MAXPATHLEN);
+ l = strlen(fname);
+ if (fname[l - 1] != '/') {
+ if (l == MAXPATHLEN - 1) {
+ io_error = 1;
+ rprintf(FERROR,
+ "skipping long-named directory %s\n",
+ fname);
+ closedir(d);
+ return;
+ }
+ strlcat(fname, "/", MAXPATHLEN);
+ l++;
+ }
+ p = fname + strlen(fname);
+
+ local_exclude_list = NULL;
+
+ if (cvs_exclude) {
+ if (strlen(fname) + strlen(".cvsignore") <= MAXPATHLEN - 1) {
+ strcpy(p, ".cvsignore");
+ local_exclude_list =
+ make_exclude_list(fname, NULL, 0, 0);
+ } else {
+ io_error = 1;
+ rprintf(FINFO,
+ "cannot cvs-exclude in long-named directory %s\n",
+ fname);
+ }
+ }
+
+ for (di = readdir(d); di; di = readdir(d)) {
+ char *dname = d_name(di);
+ if (strcmp(dname, ".") == 0 || strcmp(dname, "..") == 0)
+ continue;
+ strlcpy(p, dname, MAXPATHLEN - l);
+ send_file_name(f, flist, fname, recurse, 0);
+ }
+
+ if (local_exclude_list) {
+ add_exclude_list("!", &local_exclude_list, 0);
+ }
+
+ closedir(d);
+}
+
+
+/**
+ *
+ * I <b>think</b> f==-1 means that the list should just be built in
+ * memory and not transmitted. But who can tell? -- mbp
+ **/
+struct file_list *send_file_list(int f, int argc, char *argv[])
+{
+ int i, l;
+ STRUCT_STAT st;
+ char *p, *dir, *olddir;
+ char lastpath[MAXPATHLEN] = "";
+ struct file_list *flist;
+ int64 start_write;
+
+ if (show_filelist_p() && f != -1)
+ start_filelist_progress("building file list");
+
+ start_write = stats.total_written;
+
+ flist = flist_new();
+
+ if (f != -1) {
+ io_start_buffering(f);
+ }
+
+ for (i = 0; i < argc; i++) {
+ char *fname = topsrcname;
+
+ strlcpy(fname, argv[i], MAXPATHLEN);
+
+ l = strlen(fname);
+ if (l != 1 && fname[l - 1] == '/') {
+ if ((l == 2) && (fname[0] == '.')) {
+ /* Turn ./ into just . rather than ./.
+ This was put in to avoid a problem with
+ rsync -aR --delete from ./
+ The send_file_name() below of ./ was
+ mysteriously preventing deletes */
+ fname[1] = 0;
+ } else {
+ strlcat(fname, ".", MAXPATHLEN);
+ }
+ }
+
+ if (link_stat(fname, &st) != 0) {
+ if (f != -1) {
+ io_error = 1;
+ rprintf(FERROR, "link_stat %s : %s\n",
+ fname, strerror(errno));
+ }
+ continue;
+ }
+
+ if (S_ISDIR(st.st_mode) && !recurse) {
+ rprintf(FINFO, "skipping directory %s\n", fname);
+ continue;
+ }
+
+ dir = NULL;
+ olddir = NULL;
+
+ if (!relative_paths) {
+ p = strrchr(fname, '/');
+ if (p) {
+ *p = 0;
+ if (p == fname)
+ dir = "/";
+ else
+ dir = fname;
+ fname = p + 1;
+ }
+ } else if (f != -1 && (p = strrchr(fname, '/'))) {
+ /* this ensures we send the intermediate directories,
+ thus getting their permissions right */
+ *p = 0;
+ if (strcmp(lastpath, fname)) {
+ strlcpy(lastpath, fname, sizeof(lastpath));
+ *p = '/';
+ for (p = fname + 1; (p = strchr(p, '/'));
+ p++) {
+ int copy_links_saved = copy_links;
+ int recurse_saved = recurse;
+ *p = 0;
+ copy_links = copy_unsafe_links;
+ /* set recurse to 1 to prevent make_file
+ from ignoring directory, but still
+ turn off the recursive parameter to
+ send_file_name */
+ recurse = 1;
+ send_file_name(f, flist, fname, 0,
+ 0);
+ copy_links = copy_links_saved;
+ recurse = recurse_saved;
+ *p = '/';
+ }
+ } else {
+ *p = '/';
+ }
+ }
+
+ if (!*fname)
+ fname = ".";
+
+ if (dir && *dir) {
+ olddir = push_dir(dir, 1);
+
+ if (!olddir) {
+ io_error = 1;
+ rprintf(FERROR, "push_dir %s : %s\n",
+ dir, strerror(errno));
+ continue;
+ }
+
+ flist_dir = dir;
+ }
+
+ if (one_file_system)
+ set_filesystem(fname);
+
+ send_file_name(f, flist, fname, recurse, FLAG_DELETE);
+
+ if (olddir != NULL) {
+ flist_dir = NULL;
+ if (pop_dir(olddir) != 0) {
+ rprintf(FERROR, "pop_dir %s : %s\n",
+ dir, strerror(errno));
+ exit_cleanup(RERR_FILESELECT);
+ }
+ }
+ }
+
+ topsrcname[0] = '\0';
+
+ if (f != -1) {
+ send_file_entry(NULL, f, 0);
+ }
+
+ if (show_filelist_p() && f != -1) {
+ finish_filelist_progress(flist);
+ }
+
+ clean_flist(flist, 0);
+
+ /* now send the uid/gid list. This was introduced in protocol
+ version 15 */
+ if (f != -1 && remote_version >= 15) {
+ send_uid_list(f);
+ }
+
+ /* if protocol version is >= 17 then send the io_error flag */
+ if (f != -1 && remote_version >= 17) {
+ extern int module_id;
+ write_int(f, lp_ignore_errors(module_id) ? 0 : io_error);
+ }
+
+ if (f != -1) {
+ io_end_buffering();
+ stats.flist_size = stats.total_written - start_write;
+ stats.num_files = flist->count;
+ if (write_batch) /* dw */
+ write_batch_flist_info(flist->count, flist->files);
+ }
+
+ if (verbose > 2)
+ rprintf(FINFO, "send_file_list done\n");
+
+ return flist;