diff options
| author | Christopher Tate <ctate@google.com> | 2011-06-01 17:56:23 -0700 |
|---|---|---|
| committer | Christopher Tate <ctate@google.com> | 2011-06-01 17:56:23 -0700 |
| commit | c9cd3b976111d91ede6cd88bd06eb57b10b2f0e7 (patch) | |
| tree | 08aaa6eebb9655ea69d56c4eb8e2849b98d46e1a /adb/commandline.c | |
| parent | 211ce1343267155ce5092f3ad7fd3b27bb106475 (diff) | |
| download | system_core-c9cd3b976111d91ede6cd88bd06eb57b10b2f0e7.tar.gz system_core-c9cd3b976111d91ede6cd88bd06eb57b10b2f0e7.tar.bz2 system_core-c9cd3b976111d91ede6cd88bd06eb57b10b2f0e7.zip | |
Make 'adb backup' -f handling more bulletproof and more flexible
* "adb backup" as the entire command line no longer crashes
* The "-f filename" option can now appear anywhere in the command line.
A trailing "-f" at EOL prompts an error message and usage summary.
Change-Id: I040ed73c2ca3687e265e35600eb3ab2b3c879695
Diffstat (limited to 'adb/commandline.c')
| -rw-r--r-- | adb/commandline.c | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/adb/commandline.c b/adb/commandline.c index 460120e8..2dc86f27 100644 --- a/adb/commandline.c +++ b/adb/commandline.c @@ -131,8 +131,8 @@ void help() "\n" " adb backup [-f <file>] [-apk|-noapk] [-shared|-noshared] [-all] [<packages...>]\n" " - Write a tarfile backup of the device's data to <file>.\n" - " The -f option must come first; if not specified then the data\n" - " is written to \"backup.tar\" in the current directory.\n" + " If a -f option is not supplied then the data is\n" + " written to \"backup.tar\" in the current directory.\n" " (-apk|-noapk enable/disable backup of the .apks themselves\n" " in the tarfile; the default is noapk.)\n" " (-shared|-noshared enable/disable backup of the device's\n" @@ -241,6 +241,7 @@ static void read_and_dump(int fd) static void copy_to_file(int inFd, int outFd) { char buf[4096]; int len; + long total = 0; D("copy_to_file(%d -> %d)\n", inFd, outFd); for (;;) { @@ -254,7 +255,9 @@ static void copy_to_file(int inFd, int outFd) { break; } adb_write(outFd, buf, len); + total += len; } + D("copy_to_file() finished after %lu bytes\n", total); } static void *stdin_read_thread(void *x) @@ -568,12 +571,25 @@ static int backup(int argc, char** argv) { char buf[4096]; const char* filename = "./backup.tar"; int fd, outFd; + int i, j; - if (!strcmp("-f", argv[1])) { - if (argc < 3) return usage(); - filename = argv[2]; - argc -= 2; - argv += 2; + /* bare "adb backup" is not a valid command */ + if (argc < 2) return usage(); + + /* find, extract, and use any -f argument */ + for (i = 1; i < argc; i++) { + if (!strcmp("-f", argv[i])) { + if (i == argc-1) { + fprintf(stderr, "adb: -f passed with no filename\n"); + return usage(); + } + filename = argv[i+1]; + for (j = i+2; j <= argc; ) { + argv[i++] = argv[j++]; + } + argc -= 2; + argv[argc] = NULL; + } } outFd = adb_open_mode(filename, O_WRONLY | O_CREAT | O_TRUNC, 0640); |
