- Fixed some deletion problems where a non-empty directory was
authorWayne Davison <wayned@samba.org>
Fri, 21 Jan 2005 00:06:02 +0000 (00:06 +0000)
committerWayne Davison <wayned@samba.org>
Fri, 21 Jan 2005 00:06:02 +0000 (00:06 +0000)
  needing to be removed.
- Tweaked the option parsing a bit.
- Removed some of dry-run fixes that already made it into the
  CVS version.

delete-during.diff

index 0b59fd2..86a5917 100644 (file)
@@ -9,9 +9,17 @@ the old functionality (and indeed, the support for popt aliases that is now
 in CVS will let the user easily choose which method they'd like --delete to
 invoke, either personally or site-wide, without having to recompile rsync).
 
---- orig/flist.c       2005-01-20 00:53:48
-+++ flist.c    2005-01-20 01:12:35
-@@ -45,6 +45,8 @@ extern int cvs_exclude;
+--- orig/flist.c       2005-01-20 23:57:44
++++ flist.c    2005-01-20 23:42:36
+@@ -35,6 +35,7 @@ extern int am_root;
+ extern int am_server;
+ extern int am_daemon;
+ extern int am_sender;
++extern int delete_during;
+ extern int always_checksum;
+ extern int module_id;
+ extern int ignore_errors;
+@@ -45,6 +46,8 @@ extern int cvs_exclude;
  extern int recurse;
  extern int keep_dirs;
  extern char curr_dir[MAXPATHLEN];
@@ -20,7 +28,7 @@ invoke, either personally or site-wide, without having to recompile rsync).
  extern int filesfrom_fd;
  
  extern int one_file_system;
-@@ -57,11 +59,14 @@ extern int preserve_uid;
+@@ -57,11 +60,14 @@ extern int preserve_uid;
  extern int preserve_gid;
  extern int relative_paths;
  extern int implied_dirs;
@@ -35,7 +43,7 @@ invoke, either personally or site-wide, without having to recompile rsync).
  extern int orig_umask;
  extern int list_only;
  
