summaryrefslogtreecommitdiff
path: root/adb/file_sync_client.cpp
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2016-02-25 17:12:45 -0800
committerJosh Gao <jmgao@google.com>2016-03-03 15:46:50 -0800
commita63b17f76c54d937c779848ae3f4212539f8873f (patch)
tree61f9bb18ce16254e7c2ea10a9fb7f049709bd063 /adb/file_sync_client.cpp
parentd382d2bb5176a21bf1265ff2f80fbeaf9bfdce63 (diff)
adb: fix directory creation logic.
Previously, for `adb pull $remote $local`, we would do the equivalent of mkdir -p on `dirname $local`. This patch changes the behavior to only creating directories that are being pulled, like scp. Bug: http://b/27362811 Change-Id: I79f975ee9f2d9bc9e8be6a7c4f2de6d7ae2d2d23 (cherry picked from commit 71728ca300d1bc168fae89c8139e72db3d4591cb)
Diffstat (limited to 'adb/file_sync_client.cpp')
-rw-r--r--adb/file_sync_client.cpp27
1 files changed, 6 insertions, 21 deletions
diff --git a/adb/file_sync_client.cpp b/adb/file_sync_client.cpp
index 85aaa61413..3a81ce6aca 100644
--- a/adb/file_sync_client.cpp
+++ b/adb/file_sync_client.cpp
@@ -517,12 +517,6 @@ static bool sync_recv(SyncConnection& sc, const char* rpath, const char* lpath)
if (!sc.SendRequest(ID_RECV, rpath)) return false;
adb_unlink(lpath);
- const std::string dirpath = adb_dirname(lpath);
- if (!mkdirs(dirpath.c_str())) {
- sc.Error("failed to create parent directory '%s': %s", dirpath.c_str(), strerror(errno));
- return false;
- }
-
int lfd = adb_creat(lpath, 0644);
if (lfd < 0) {
sc.Error("cannot create '%s': %s", lpath, strerror(errno));
@@ -803,13 +797,14 @@ static bool remote_symlink_isdir(SyncConnection& sc, const std::string& rpath) {
return S_ISDIR(mode);
}
-static bool remote_build_list(SyncConnection& sc,
- std::vector<copyinfo>* file_list,
- const std::string& rpath,
- const std::string& lpath) {
+static bool remote_build_list(SyncConnection& sc, std::vector<copyinfo>* file_list,
+ const std::string& rpath, const std::string& lpath) {
std::vector<copyinfo> dirlist;
std::vector<copyinfo> linklist;
- bool empty_dir = true;
+
+ // Add an entry for the current directory to ensure it gets created before pulling its contents.
+ copyinfo ci(adb_dirname(lpath), adb_dirname(rpath), adb_basename(rpath), S_IFDIR);
+ file_list->push_back(ci);
// Put the files/dirs in rpath on the lists.
auto callback = [&](unsigned mode, unsigned size, unsigned time, const char* name) {
@@ -817,9 +812,6 @@ static bool remote_build_list(SyncConnection& sc,
return;
}
- // We found a child that isn't '.' or '..'.
- empty_dir = false;
-
copyinfo ci(lpath, rpath, name, mode);
if (S_ISDIR(mode)) {
dirlist.push_back(ci);
@@ -836,13 +828,6 @@ static bool remote_build_list(SyncConnection& sc,
return false;
}
- // Add the current directory to the list if it was empty, to ensure that it gets created.
- if (empty_dir) {
- copyinfo ci(adb_dirname(lpath), adb_dirname(rpath), adb_basename(rpath), S_IFDIR);
- file_list->push_back(ci);
- return true;
- }
-
// Check each symlink we found to see whether it's a file or directory.
for (copyinfo& link_ci : linklist) {
if (remote_symlink_isdir(sc, link_ci.rpath)) {