adb: added support for adb pull -a to preserve time stamps and mode
Added -a flag to adb pull that preserves time and mode. Mode is
subjected to umask for security. We only receive modification
time from adb server, so creation time will be set to the modification
time as well.
Signed-off-by: Lajos Molnar <lajos@google.com>
(cherry picked from commit de8ff4adcaa487259f9ddcd0eab4d1117d1cca71)
Change-Id: I03bb5cc14ce542299cf3b221a8be318a28ee8a8d
diff --git a/adb/commandline.c b/adb/commandline.c
index 18dc6e0..9cba751 100644
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -110,9 +110,10 @@
" adb push [-p] <local> <remote>\n"
" - copy file/dir to device\n"
" ('-p' to display the transfer progress)\n"
- " adb pull [-p] <remote> [<local>]\n"
+ " adb pull [-p] [-a] <remote> [<local>]\n"
" - copy file/dir from device\n"
" ('-p' to display the transfer progress)\n"
+ " ('-a' means copy timestamp and mode)\n"
" adb sync [ <directory> ] - copy host->device only if changed\n"
" (-l means list but don't copy)\n"
" (see 'adb help all')\n"
@@ -939,12 +940,19 @@
}
-static void parse_push_pull_args(char** arg, int narg, char const** path1, char const** path2,
- int* show_progress) {
+static void parse_push_pull_args(char **arg, int narg, char const **path1, char const **path2,
+ int *show_progress, int *copy_attrs) {
*show_progress = 0;
+ *copy_attrs = 0;
- if ((narg > 0) && !strcmp(*arg, "-p")) {
- *show_progress = 1;
+ while (narg > 0) {
+ if (!strcmp(*arg, "-p")) {
+ *show_progress = 1;
+ } else if (!strcmp(*arg, "-a")) {
+ *copy_attrs = 1;
+ } else {
+ break;
+ }
++arg;
--narg;
}
@@ -1415,9 +1423,10 @@
if(!strcmp(argv[0], "push")) {
int show_progress = 0;
+ int copy_attrs = 0; // unused
const char* lpath = NULL, *rpath = NULL;
- parse_push_pull_args(&argv[1], argc - 1, &lpath, &rpath, &show_progress);
+ parse_push_pull_args(&argv[1], argc - 1, &lpath, &rpath, &show_progress, ©_attrs);
if ((lpath != NULL) && (rpath != NULL)) {
return do_sync_push(lpath, rpath, 0 /* no verify APK */, show_progress);
@@ -1428,12 +1437,13 @@
if(!strcmp(argv[0], "pull")) {
int show_progress = 0;
+ int copy_attrs = 0;
const char* rpath = NULL, *lpath = ".";
- parse_push_pull_args(&argv[1], argc - 1, &rpath, &lpath, &show_progress);
+ parse_push_pull_args(&argv[1], argc - 1, &rpath, &lpath, &show_progress, ©_attrs);
if (rpath != NULL) {
- return do_sync_pull(rpath, lpath, show_progress);
+ return do_sync_pull(rpath, lpath, show_progress, copy_attrs);
}
return usage();