How about a --min-size option, next to --max-size

Paul Slootman paul at debian.org
Thu Apr 28 15:47:57 GMT 2005


On Thu 28 Apr 2005, Paul Slootman wrote:
> 
> Well, I had no protests, so here's the patch :-)

... and I promptly found a problem with it (didn't pass the --min-size
option to the remote end), so here's a revised one.

Paul Slootman
-------------- next part --------------
diff -ru rsync-2.6.4/generator.c rsync-2.6.4.min-size/generator.c
--- rsync-2.6.4/generator.c	2005-04-28 17:13:57.000000000 +0200
+++ rsync-2.6.4.min-size/generator.c	2005-04-28 17:11:24.000000000 +0200
@@ -58,6 +58,7 @@
 extern int ignore_times;
 extern int size_only;
 extern OFF_T max_size;
+extern OFF_T min_size;
 extern int io_timeout;
 extern int io_error;
 extern int sock_f_out;
@@ -728,6 +729,13 @@
 		}
 		return;
 	}
+	if (min_size && S_ISREG(file->mode) && file->length < min_size) {
+		if (verbose > 1) {
+			rprintf(FINFO, "%s is under min-size\n",
+				safe_fname(fname));
+		}
+		return;
+	}
 
 	if (preserve_links && S_ISLNK(file->mode)) {
 #ifdef SUPPORT_LINKS
@@ -1204,7 +1212,7 @@
 
 	phase++;
 	csum_length = SUM_LENGTH;
-	only_existing = max_size = opt_ignore_existing = 0;
+	only_existing = min_size = max_size = opt_ignore_existing = 0;
 	update_only = always_checksum = size_only = 0;
 	ignore_times = 1;
 	make_backups = 0; /* avoid a duplicate backup for inplace processing */
diff -ru rsync-2.6.4/options.c rsync-2.6.4.min-size/options.c
--- rsync-2.6.4/options.c	2005-04-28 17:13:57.000000000 +0200
+++ rsync-2.6.4.min-size/options.c	2005-04-28 17:44:51.000000000 +0200
@@ -98,6 +98,7 @@
 int need_messages_from_generator = 0;
 int max_delete = 0;
 OFF_T max_size = 0;
+OFF_T min_size = 0;
 int ignore_errors = 0;
 int modify_window = 0;
 int blocking_io = -1;
@@ -165,7 +166,7 @@
 static int itemize_changes = 0;
 static int refused_delete, refused_archive_part;
 static int refused_partial, refused_progress, refused_delete_before;
-static char *max_size_arg;
+static char *max_size_arg, *min_size_arg;
 static char partialdir_for_delayupdate[] = ".~tmp~";
 
 /** Local address to bind.  As a character string because it's
@@ -306,6 +307,7 @@
   rprintf(F,"     --ignore-errors         delete even if there are I/O errors\n");
   rprintf(F,"     --force                 force deletion of directories even if not empty\n");
   rprintf(F,"     --max-delete=NUM        don't delete more than NUM files\n");
+  rprintf(F,"     --min-size=SIZE         don't transfer any file smaller than SIZE\n");
   rprintf(F,"     --max-size=SIZE         don't transfer any file larger than SIZE\n");
   rprintf(F,"     --partial               keep partially transferred files\n");
   rprintf(F,"     --partial-dir=DIR       put a partially transferred file into DIR\n");
@@ -360,7 +362,7 @@
 enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
       OPT_FILTER, 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,
+      OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT, OPT_MAX_SIZE, OPT_MIN_SIZE,
       OPT_REFUSED_BASE = 9000};
 
 static struct poptOption long_options[] = {
@@ -424,6 +426,7 @@
   {"block-size",      'B', POPT_ARG_LONG,   &block_size, 0, 0, 0 },
   {"max-delete",       0,  POPT_ARG_INT,    &max_delete, 0, 0, 0 },
   {"max-size",         0,  POPT_ARG_STRING, &max_size_arg,  OPT_MAX_SIZE, 0, 0 },
+  {"min-size",         0,  POPT_ARG_STRING, &min_size_arg,  OPT_MIN_SIZE, 0, 0 },
   {"timeout",          0,  POPT_ARG_INT,    &io_timeout, OPT_TIMEOUT, 0, 0 },
   {"temp-dir",        'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
   {"compare-dest",     0,  POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
@@ -618,6 +621,35 @@
 }
 
 
+static OFF_T get_size_arg(char *size_arg)
+{ 
+	OFF_T size;
+	char *arg;
+
+	for (arg = size_arg; isdigit(*(uchar*)arg); arg++) {}
+	if (*arg == '.')
+		for (arg++; isdigit(*(uchar*)arg); arg++) {}
+	switch (toupper(*arg)) {
+	case 'K':
+		size = atof(size_arg) * 1024;
+		break;
+	case 'M':
+		size = atof(size_arg) * 1024*1024;
+		break;
+	case 'G':
+		size = atof(size_arg) * 1024*1024*1024;
+		break;
+	case '\0':
+		size = atof(size_arg);
+		break;
+	default:
+		size = 0;
+		break;
+	}
+	return size;
+}
+
+
 static void create_refuse_error(int which)
 {
 	/* The "which" value is the index + OPT_REFUSED_BASE. */
@@ -798,26 +830,7 @@
 			break;
 
 		case OPT_MAX_SIZE:
-			for (arg = max_size_arg; isdigit(*(uchar*)arg); arg++) {}
-			if (*arg == '.')
-				for (arg++; isdigit(*(uchar*)arg); arg++) {}
-			switch (*arg) {
-			case 'k': case 'K':
-				max_size = atof(max_size_arg) * 1024;
-				break;
-			case 'm': case 'M':
-				max_size = atof(max_size_arg) * 1024*1024;
-				break;
-			case 'g': case 'G':
-				max_size = atof(max_size_arg) * 1024*1024*1024;
-				break;
-			case '\0':
-				max_size = atof(max_size_arg);
-				break;
-			default:
-				max_size = 0;
-				break;
-			}
+			max_size = get_size_arg(max_size_arg);
 			if (max_size <= 0) {
 				snprintf(err_buf, sizeof err_buf,
 					"--max-size value is invalid: %s\n",
@@ -826,6 +839,16 @@
 			}
 			break;
 
+		case OPT_MIN_SIZE:
+			min_size = get_size_arg(min_size_arg);
+			if (min_size <= 0) {
+				snprintf(err_buf, sizeof err_buf,
+					"--min-size value is invalid: %s\n",
+					min_size_arg);
+				return 0;
+			}
+			break;
+
 		case OPT_TIMEOUT:
 			if (io_timeout && io_timeout < select_timeout)
 				select_timeout = io_timeout;
@@ -1336,6 +1359,11 @@
 		args[ac++] = max_size_arg;
 	}
 
+	if (min_size && am_sender) {
+		args[ac++] = "--min-size";
+		args[ac++] = min_size_arg;
+	}
+
 	if (io_timeout) {
 		if (asprintf(&arg, "--timeout=%d", io_timeout) < 0)
 			goto oom;
diff -ru rsync-2.6.4/rsync.yo rsync-2.6.4.min-size/rsync.yo
--- rsync-2.6.4/rsync.yo	2005-03-31 05:14:09.000000000 +0200
+++ rsync-2.6.4.min-size/rsync.yo	2005-04-28 17:13:29.000000000 +0200
@@ -341,6 +341,7 @@
      --ignore-errors         delete even if there are I/O errors
      --force                 force deletion of dirs even if not empty
      --max-delete=NUM        don't delete more than NUM files
+     --min-size=SIZE         don't transfer any file smaller than SIZE
      --max-size=SIZE         don't transfer any file larger than SIZE
      --partial               keep partially transferred files
      --partial-dir=DIR       put a partially transferred file into DIR
@@ -754,6 +755,13 @@
 files or directories (NUM must be non-zero).
 This is useful when mirroring very large trees to prevent disasters.
 
+dit(bf(--min-size=SIZE)) This tells rsync to avoid transferring any
+file that is smaller than the specified SIZE. The SIZE value can be
+suffixed with a letter to indicate a size multiplier (K, M, or G) and
+may be a fractional value (e.g. "bf(--max-size=1.5m)").
+This can help in not transferring small junk files.
+This only affects regular files, not e.g. device nodes or symbolic links.
+
 dit(bf(--max-size=SIZE)) This tells rsync to avoid transferring any
 file that is larger than the specified SIZE. The SIZE value can be
 suffixed with a letter to indicate a size multiplier (K, M, or G) and


More information about the rsync mailing list