Some improvements from Chris Shoemaker.
[rsync/rsync-patches.git] / max-size.diff
CommitLineData
7e7fe794 1--- generator.c 11 Jun 2004 07:40:51 -0000 1.87
38037c6b 2+++ generator.c 15 Jun 2004 16:19:44 -0000
7e7fe794
WD
3@@ -39,6 +39,7 @@ extern int opt_ignore_existing;
4 extern int csum_length;
5 extern int ignore_times;
6 extern int size_only;
7+extern OFF_T max_size;
8 extern int io_timeout;
9 extern int protocol_version;
10 extern int always_checksum;
11@@ -345,6 +346,10 @@ void recv_generator(char *fname, struct
12 && verbose && f_out != -1)
13 rprintf(FINFO,"%s/\n",fname);
14 return;
15+ } else if (max_size && file->length > max_size) {
16+ if (verbose > 1)
17+ rprintf(FINFO, "%s is over max-size\n", fname);
18+ return;
19 }
20
21 if (preserve_links && S_ISLNK(file->mode)) {
22--- options.c 7 Jun 2004 22:05:22 -0000 1.156
38037c6b 23+++ options.c 15 Jun 2004 16:19:44 -0000
7e7fe794
WD
24@@ -90,6 +90,7 @@ int delete_after = 0;
25 int only_existing = 0;
26 int opt_ignore_existing = 0;
27 int max_delete = 0;
28+OFF_T max_size = 0;
29 int ignore_errors = 0;
30 int modify_window = 0;
31 int blocking_io = -1;
32@@ -139,6 +140,7 @@ char *batch_prefix = NULL;
33
34 static int daemon_opt; /* sets am_daemon after option error-reporting */
35 static int modify_window_set;
36+static char *max_size_arg;
37
38 /** Local address to bind. As a character string because it's
39 * interpreted by the IPv6 layer: should be a numeric IP4 or ip6
38037c6b
WD
40@@ -260,6 +262,7 @@ void usage(enum logcode F)
41 rprintf(F," --delete-after receiver deletes after transferring, not before\n");
42 rprintf(F," --ignore-errors delete even if there are I/O errors\n");
43 rprintf(F," --max-delete=NUM don't delete more than NUM files\n");
44+ rprintf(F," --max-size=SIZE don't transfer any file larger than SIZE\n");
45 rprintf(F," --partial keep partially transferred files\n");
46 rprintf(F," --force force deletion of directories even if not empty\n");
47 rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
48@@ -310,7 +313,7 @@ void usage(enum logcode F)
7e7fe794
WD
49 enum {OPT_VERSION = 1000, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
50 OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_LINK_DEST,
51 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
52- OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT,
53+ OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT, OPT_MAX_SIZE,
54 OPT_REFUSED_BASE = 9000};
55
56 static struct poptOption long_options[] = {
38037c6b 57@@ -364,6 +367,7 @@ static struct poptOption long_options[]
7e7fe794
WD
58 {"rsh", 'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 },
59 {"block-size", 'B', POPT_ARG_INT, &block_size, 0, 0, 0 },
60 {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 },
61+ {"max-size", 0, POPT_ARG_STRING, &max_size_arg, OPT_MAX_SIZE, 0, 0 },
62 {"timeout", 0, POPT_ARG_INT, &io_timeout, OPT_TIMEOUT, 0, 0 },
63 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
64 {"compare-dest", 0, POPT_ARG_STRING, &compare_dest, 0, 0, 0 },
38037c6b 65@@ -580,6 +584,32 @@ int parse_arguments(int *argc, const cha
7e7fe794
WD
66 checksum_seed = FIXED_CHECKSUM_SEED;
67 break;
68
69+ case OPT_MAX_SIZE:
70+ for (arg = max_size_arg; isdigit(*arg); arg++) {}
71+ if (*arg == '.')
72+ for (arg++; isdigit(*arg); arg++) {}
73+ if (arg == max_size_arg)
74+ arg = "?";
75+ switch (*arg) {
76+ case 'k': case 'K':
77+ max_size = atof(max_size_arg) * 1024;
78+ break;
79+ case 'm': case 'M':
80+ max_size = atof(max_size_arg) * 1024*1024;
81+ break;
82+ case 'g': case 'G':
83+ max_size = atof(max_size_arg) * 1024*1024*1024;
84+ break;
85+ case '\0':
86+ break;
87+ default:
88+ rprintf(FERROR,
89+ "--max-size value is invalid.\n");
90+ exit_cleanup(RERR_SYNTAX);
91+ break;
92+ }
93+ break;
94+
95 case OPT_TIMEOUT:
96 if (io_timeout && io_timeout < select_timeout)
97 select_timeout = io_timeout;
38037c6b 98@@ -884,6 +914,11 @@ void server_options(char **args,int *arg
7e7fe794
WD
99 args[ac++] = arg;
100 }
101
102+ if (max_size && am_sender) {
103+ args[ac++] = "--max-size";
104+ args[ac++] = max_size_arg;
105+ }
106+
107 if (batch_prefix) {
108 char *r_or_w = write_batch ? "write" : "read";
109 if (asprintf(&arg, "--%s-batch=%s", r_or_w, batch_prefix) < 0)
38037c6b
WD
110--- rsync.yo 5 Jun 2004 16:16:30 -0000 1.171
111+++ rsync.yo 15 Jun 2004 16:19:45 -0000
112@@ -315,6 +315,7 @@ verb(
113 --delete-after receiver deletes after transfer, not before
114 --ignore-errors delete even if there are I/O errors
115 --max-delete=NUM don't delete more than NUM files
116+ --max-size=SIZE don't transfer any file larger than SIZE
117 --partial keep partially transferred files
118 --force force deletion of dirs even if not empty
119 --numeric-ids don't map uid/gid values by user/group name
120@@ -577,6 +578,11 @@ dit(bf(--max-delete=NUM)) This tells rsy
121 files or directories. This is useful when mirroring very large trees
122 to prevent disasters.
123
124+dit(bf(--max-size=SIZE)) This tells rsync to avoid transferring any
125+file that is larger than the specified SIZE. The SIZE value can be
126+suffixed with a letter to indicate a size multiplier (K, M, or G) and
127+may be a fractional value (e.g. "--max-size=1.5m").
128+
129 dit(bf(--delete)) This tells rsync to delete any files on the receiving
130 side that aren't on the sending side. Files that are excluded from
131 transfer are excluded from being deleted unless you use --delete-excluded.