Index: backup.c
--- backup.c	31 Jul 2003 09:32:15 -0000	1.12
+++ backup.c	1 Aug 2003 07:55:43 -0000
@@ -21,11 +21,11 @@
 #include "rsync.h"
 
 extern int verbose;
-extern int suffix_specified;
+extern int backup_suffix_len;
+extern int backup_dir_len;
 extern char *backup_suffix;
 extern char *backup_dir;
 
-
 extern int am_root;
 extern int preserve_devices;
 extern int preserve_links;
@@ -35,7 +35,7 @@
 static int make_simple_backup(char *fname)
 {
 	char fnamebak[MAXPATHLEN];
-	if (strlen(fname) + strlen(backup_suffix) > (MAXPATHLEN-1)) {
+	if (strlen(fname) + backup_suffix_len > MAXPATHLEN-1) {
 		rprintf(FERROR, "backup filename too long\n");
 		return 0;
 	}
@@ -184,8 +184,8 @@
 	int ret_code;
 
 	if (!initialised) {
-		if (backup_dir[strlen(backup_dir) - 1] == '/')
-			backup_dir[strlen(backup_dir) - 1] = 0;
+		if (backup_dir_len && backup_dir[backup_dir_len - 1] == '/')
+			backup_dir[--backup_dir_len] = '\0';
 		if (verbose > 0)
 			rprintf (FINFO, "backup_dir is %s\n", backup_dir);
 		initialised = 1;
@@ -204,20 +204,13 @@
 	if (!file) return 1;
 
 	/* make a complete pathname for backup file */
-	if (strlen(backup_dir) + strlen(fname) +
-		(suffix_specified ? strlen(backup_suffix) : 0) > (MAXPATHLEN - 1)) {
+	if (backup_dir_len+strlen(fname)+backup_suffix_len > MAXPATHLEN-1) {
 		rprintf (FERROR, "keep_backup filename too long\n");
 		return 0;
 	}
 
-	if (suffix_specified) {
-		snprintf(keep_name, sizeof (keep_name), "%s/%s%s",
-		    backup_dir, fname, backup_suffix);
-	} else {
-		snprintf(keep_name, sizeof (keep_name), "%s/%s",
-		    backup_dir, fname);
-	}
-
+	snprintf(keep_name, sizeof (keep_name), "%s/%s%s",
+	    backup_dir, fname, backup_suffix);
 
 #ifdef HAVE_MKNOD
 	/* Check to see if this is a device file, or link */
Index: options.c
--- options.c	1 Jul 2003 21:45:23 -0000	1.109
+++ options.c	1 Aug 2003 07:55:44 -0000
@@ -105,9 +105,10 @@
 
 int write_batch = 0;
 int read_batch = 0;
-int suffix_specified = 0;
+int backup_dir_len = 0;
+int backup_suffix_len;
 
-char *backup_suffix = BACKUP_SUFFIX;
+char *backup_suffix = NULL;
 char *tmpdir = NULL;
 char *compare_dest = NULL;
 char *config_file = NULL;
@@ -293,7 +294,7 @@
   rprintf(F,"See http://rsync.samba.org/ for updates, bug reports, and answers\n");
 }
 
-enum {OPT_VERSION = 1000, OPT_SUFFIX, OPT_SENDER, OPT_SERVER, OPT_EXCLUDE,
+enum {OPT_VERSION = 1000, 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,
@@ -306,7 +307,7 @@
 static struct poptOption long_options[] = {
   /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
   {"version",          0,  POPT_ARG_NONE,   0,              OPT_VERSION, 0, 0},
-  {"suffix",           0,  POPT_ARG_STRING, &backup_suffix, OPT_SUFFIX, 0, 0 },
+  {"suffix",           0,  POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
   {"rsync-path",       0,  POPT_ARG_STRING, &rsync_path,	0, 0, 0 },
   {"password-file",    0,  POPT_ARG_STRING, &password_file,	0, 0, 0 },
   {"ignore-times",    'I', POPT_ARG_NONE,   &ignore_times, 0, 0, 0 },
@@ -485,13 +486,6 @@
 			print_rsync_version(FINFO);
 			exit_cleanup(0);
 
-		case OPT_SUFFIX:
-			/* The value has already been set by popt, but
-			 * we need to remember that a suffix was specified
-			 * in case a backup-directory is used. */
-			suffix_specified = 1;
-			break;
-
 		case OPT_MODIFY_WINDOW:
 			/* The value has already been set by popt, but
 			 * we need to remember that we're using a
@@ -543,10 +537,10 @@
 			 * rprintf?  Everybody who gets this message
 			 * ought to send it to the client and also to
 			 * the logs. */
-			snprintf(err_buf,sizeof(err_buf),
+			snprintf(err_buf, sizeof err_buf,
 				 "hard links are not supported on this %s\n",
 				 am_server ? "server" : "client");
-			rprintf(FERROR,"ERROR: hard links not supported on this platform\n");
+			rprintf(FERROR, "ERROR: %s", err_buf);
 			return 0;
 #endif /* SUPPORT_HARD_LINKS */
 			break;
@@ -588,10 +582,10 @@
 			link_dest = 1;
 			break;
 #else
-			snprintf(err_buf,sizeof(err_buf),
+			snprintf(err_buf, sizeof err_buf,
 				 "hard links are not supported on this %s\n",
 				 am_server ? "server" : "client");
-			rprintf(FERROR,"ERROR: hard links not supported on this platform\n");
+			rprintf(FERROR, "ERROR: %s", err_buf);
 			return 0;
 #endif
 
@@ -609,19 +603,15 @@
 	}
 
 	if (write_batch && read_batch) {
-		snprintf(err_buf,sizeof(err_buf),
-			 "write-batch and read-batch can not be used together\n");
-		rprintf(FERROR,"ERROR: write-batch and read-batch"
-			" can not be used together\n");
-		return 0;
+		rprintf(FERROR,
+			"write-batch and read-batch can not be used together\n");
+		exit_cleanup(RERR_SYNTAX);
 	}
 
 	if (do_compression && (write_batch || read_batch)) {
-		snprintf(err_buf,sizeof(err_buf),
-			 "compress can not be used with write-batch or read-batch\n");
-		rprintf(FERROR,"ERROR: compress can not be used with"
-			"  write-batch or read-batch\n");
-		return 0;
+		rprintf(FERROR,
+			"compress can not be used with write-batch or read-batch\n");
+		exit_cleanup(RERR_SYNTAX);
 	}
 
 	if (archive_mode) {
@@ -640,6 +630,17 @@
 	if (relative_paths < 0)
 		relative_paths = files_from? 1 : 0;
 
+	if (!backup_suffix)
+		backup_suffix = backup_dir? "" : BACKUP_SUFFIX;
+	backup_suffix_len = strlen(backup_suffix);
+	if (backup_dir)
+		backup_dir_len = strlen(backup_dir);
+	else if (!backup_suffix_len) {
+		rprintf(FERROR,
+			"--suffix cannot be a null string without --backup-dir\n");
+		exit_cleanup(RERR_SYNTAX);
+	}
+
 	*argv = poptGetArgs(pc);
 	if (*argv)
 		*argc = count_args(*argv);
@@ -813,7 +814,13 @@
 		args[ac++] = bw;
 	}
 
-	if (strcmp(backup_suffix, BACKUP_SUFFIX)) {
+	if (backup_dir) {
+		args[ac++] = "--backup-dir";
+		args[ac++] = backup_dir;
+	}
+
+	/* Only send --suffix if it specifies a non-default value. */
+	if (strcmp(backup_suffix, backup_dir? "" : BACKUP_SUFFIX) != 0) {
 		args[ac++] = "--suffix";
 		args[ac++] = backup_suffix;
 	}
@@ -863,14 +870,6 @@
 	if (tmpdir) {
 		args[ac++] = "--temp-dir";
 		args[ac++] = tmpdir;
-	}
-
-	if (backup_dir && am_sender) {
-		/* only the receiver needs this option, if we are the sender
-		 *   then we need to send it to the receiver.
-		 */
-		args[ac++] = "--backup-dir";
-		args[ac++] = backup_dir;
 	}
 
 	if (compare_dest && am_sender) {
Index: receiver.c
--- receiver.c	8 Jul 2003 16:49:10 -0000	1.47
+++ receiver.c	1 Aug 2003 07:55:44 -0000
@@ -36,7 +36,9 @@
 extern char *compare_dest;
 extern int make_backups;
 extern int do_progress;
+extern char *backup_dir;
 extern char *backup_suffix;
+extern int backup_suffix_len;
 
 static struct delete_list {
 	DEV64_T dev;
@@ -80,26 +82,33 @@
 		rprintf(FINFO,"added %s to delete list\n", f_name(file));
 }
 
-static void delete_one(struct file_struct *f)
+static void delete_one(char *fn, int is_dir)
 {
-	if (!S_ISDIR(f->mode)) {
-		if (robust_unlink(f_name(f)) != 0) {
-			rprintf(FERROR,"delete_one: unlink %s: %s\n",f_name(f),strerror(errno));
+	if (!is_dir) {
+		if (robust_unlink(fn) != 0) {
+			rprintf(FERROR, "delete_one: unlink %s: %s\n",
+				fn, strerror(errno));
 		} else if (verbose) {
-			rprintf(FINFO,"deleting %s\n",f_name(f));
+			rprintf(FINFO, "deleting %s\n", fn);
 		}
 	} else {    
-		if (do_rmdir(f_name(f)) != 0) {
-			if (errno != ENOTEMPTY && errno != EEXIST)
-				rprintf(FERROR,"delete_one: rmdir %s: %s\n",
-                                        f_name(f), strerror(errno));
+		if (do_rmdir(fn) != 0) {
+			if (errno != ENOTEMPTY && errno != EEXIST) {
+				rprintf(FERROR, "delete_one: rmdir %s: %s\n",
+                                        fn, strerror(errno));
+			}
 		} else if (verbose) {
-			rprintf(FINFO,"deleting directory %s\n",f_name(f));      
+			rprintf(FINFO, "deleting directory %s\n", fn);
 		}
 	}
 }
 
 
+static int is_backup_file(char *fn)
+{
+	int k = strlen(fn) - backup_suffix_len;
+	return k > 0 && strcmp(fn+k, backup_suffix) == 0;
+}
 
 
 /* this deletes any files on the receiving side that are not present
@@ -148,14 +157,14 @@
 				add_delete_entry(local_file_list->files[i]);
 			if (-1 == flist_find(flist,local_file_list->files[i])) {
 				char *f = f_name(local_file_list->files[i]);
-				int k = strlen(f) - strlen(backup_suffix);
-/* Hi Andrew, do we really need to play with backup_suffix here? */
-				if (make_backups && ((k <= 0) ||
-					    (strcmp(f+k,backup_suffix) != 0))) {
+				if (make_backups && (backup_dir || !is_backup_file(f))) {
 					(void) make_backup(f);
+					if (verbose)
+						rprintf(FINFO, "deleting %s\n", f);
 				} else {
+					int mode = local_file_list->files[i]->mode;
+					delete_one(f, S_ISDIR(mode) != 0);
 					deletion_count++;
-					delete_one(local_file_list->files[i]);
 				}
 			}
 		}
