Add a --max-size option.
[rsync/rsync-patches.git] / max-size.diff
1 --- generator.c 11 Jun 2004 07:40:51 -0000      1.87
2 +++ generator.c 15 Jun 2004 15:35:48 -0000
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
23 +++ options.c   15 Jun 2004 15:35:48 -0000
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
40 @@ -310,7 +312,7 @@ void usage(enum logcode F)
41  enum {OPT_VERSION = 1000, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
42        OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_LINK_DEST,
43        OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
44 -      OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT,
45 +      OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT, OPT_MAX_SIZE,
46        OPT_REFUSED_BASE = 9000};
47  
48  static struct poptOption long_options[] = {
49 @@ -364,6 +366,7 @@ static struct poptOption long_options[] 
50    {"rsh",             'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 },
51    {"block-size",      'B', POPT_ARG_INT,    &block_size, 0, 0, 0 },
52    {"max-delete",       0,  POPT_ARG_INT,    &max_delete, 0, 0, 0 },
53 +  {"max-size",         0,  POPT_ARG_STRING, &max_size_arg,  OPT_MAX_SIZE, 0, 0 },
54    {"timeout",          0,  POPT_ARG_INT,    &io_timeout, OPT_TIMEOUT, 0, 0 },
55    {"temp-dir",        'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
56    {"compare-dest",     0,  POPT_ARG_STRING, &compare_dest, 0, 0, 0 },
57 @@ -580,6 +583,32 @@ int parse_arguments(int *argc, const cha
58                         checksum_seed = FIXED_CHECKSUM_SEED;
59                         break;
60  
61 +               case OPT_MAX_SIZE:
62 +                       for (arg = max_size_arg; isdigit(*arg); arg++) {}
63 +                       if (*arg == '.')
64 +                               for (arg++; isdigit(*arg); arg++) {}
65 +                       if (arg == max_size_arg)
66 +                               arg = "?";
67 +                       switch (*arg) {
68 +                       case 'k': case 'K':
69 +                               max_size = atof(max_size_arg) * 1024;
70 +                               break;
71 +                       case 'm': case 'M':
72 +                               max_size = atof(max_size_arg) * 1024*1024;
73 +                               break;
74 +                       case 'g': case 'G':
75 +                               max_size = atof(max_size_arg) * 1024*1024*1024;
76 +                               break;
77 +                       case '\0':
78 +                               break;
79 +                       default:
80 +                               rprintf(FERROR,
81 +                                       "--max-size value is invalid.\n");
82 +                               exit_cleanup(RERR_SYNTAX);
83 +                               break;
84 +                       }
85 +                       break;
86 +
87                 case OPT_TIMEOUT:
88                         if (io_timeout && io_timeout < select_timeout)
89                                 select_timeout = io_timeout;
90 @@ -884,6 +913,11 @@ void server_options(char **args,int *arg
91                 args[ac++] = arg;
92         }
93  
94 +       if (max_size && am_sender) {
95 +               args[ac++] = "--max-size";
96 +               args[ac++] = max_size_arg;
97 +       }
98 +
99         if (batch_prefix) {
100                 char *r_or_w = write_batch ? "write" : "read";
101                 if (asprintf(&arg, "--%s-batch=%s", r_or_w, batch_prefix) < 0)