2241f2c8fae6da932be0e1a77131956d14852860
[rsync-patches.git] / max-size.diff
1 --- orig/generator.c    2004-07-28 10:05:29
2 +++ generator.c 2004-07-03 20:20:46
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 @@ -336,6 +337,10 @@ static void recv_generator(char *fname, 
12                     && verbose && f_out != -1)
13                         rprintf(FINFO, "%s/\n", safe_fname(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 --- orig/options.c      2004-07-23 17:16:13
23 +++ options.c   2004-07-15 02:34:44
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_name = 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
40 @@ -267,6 +269,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 @@ -317,7 +320,7 @@ void usage(enum logcode F)
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[] = {
57 @@ -372,6 +375,7 @@ static struct poptOption long_options[] 
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 },
65 @@ -586,6 +590,32 @@ int parse_arguments(int *argc, const cha
66                         read_batch = 1;
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;
98 @@ -924,6 +954,11 @@ void server_options(char **args,int *arg
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 (io_timeout) {
108                 if (asprintf(&arg, "--timeout=%d", io_timeout) < 0)
109                         goto oom;
110 --- orig/rsync.yo       2004-07-24 16:52:10
111 +++ rsync.yo    2004-07-03 20:20:46
112 @@ -316,6 +316,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 @@ -592,6 +593,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.