I had a situation where I needed to remove a file locally after I
transferred it to a remote machine. I modified rsync and added the
--delete-local option. 

I am now submitting my changes back to the community in case anyone else
needs this option. enjoy

p.s. I am not subscribed to the list but you can reply to me directly at
[EMAIL PROTECTED] 

-Dave


-- 
Dave Seff <[EMAIL PROTECTED]>
IT Manager
Advisen Ltd. 
diff -Nur rsync-2.5.6/lib/dummy rsync-dave/lib/dummy
--- rsync-2.5.6/lib/dummy	1969-12-31 19:00:00.000000000 -0500
+++ rsync-dave/lib/dummy	2003-09-19 13:33:56.000000000 -0400
@@ -0,0 +1,2 @@
+This is a dummy file to ensure that the lib directory gets created
+by configure when a VPATH is used.
diff -Nur rsync-2.5.6/options.c rsync-dave/options.c
--- rsync-2.5.6/options.c	2003-01-27 22:11:57.000000000 -0500
+++ rsync-dave/options.c	2003-09-19 13:53:58.000000000 -0400
@@ -49,6 +49,7 @@
 int local_server=0;
 int ignore_times=0;
 int delete_mode=0;
+int delete_local=0;
 int delete_excluded=0;
 int one_file_system=0;
 int remote_version=0;
@@ -238,6 +239,7 @@
   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,"     --delete-after          delete after transferring, not before\n");
+  rprintf(F,"     --delete-local          delete the local files after transferring\n");
   rprintf(F,"     --ignore-errors         delete even if there are IO errors\n");
   rprintf(F,"     --max-delete=NUM        don't delete more than NUM files\n");
   rprintf(F,"     --partial               keep partially transferred files\n");
@@ -288,7 +290,7 @@
       OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_STATS, OPT_PARTIAL, OPT_PROGRESS,
       OPT_COPY_UNSAFE_LINKS, OPT_SAFE_LINKS, OPT_COMPARE_DEST, OPT_LINK_DEST,
       OPT_LOG_FORMAT, OPT_PASSWORD_FILE, OPT_SIZE_ONLY, OPT_ADDRESS,
-      OPT_DELETE_AFTER, OPT_EXISTING, OPT_MAX_DELETE, OPT_BACKUP_DIR, 
+      OPT_DELETE_AFTER, OPT_DELETE_LOCAL, OPT_EXISTING, OPT_MAX_DELETE, OPT_BACKUP_DIR, 
       OPT_IGNORE_ERRORS, OPT_BWLIMIT, OPT_BLOCKING_IO,
       OPT_NO_BLOCKING_IO, OPT_WHOLE_FILE, OPT_NO_WHOLE_FILE,
       OPT_MODIFY_WINDOW, OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_IGNORE_EXISTING};
@@ -306,6 +308,7 @@
   {"delete",           0,  POPT_ARG_NONE,   &delete_mode , 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-local",     0,  POPT_ARG_NONE,   0,              OPT_DELETE_LOCAL, 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 },
   {"force",            0,  POPT_ARG_NONE,   &force_delete , 0, 0, 0 },
@@ -490,6 +493,10 @@
 			delete_mode = 1;
 			break;
 
+		case OPT_DELETE_LOCAL:
+			delete_local = 1;
+			break;
+
 		case OPT_DELETE_EXCLUDED:
 			delete_excluded = 1;
 			delete_mode = 1;
diff -Nur rsync-2.5.6/sender.c rsync-dave/sender.c
--- rsync-2.5.6/sender.c	2002-04-09 02:03:50.000000000 -0400
+++ rsync-dave/sender.c	2003-09-19 14:46:37.000000000 -0400
@@ -104,6 +104,7 @@
 	struct stats initial_stats;
 	extern int write_batch;   /* dw */
 	extern int read_batch;    /* dw */
+	extern int delete_local;
 	int checksums_match;   /* dw */
 	int buff_len;  /* dw */
 	char buff[CHUNK_SIZE];    /* dw */
@@ -281,6 +282,16 @@
 	  
 		if (verbose > 2)
 			rprintf(FINFO,"sender finished %s\n",fname);
+                
+                /* here is where I delete the file locally after I have sent it. */
+                if (delete_local)
+                {
+                   if (robust_unlink(f_name(file)) != 0) {
+                      rprintf(FERROR,"delete_one: unlink %s: %s\n",f_name(file),strerror(errno));
+                   } else if (verbose) {
+                      rprintf(FINFO,"deleting %s\n",f_name(file));
+                   }
+                }
 	}
 
 	if (verbose > 2)
@@ -297,6 +308,3 @@
 }
 
 
-
-
-
diff -Nur rsync-2.5.6/zlib/dummy rsync-dave/zlib/dummy
--- rsync-2.5.6/zlib/dummy	1969-12-31 19:00:00.000000000 -0500
+++ rsync-dave/zlib/dummy	2003-09-19 13:33:59.000000000 -0400
@@ -0,0 +1,2 @@
+This is a dummy file to ensure that the lib directory gets created
+by configure when a VPATH is used.
-- 
To unsubscribe or change options: http://lists.samba.org/mailman/listinfo/rsync
Before posting, read: http://www.catb.org/~esr/faqs/smart-questions.html

Reply via email to