Re: openrsync add --max-size and --min-size support
Claudio Jeker(cje...@diehard.n-r-g.com) on 2021.10.28 17:36:27 +0200: > This diff should implement --max-size and --min-size almost equivalent to > GNU rsync. I decided to use scan_scaled() instead of building something > new that handles all the extra bits GNU rsync has. > The remote rsync process gets the sizes in bytes so scaling is just a > local issue. > > Manpage probably needs more love. rsync does not print a message about skipping a file, should we. ok benno@ > -- > :wq Claudio > > Index: Makefile > === > RCS file: /cvs/src/usr.bin/rsync/Makefile,v > retrieving revision 1.12 > diff -u -p -r1.12 Makefile > --- Makefile 22 Oct 2021 11:10:34 - 1.12 > +++ Makefile 28 Oct 2021 14:06:07 - > @@ -4,8 +4,8 @@ PROG= openrsync > SRCS=blocks.c client.c copy.c downloader.c fargs.c flist.c hash.c > ids.c \ > io.c log.c main.c misc.c mkpath.c mktemp.c receiver.c rmatch.c \ > rules.c sender.c server.c session.c socket.c symlinks.c uploader.c > -LDADD+= -lcrypto -lm > -DPADD+= ${LIBCRYPTO} ${LIBM} > +LDADD+= -lcrypto -lm -lutil > +DPADD+= ${LIBCRYPTO} ${LIBM} ${LIBUTIL} > MAN= openrsync.1 > > CFLAGS+= -Wall -Wextra > Index: extern.h > === > RCS file: /cvs/src/usr.bin/rsync/extern.h,v > retrieving revision 1.42 > diff -u -p -r1.42 extern.h > --- extern.h 22 Oct 2021 11:10:34 - 1.42 > +++ extern.h 28 Oct 2021 13:59:20 - > @@ -141,6 +141,8 @@ structopts { > int numeric_ids; /* --numeric-ids */ > int one_file_system; /* -x */ > int alt_base_mode; > + off_tmax_size; /* --max-size */ > + off_tmin_size; /* --min-size */ > char*rsync_path;/* --rsync-path */ > char*ssh_prog; /* --rsh or -e */ > char*port; /* --port */ > Index: fargs.c > === > RCS file: /cvs/src/usr.bin/rsync/fargs.c,v > retrieving revision 1.20 > diff -u -p -r1.20 fargs.c > --- fargs.c 22 Oct 2021 11:10:34 - 1.20 > +++ fargs.c 28 Oct 2021 14:09:23 - > @@ -131,6 +131,10 @@ fargs_cmdline(struct sess *sess, const s > if (!sess->opts->specials && sess->opts->devices) > /* --devices is sent as -D --no-specials */ > addargs(, "--no-specials"); > + if (sess->opts->max_size >= 0) > + addargs(, "--max-size=%lld", sess->opts->max_size); > + if (sess->opts->min_size >= 0) > + addargs(, "--min-size=%lld", sess->opts->min_size); > > /* only add --compare-dest, etc if this is the sender */ > if (sess->opts->alt_base_mode != 0 && > Index: main.c > === > RCS file: /cvs/src/usr.bin/rsync/main.c,v > retrieving revision 1.61 > diff -u -p -r1.61 main.c > --- main.c28 Oct 2021 13:07:43 - 1.61 > +++ main.c28 Oct 2021 15:17:39 - > @@ -26,6 +26,7 @@ > #include > #include > #include > +#include > > #include "extern.h" > > @@ -341,7 +342,7 @@ main(int argc, char *argv[]) > pid_tchild; > int fds[2], sd = -1, rc, c, st, i, lidx; > size_t basedir_cnt = 0; > - struct sess sess; > + struct sess sess; > struct fargs*fargs; > char**args; > const char *errstr; > @@ -352,6 +353,8 @@ main(int argc, char *argv[]) > NULL) == -1) > err(ERR_IPC, "pledge"); > > + opts.max_size = opts.min_size = -1; > + > while ((c = getopt_long(argc, argv, "Dae:ghlnoprtvxz", lopts, )) > != -1) { > switch (c) { > @@ -472,8 +475,12 @@ basedir: > opts.basedir[basedir_cnt++] = optarg; > break; > case OP_MAX_SIZE: > + if (scan_scaled(optarg, _size) == -1) > + err(1, "bad max-size"); > + break; > case OP_MIN_SIZE: > - /* for now simply ignore */ > + if (scan_scaled(optarg, _size) == -1) > + err(1, "bad min-size"); > break; > case OP_VERSION: > fprintf(stderr, "openrsync: protocol version %u\n", > Index: rsync.1 > === > RCS file: /cvs/src/usr.bin/rsync/rsync.1,v > retrieving revision 1.27 > diff -u -p -r1.27 rsync.1 > --- rsync.1 22 Oct 2021 16:42:28 - 1.27 > +++ rsync.1 28 Oct 2021 15:29:42 - > @@ -31,6 +31,8 @@ > .Op Fl -exclude-from Ns = Ns Ar file > .Op Fl -include Ar pattern > .Op Fl -include-from Ns = Ns Ar file > +.Op Fl -max-size Ns
openrsync add --max-size and --min-size support
This diff should implement --max-size and --min-size almost equivalent to GNU rsync. I decided to use scan_scaled() instead of building something new that handles all the extra bits GNU rsync has. The remote rsync process gets the sizes in bytes so scaling is just a local issue. Manpage probably needs more love. -- :wq Claudio Index: Makefile === RCS file: /cvs/src/usr.bin/rsync/Makefile,v retrieving revision 1.12 diff -u -p -r1.12 Makefile --- Makefile22 Oct 2021 11:10:34 - 1.12 +++ Makefile28 Oct 2021 14:06:07 - @@ -4,8 +4,8 @@ PROG= openrsync SRCS= blocks.c client.c copy.c downloader.c fargs.c flist.c hash.c ids.c \ io.c log.c main.c misc.c mkpath.c mktemp.c receiver.c rmatch.c \ rules.c sender.c server.c session.c socket.c symlinks.c uploader.c -LDADD+= -lcrypto -lm -DPADD+= ${LIBCRYPTO} ${LIBM} +LDADD+= -lcrypto -lm -lutil +DPADD+= ${LIBCRYPTO} ${LIBM} ${LIBUTIL} MAN= openrsync.1 CFLAGS+= -Wall -Wextra Index: extern.h === RCS file: /cvs/src/usr.bin/rsync/extern.h,v retrieving revision 1.42 diff -u -p -r1.42 extern.h --- extern.h22 Oct 2021 11:10:34 - 1.42 +++ extern.h28 Oct 2021 13:59:20 - @@ -141,6 +141,8 @@ struct opts { int numeric_ids; /* --numeric-ids */ int one_file_system; /* -x */ int alt_base_mode; + off_tmax_size; /* --max-size */ + off_tmin_size; /* --min-size */ char*rsync_path;/* --rsync-path */ char*ssh_prog; /* --rsh or -e */ char*port; /* --port */ Index: fargs.c === RCS file: /cvs/src/usr.bin/rsync/fargs.c,v retrieving revision 1.20 diff -u -p -r1.20 fargs.c --- fargs.c 22 Oct 2021 11:10:34 - 1.20 +++ fargs.c 28 Oct 2021 14:09:23 - @@ -131,6 +131,10 @@ fargs_cmdline(struct sess *sess, const s if (!sess->opts->specials && sess->opts->devices) /* --devices is sent as -D --no-specials */ addargs(, "--no-specials"); + if (sess->opts->max_size >= 0) + addargs(, "--max-size=%lld", sess->opts->max_size); + if (sess->opts->min_size >= 0) + addargs(, "--min-size=%lld", sess->opts->min_size); /* only add --compare-dest, etc if this is the sender */ if (sess->opts->alt_base_mode != 0 && Index: main.c === RCS file: /cvs/src/usr.bin/rsync/main.c,v retrieving revision 1.61 diff -u -p -r1.61 main.c --- main.c 28 Oct 2021 13:07:43 - 1.61 +++ main.c 28 Oct 2021 15:17:39 - @@ -26,6 +26,7 @@ #include #include #include +#include #include "extern.h" @@ -341,7 +342,7 @@ main(int argc, char *argv[]) pid_tchild; int fds[2], sd = -1, rc, c, st, i, lidx; size_t basedir_cnt = 0; - struct sess sess; + struct sess sess; struct fargs*fargs; char**args; const char *errstr; @@ -352,6 +353,8 @@ main(int argc, char *argv[]) NULL) == -1) err(ERR_IPC, "pledge"); + opts.max_size = opts.min_size = -1; + while ((c = getopt_long(argc, argv, "Dae:ghlnoprtvxz", lopts, )) != -1) { switch (c) { @@ -472,8 +475,12 @@ basedir: opts.basedir[basedir_cnt++] = optarg; break; case OP_MAX_SIZE: + if (scan_scaled(optarg, _size) == -1) + err(1, "bad max-size"); + break; case OP_MIN_SIZE: - /* for now simply ignore */ + if (scan_scaled(optarg, _size) == -1) + err(1, "bad min-size"); break; case OP_VERSION: fprintf(stderr, "openrsync: protocol version %u\n", Index: rsync.1 === RCS file: /cvs/src/usr.bin/rsync/rsync.1,v retrieving revision 1.27 diff -u -p -r1.27 rsync.1 --- rsync.1 22 Oct 2021 16:42:28 - 1.27 +++ rsync.1 28 Oct 2021 15:29:42 - @@ -31,6 +31,8 @@ .Op Fl -exclude-from Ns = Ns Ar file .Op Fl -include Ar pattern .Op Fl -include-from Ns = Ns Ar file +.Op Fl -max-size Ns = Ns size +.Op Fl -min-size Ns = Ns size .Op Fl -no-motd .Op Fl -numeric-ids .Op Fl -port Ns = Ns Ar service @@ -127,6 +129,22 @@ set the numeric group ID to match the so Also transfer symbolic links. The link is transferred as a standalone file: if the destination does not