From b33b791e6ba823589bdee416b91ad9278cb36ef2 Mon Sep 17 00:00:00 2001 From: David Dykstra Date: Mon, 22 Feb 1999 19:55:57 +0000 Subject: [PATCH] Add --delete-excluded option to delete files on the receiving side that are excluded. Implies --delete. --- README | 1 + flist.c | 10 ++++++---- main.c | 6 ++++-- options.c | 19 +++++++++++++++---- rsync.yo | 17 +++++++++++------ 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/README b/README index 7e6c181e..4934a90b 100644 --- a/README +++ b/README @@ -61,6 +61,7 @@ Options --rsync-path=PATH specify path to rsync on the remote machine -C, --cvs-exclude auto ignore files in the same way CVS does --delete delete files that don't exist on the sending side + --delete-excluded also delete excluded files on the receiving side --partial keep partially transferred files --force force deletion of directories even if not empty --numeric-ids don't map uid/gid values by user/group name diff --git a/flist.c b/flist.c index 2ec04c88..3a44aa7b 100644 --- a/flist.c +++ b/flist.c @@ -395,7 +395,7 @@ static int skip_filesystem(char *fname, STRUCT_STAT *st) return (st2.st_dev != filesystem_dev); } -static struct file_struct *make_file(char *fname) +static struct file_struct *make_file(int f, char *fname) { struct file_struct *file; STRUCT_STAT st; @@ -403,6 +403,7 @@ static struct file_struct *make_file(char *fname) char *p; char cleaned_name[MAXPATHLEN]; char linkbuf[MAXPATHLEN]; + extern int delete_excluded; strlcpy(cleaned_name, fname, MAXPATHLEN); cleaned_name[MAXPATHLEN-1] = 0; @@ -428,11 +429,12 @@ static struct file_struct *make_file(char *fname) return NULL; } - if (!match_file_name(fname,&st)) + /* f is set to -1 when calculating deletion file list */ + if (((f != -1) || !delete_excluded) && !match_file_name(fname,&st)) return NULL; if (verbose > 2) - rprintf(FINFO,"make_file(%s)\n",fname); + rprintf(FINFO,"make_file(%d,%s)\n",f,fname); file = (struct file_struct *)malloc(sizeof(*file)); if (!file) out_of_memory("make_file"); @@ -509,7 +511,7 @@ void send_file_name(int f,struct file_list *flist,char *fname, { struct file_struct *file; - file = make_file(fname); + file = make_file(f,fname); if (!file) return; diff --git a/main.c b/main.c index 2846f881..5bd5b8a1 100644 --- a/main.c +++ b/main.c @@ -335,6 +335,7 @@ static void do_server_recv(int f_in, int f_out, int argc,char *argv[]) char *local_name=NULL; char *dir = NULL; extern int delete_mode; + extern int delete_excluded; extern int am_daemon; if (verbose > 2) @@ -351,7 +352,7 @@ static void do_server_recv(int f_in, int f_out, int argc,char *argv[]) } } - if (delete_mode) + if (delete_mode && !delete_excluded) recv_exclude_list(f_in); flist = recv_file_list(f_in); @@ -408,9 +409,10 @@ int client_run(int f_in, int f_out, int pid, int argc, char *argv[]) if (am_sender) { extern int cvs_exclude; extern int delete_mode; + extern int delete_excluded; if (cvs_exclude) add_cvs_excludes(); - if (delete_mode) + if (delete_mode && !delete_excluded) send_exclude_list(f_out); flist = send_file_list(f_out,argc,argv); if (verbose > 3) diff --git a/options.c b/options.c index aff2a3a1..3b94533a 100644 --- a/options.c +++ b/options.c @@ -37,6 +37,7 @@ int dry_run=0; int local_server=0; int ignore_times=0; int delete_mode=0; +int delete_excluded=0; int one_file_system=0; int remote_version=0; int sparse_files=0; @@ -123,6 +124,7 @@ void usage(int F) rprintf(F," --rsync-path=PATH specify path to rsync on the remote machine\n"); rprintf(F," -C, --cvs-exclude auto ignore files in the same way CVS does\n"); rprintf(F," --delete delete files that don't exist on the sending side\n"); + rprintf(F," --delete-excluded also delete excluded files on the receiving side\n"); rprintf(F," --partial keep partially transferred files\n"); rprintf(F," --force force deletion of directories even if not empty\n"); rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n"); @@ -152,9 +154,9 @@ void usage(int F) rprintf(F,"See http://rsync.samba.org/ for updates and bug reports\n"); } -enum {OPT_VERSION,OPT_SUFFIX,OPT_SENDER,OPT_SERVER,OPT_EXCLUDE, - OPT_EXCLUDE_FROM,OPT_DELETE,OPT_NUMERIC_IDS,OPT_RSYNC_PATH, - OPT_FORCE,OPT_TIMEOUT,OPT_DAEMON,OPT_CONFIG,OPT_PORT, +enum {OPT_VERSION, OPT_SUFFIX, OPT_SENDER, OPT_SERVER, OPT_EXCLUDE, + OPT_EXCLUDE_FROM, OPT_DELETE, OPT_DELETE_EXCLUDED, OPT_NUMERIC_IDS, + OPT_RSYNC_PATH, OPT_FORCE, OPT_TIMEOUT, OPT_DAEMON, OPT_CONFIG, OPT_PORT, OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_STATS, OPT_PARTIAL, OPT_PROGRESS, OPT_COPY_UNSAFE_LINKS, OPT_SAFE_LINKS, OPT_COMPARE_DEST, OPT_LOG_FORMAT, OPT_PASSWORD_FILE, OPT_SIZE_ONLY}; @@ -166,6 +168,7 @@ static struct option long_options[] = { {"server", 0, 0, OPT_SERVER}, {"sender", 0, 0, OPT_SENDER}, {"delete", 0, 0, OPT_DELETE}, + {"delete-excluded", 0, 0, OPT_DELETE_EXCLUDED}, {"force", 0, 0, OPT_FORCE}, {"numeric-ids", 0, 0, OPT_NUMERIC_IDS}, {"exclude", 1, 0, OPT_EXCLUDE}, @@ -309,6 +312,11 @@ int parse_arguments(int argc, char *argv[], int frommain) delete_mode = 1; break; + case OPT_DELETE_EXCLUDED: + delete_excluded = 1; + delete_mode = 1; + break; + case OPT_FORCE: force_delete = 1; break; @@ -591,9 +599,12 @@ void server_options(char **args,int *argc) args[ac++] = backup_suffix; } - if (delete_mode) + if (delete_mode && !delete_excluded) args[ac++] = "--delete"; + if (delete_excluded) + args[ac++] = "--delete-excluded"; + if (size_only) args[ac++] = "--size-only"; diff --git a/rsync.yo b/rsync.yo index 28097494..9f27cf97 100644 --- a/rsync.yo +++ b/rsync.yo @@ -1,5 +1,5 @@ mailto(rsync-bugs@samba.org) -manpage(rsync)(1)(18 Feb 1999)()() +manpage(rsync)(1)(22 Feb 1999)()() manpagename(rsync)(faster, flexible replacement for rcp) manpagesynopsis() @@ -250,6 +250,7 @@ Options --rsync-path=PATH specify path to rsync on the remote machine -C, --cvs-exclude auto ignore files in the same way CVS does --delete delete files that don't exist on the sending side + --delete-excluded also delete excluded files on the receiving side --partial keep partially transferred files --force force deletion of directories even if not empty --numeric-ids don't map uid/gid values by user/group name @@ -430,12 +431,12 @@ boundaries when recursing. This is useful for transferring the contents of only one filesystem. dit(bf(--delete)) This tells rsync to delete any files on the receiving -side that aren't on the sending side. This option can be dangerous if -used incorrectly! +side that aren't on the sending side. Files that are excluded from +transfer are excluded from being deleted unless you use --delete-excluded. -It is a very good idea to run first using the dry run option (-n) to -see what files would be deleted to make sure important files aren't -listed. +This option can be dangerous if used incorrectly! It is a very good idea +to run first using the dry run option (-n) to see what files would be +deleted to make sure important files aren't listed. rsync 1.6.4 changed the behavior of --delete to make it less dangerous. rsync now only scans directories on the receiving side @@ -452,6 +453,10 @@ prevent temporary filesystem failures (such as NFS errors) on the sending side causing a massive deletion of files on the destination. +dit(bf(--delete-excluded)) In addition to deleting the files on the +receiving side that are not on the sending side, this tells rsync to also +delete any files on the receiving side that are excluded (see --exclude). + dit(bf(--force)) This options tells rsync to delete directories even if they are not empty. This applies to both the --delete option and to cases where rsync tries to copy a normal file but the destination -- 2.34.1