-@@ -1044,7 +1049,8 @@ static void send_directory(int f, struct
+@@ -1044,7 +1050,8 @@ static void send_directory(int f, struct
                    || (dname[1] == '.' && dname[2] == '\0')))
                        continue;
                if (strlcpy(p, dname, MAXPATHLEN - offset) < MAXPATHLEN - offset) {
@@ -45,7 +53,7 @@ invoke, either personally or site-wide, without having to recompile rsync).
                } else {
                        io_error |= IOERR_GENERAL;
                        rprintf(FINFO,
-@@ -1102,6 +1108,7 @@ struct file_list *send_file_list(int f, 
+@@ -1102,6 +1109,7 @@ struct file_list *send_file_list(int f, 
        while (1) {
                char fname2[MAXPATHLEN];
                char *fname = fname2;
@@ -53,7 +61,7 @@ invoke, either personally or site-wide, without having to recompile rsync).
  
                if (use_ff_fd) {
                        if (read_filesfrom_line(filesfrom_fd, fname) == 0)
-@@ -1143,7 +1150,7 @@ struct file_list *send_file_list(int f, 
+@@ -1143,7 +1151,7 @@ struct file_list *send_file_list(int f, 
                dir = NULL;
                olddir[0] = '\0';
  
@@ -62,7 +70,7 @@ invoke, either personally or site-wide, without having to recompile rsync).
                        p = strrchr(fname, '/');
                        if (p) {
                                *p = 0;
-@@ -1212,7 +1219,8 @@ struct file_list *send_file_list(int f, 
+@@ -1212,7 +1220,8 @@ struct file_list *send_file_list(int f, 
                if (one_file_system)
                        set_filesystem(fname);
  
@@ -72,7 +80,7 @@ invoke, either personally or site-wide, without having to recompile rsync).
  
                if (olddir[0]) {
                        flist_dir = NULL;
-@@ -1634,3 +1642,89 @@ char *f_name(struct file_struct *f)
+@@ -1634,3 +1643,91 @@ char *f_name(struct file_struct *f)
  
        return f_name_to(f, names[n]);
  }
@@ -91,7 +99,7 @@ invoke, either personally or site-wide, without having to recompile rsync).
 +      int save_keep_dirs = keep_dirs;
 +      int save_implied_dirs = implied_dirs;
 +      char *argv[1];
-+      int i;
++      int i, j, mode;
 +
 +      if (max_delete && deletion_count >= max_delete)
 +              return;
@@ -124,9 +132,11 @@ invoke, either personally or site-wide, without having to recompile rsync).
 +                      break;
 +              if (!del_flist->files[i]->basename)
 +                      continue;
-+              if (flist_find(flist, del_flist->files[i]) < 0) {
++              mode = del_flist->files[i]->mode;
++              if ((j = flist_find(flist, del_flist->files[i])) < 0
++                  || (delete_during && S_ISDIR(mode)
++                   && !S_ISDIR(flist->files[j]->mode))) {
 +                      char *f = f_name(del_flist->files[i]);
-+                      int mode = del_flist->files[i]->mode;
 +                      if (make_backups && (backup_dir || !is_backup_file(f))
 +                        && !S_ISDIR(mode)) {
 +                              make_backup(f);
@@ -136,7 +146,7 @@ invoke, either personally or site-wide, without having to recompile rsync).
 +                              }
 +                      } else {
 +                              delete_file(f, S_ISDIR(mode)
-+                                          ? DEL_DIR | DEL_NO_RECURSE : 0);
++                                              ? DEL_DIR | DEL_RECURSE : 0);
 +                      }
 +                      deletion_count++;
 +              }
@@ -162,8 +172,8 @@ invoke, either personally or site-wide, without having to recompile rsync).
 +              delete_in_dir(flist, f_name_to(flist->files[j], fbuf), recurse);
 +      }
 +}
---- orig/generator.c   2005-01-19 20:11:10
-+++ generator.c        2005-01-18 23:14:23
+--- orig/generator.c   2005-01-20 23:05:34
++++ generator.c        2005-01-20 23:08:38
 @@ -34,6 +34,8 @@ extern int preserve_hard_links;
  extern int preserve_perms;
  extern int preserve_uid;
@@ -183,16 +193,7 @@ invoke, either personally or site-wide, without having to recompile rsync).
                           int f_out, int f_out_name)
  {
        int fd = -1, f_copy = -1;
-@@ -294,8 +297,6 @@ static void recv_generator(char *fname, 
-                * we need to delete it.  If it doesn't exist, then
-                * recursively create it. */
--              if (dry_run)
--                      return; /* TODO: causes inaccuracies -- fix */
-               if (statret == 0 && !S_ISDIR(st.st_mode)) {
-                       delete_file(fname, DEL_TERSE);
-                       statret = -1;
-@@ -311,6 +312,8 @@ static void recv_generator(char *fname, 
+@@ -308,6 +311,8 @@ static void recv_generator(char *fname, 
                }
                /* f_out is set to -1 when doing final directory-permission
                 * and modification-time repair. */
@@ -201,7 +202,7 @@ invoke, either personally or site-wide, without having to recompile rsync).
                if (set_perms(fname, file, statret ? NULL : &st, 0)
                    && verbose && f_out != -1)
                        rprintf(FINFO, "%s/\n", safe_fname(fname));
-@@ -621,6 +624,9 @@ void generate_files(int f_out, struct fi
+@@ -618,6 +623,9 @@ void generate_files(int f_out, struct fi
                        : "delta transmission enabled\n");
        }
  
@@ -211,7 +212,7 @@ invoke, either personally or site-wide, without having to recompile rsync).
        /* we expect to just sit around now, so don't exit on a
           timeout. If we really get a timeout then the other process should
           exit */
-@@ -644,7 +650,7 @@ void generate_files(int f_out, struct fi
+@@ -641,7 +649,7 @@ void generate_files(int f_out, struct fi
                }
  
                recv_generator(local_name ? local_name : f_name_to(file, fbuf),
@@ -220,7 +221,7 @@ invoke, either personally or site-wide, without having to recompile rsync).
        }
  
        phase++;
-@@ -661,7 +667,7 @@ void generate_files(int f_out, struct fi
+@@ -658,7 +666,7 @@ void generate_files(int f_out, struct fi
        while ((i = get_redo_num()) != -1) {
                struct file_struct *file = flist->files[i];
                recv_generator(local_name ? local_name : f_name_to(file, fbuf),
@@ -229,7 +230,7 @@ invoke, either personally or site-wide, without having to recompile rsync).
        }
  
        phase++;
-@@ -683,7 +689,7 @@ void generate_files(int f_out, struct fi
+@@ -680,7 +688,7 @@ void generate_files(int f_out, struct fi
                if (!file->basename || !S_ISDIR(file->mode))
                        continue;
                recv_generator(local_name ? local_name : f_name(file),
@@ -260,8 +261,8 @@ invoke, either personally or site-wide, without having to recompile rsync).
                        delete_files(flist);
        }
  
---- orig/options.c     2005-01-19 00:34:19
-+++ options.c  2005-01-20 01:17:04
+--- orig/options.c     2005-01-20 23:05:34
++++ options.c  2005-01-20 23:06:33
 @@ -54,6 +54,8 @@ int dry_run = 0;
  int local_server = 0;
  int ignore_times = 0;
@@ -289,35 +290,32 @@ invoke, either personally or site-wide, without having to recompile rsync).
    rprintf(F,"     --numeric-ids           don't map uid/gid values by user/group name\n");
    rprintf(F,"     --timeout=TIME          set I/O timeout in seconds\n");
    rprintf(F," -I, --ignore-times          turn off mod time & file size quick check\n");
-@@ -320,8 +323,8 @@ void usage(enum logcode F)
-   rprintf(F,"See http://rsync.samba.org/ for updates, bug reports, and answers\n");
+@@ -321,7 +324,6 @@ void usage(enum logcode F)
  }
  
--enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
+ enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
 -      OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED,
-+enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE,
-+      OPT_EXCLUDE_FROM, OPT_DELETE_MODE,
        OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST,
        OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
        OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT, OPT_MAX_SIZE,
-@@ -337,11 +340,13 @@ static struct poptOption long_options[] 
+@@ -337,11 +339,13 @@ static struct poptOption long_options[] 
    {"size-only",        0,  POPT_ARG_NONE,   &size_only, 0, 0, 0 },
    {"modify-window",    0,  POPT_ARG_INT,    &modify_window, OPT_MODIFY_WINDOW, 0, 0 },
    {"one-file-system", 'x', POPT_ARG_NONE,   &one_file_system, 0, 0, 0 },
 -  {"delete",           0,  POPT_ARG_NONE,   &delete_mode, 0, 0, 0 },
-+  {"delete",           0,  POPT_ARG_NONE,   0, OPT_DELETE_MODE, 0, 0 },
-+  {"delete-during",    0,  POPT_ARG_NONE,   &delete_during, OPT_DELETE_MODE, 0, 0 },
-+  {"delete-before",    0,  POPT_ARG_NONE,   &delete_before, OPT_DELETE_MODE, 0, 0 },
++  {"delete",           0,  POPT_ARG_NONE,   &delete_during, 0, 0, 0 },
++  {"delete-during",    0,  POPT_ARG_NONE,   &delete_during, 0, 0, 0 },
++  {"delete-before",    0,  POPT_ARG_NONE,   &delete_before, 0, 0, 0 },
    {"existing",         0,  POPT_ARG_NONE,   &only_existing, 0, 0, 0 },
    {"ignore-existing",  0,  POPT_ARG_NONE,   &opt_ignore_existing, 0, 0, 0 },
 -  {"delete-after",     0,  POPT_ARG_NONE,   0, OPT_DELETE_AFTER, 0, 0 },
 -  {"delete-excluded",  0,  POPT_ARG_NONE,   0, OPT_DELETE_EXCLUDED, 0, 0 },
-+  {"delete-after",     0,  POPT_ARG_NONE,   &delete_after, OPT_DELETE_MODE, 0, 0 },
-+  {"delete-excluded",  0,  POPT_ARG_NONE,   &delete_excluded, OPT_DELETE_MODE, 0, 0 },
++  {"delete-after",     0,  POPT_ARG_NONE,   &delete_after, 0, 0, 0 },
++  {"delete-excluded",  0,  POPT_ARG_NONE,   &delete_excluded, 0, 0, 0 },
    {"force",            0,  POPT_ARG_NONE,   &force_delete, 0, 0, 0 },
    {"numeric-ids",      0,  POPT_ARG_NONE,   &numeric_ids, 0, 0, 0 },
    {"exclude",          0,  POPT_ARG_STRING, 0, OPT_EXCLUDE, 0, 0 },
-@@ -613,13 +618,7 @@ int parse_arguments(int *argc, const cha
+@@ -613,16 +617,6 @@ int parse_arguments(int *argc, const cha
                        modify_window_set = 1;
                        break;
  
@@ -328,11 +326,13 @@ invoke, either personally or site-wide, without having to recompile rsync).
 -
 -              case OPT_DELETE_EXCLUDED:
 -                      delete_excluded = 1;
-+              case OPT_DELETE_MODE:
-                       delete_mode = 1;
+-                      delete_mode = 1;
+-                      break;
+-
+               case OPT_EXCLUDE:
+                       add_exclude(&exclude_list, poptGetOptArg(pc), 0);
                        break;
-@@ -851,13 +850,18 @@ int parse_arguments(int *argc, const cha
+@@ -851,13 +845,20 @@ int parse_arguments(int *argc, const cha
                preserve_uid = 1;
                preserve_devices = 1;
        }
@@ -345,13 +345,15 @@ invoke, either personally or site-wide, without having to recompile rsync).
        if (relative_paths < 0)
                relative_paths = files_from? 1 : 0;
  
-+      if (delete_mode && !(delete_during || delete_before || delete_after))
-+              delete_during = 1; /* Use "delete_before" for old default. */
++      if (delete_during || delete_before || delete_after)
++              delete_mode = 1;
++      if (delete_excluded && !delete_mode)
++              delete_mode = delete_during = 1;
 +
        *argv = poptGetArgs(pc);
        *argc = count_args(*argv);
  
-@@ -1156,7 +1160,9 @@ void server_options(char **args,int *arg
+@@ -1156,7 +1157,9 @@ void server_options(char **args,int *arg
        if (am_sender) {
                if (delete_excluded)
                        args[ac++] = "--delete-excluded";
@@ -362,7 +364,7 @@ invoke, either personally or site-wide, without having to recompile rsync).
                        args[ac++] = "--delete";
  
                if (delete_after)
---- orig/receiver.c    2005-01-19 20:11:10
+--- orig/receiver.c    2005-01-20 23:52:09
 +++ receiver.c 2005-01-18 22:47:38
 @@ -23,7 +23,6 @@
  extern int verbose;
@@ -448,7 +450,7 @@ invoke, either personally or site-wide, without having to recompile rsync).
 -                                      }
 -                              } else {
 -                                      delete_file(f, S_ISDIR(mode)
--                                          ? DEL_DIR | DEL_NO_RECURSE : 0);
+-                                              ? DEL_DIR | DEL_RECURSE : 0);
 -                              }
 -                              deletion_count++;
 -                      }
@@ -461,8 +463,8 @@ invoke, either personally or site-wide, without having to recompile rsync).
  /*
   * get_tmpname() - create a tmp filename for a given filename
   *
---- orig/rsync.yo      2005-01-17 23:11:46
-+++ rsync.yo   2005-01-20 01:16:54
+--- orig/rsync.yo      2005-01-20 19:47:08
++++ rsync.yo   2005-01-19 01:05:05
 @@ -341,14 +341,15 @@ verb(
       --existing              only update files that already exist
       --ignore-existing       ignore files that already exist on receiver