diff options
Diffstat (limited to 'cmds-receive.c')
-rw-r--r-- | cmds-receive.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/cmds-receive.c b/cmds-receive.c index 8d85ca92..87dc1b4e 100644 --- a/cmds-receive.c +++ b/cmds-receive.c @@ -32,6 +32,7 @@ #include <ftw.h> #include <wait.h> #include <assert.h> +#include <getopt.h> #include <sys/stat.h> #include <sys/types.h> @@ -816,7 +817,8 @@ static struct btrfs_send_ops send_ops = { .utimes = process_utimes, }; -static int do_receive(struct btrfs_receive *r, const char *tomnt, int r_fd) +static int do_receive(struct btrfs_receive *r, const char *tomnt, int r_fd, + u64 max_errors) { int ret; char *dest_dir_full_path; @@ -868,7 +870,8 @@ static int do_receive(struct btrfs_receive *r, const char *tomnt, int r_fd) while (!end) { ret = btrfs_read_and_process_send_stream(r_fd, &send_ops, r, - r->honor_end_cmd); + r->honor_end_cmd, + max_errors); if (ret < 0) goto out; if (ret) @@ -911,6 +914,11 @@ out: return ret; } +static const struct option long_opts[] = { + { "max-errors", 1, NULL, 'E' }, + { NULL, 0, NULL, 0 } +}; + int cmd_receive(int argc, char **argv) { int c; @@ -918,7 +926,7 @@ int cmd_receive(int argc, char **argv) char *fromfile = NULL; struct btrfs_receive r; int receive_fd = fileno(stdin); - + u64 max_errors = 1; int ret; memset(&r, 0, sizeof(r)); @@ -926,7 +934,7 @@ int cmd_receive(int argc, char **argv) r.write_fd = -1; r.dest_dir_fd = -1; - while ((c = getopt(argc, argv, "evf:")) != -1) { + while ((c = getopt_long(argc, argv, "evf:", long_opts, NULL)) != -1) { switch (c) { case 'v': g_verbose++; @@ -937,6 +945,9 @@ int cmd_receive(int argc, char **argv) case 'e': r.honor_end_cmd = 1; break; + case 'E': + max_errors = arg_strtou64(optarg); + break; case '?': default: fprintf(stderr, "ERROR: receive args invalid.\n"); @@ -957,7 +968,7 @@ int cmd_receive(int argc, char **argv) } } - ret = do_receive(&r, tomnt, receive_fd); + ret = do_receive(&r, tomnt, receive_fd, max_errors); return !!ret; } @@ -983,5 +994,8 @@ const char * const cmd_receive_usage[] = { " in the data stream. Without this option,", " the receiver terminates only if an error", " is recognized or on EOF.", + "--max-errors <N> Terminate as soon as N errors happened while", + " processing commands from the send stream.", + " Default value is 1. A value of 0 means no limit.", NULL }; |