btrfs-progs: restore: use long option for the path regex

Current way of specifying the path to match is not very comfortable, but
the feature itself is very useful. Let's save the short option -m for a
more user friendly syntax and keep a long option --path-regex with the
current syntax.

CC: Peter Stuge <peter@stuge.se>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
This commit is contained in:
David Sterba 2013-05-16 00:26:04 +02:00
parent 65b01dcc5a
commit f6e4a423eb

View File

@ -32,6 +32,7 @@
#include <lzo/lzo1x.h> #include <lzo/lzo1x.h>
#include <zlib.h> #include <zlib.h>
#include <regex.h> #include <regex.h>
#include <getopt.h>
#include "ctree.h" #include "ctree.h"
#include "disk-io.h" #include "disk-io.h"
@ -967,6 +968,11 @@ out:
return ret; return ret;
} }
static struct option long_options[] = {
{ "path-regex", 1, NULL, 256},
{ 0, 0, 0, 0}
};
const char * const cmd_restore_usage[] = { const char * const cmd_restore_usage[] = {
"btrfs restore [options] <device>", "btrfs restore [options] <device>",
"Try to restore files from a damaged filesystem (unmounted)", "Try to restore files from a damaged filesystem (unmounted)",
@ -979,6 +985,10 @@ const char * const cmd_restore_usage[] = {
"-f <offset> filesystem location", "-f <offset> filesystem location",
"-u <block> super mirror", "-u <block> super mirror",
"-d find dir", "-d find dir",
"--path-regex <regex>",
" restore only filenames matching regex,",
" you have to use following syntax (possibly quoted):",
" ^/(|home(|/username(|/Desktop(|/.*))))$",
NULL NULL
}; };
@ -993,6 +1003,7 @@ int cmd_restore(int argc, char **argv)
int len; int len;
int ret; int ret;
int opt; int opt;
int option_index = 0;
int super_mirror = 0; int super_mirror = 0;
int find_dir = 0; int find_dir = 0;
int list_roots = 0; int list_roots = 0;
@ -1001,7 +1012,8 @@ int cmd_restore(int argc, char **argv)
regex_t match_reg, *mreg = NULL; regex_t match_reg, *mreg = NULL;
char reg_err[256]; char reg_err[256];
while ((opt = getopt(argc, argv, "sviot:u:df:r:lcm:")) != -1) { while ((opt = getopt_long(argc, argv, "sviot:u:df:r:lc", long_options,
&option_index)) != -1) {
switch (opt) { switch (opt) {
case 's': case 's':
@ -1059,7 +1071,8 @@ int cmd_restore(int argc, char **argv)
case 'c': case 'c':
match_cflags |= REG_ICASE; match_cflags |= REG_ICASE;
break; break;
case 'm': /* long option without single letter alternative */
case 256:
match_regstr = optarg; match_regstr = optarg;
break; break;
default: default: