Merge "adb: fix infinite loop when attempting to push to //foo."

This commit is contained in:
Treehugger Robot 2019-09-25 19:59:51 +00:00 committed by Gerrit Code Review
commit 070c030289
2 changed files with 24 additions and 2 deletions

View File

@ -849,6 +849,16 @@ static bool local_build_list(SyncConnection& sc, std::vector<copyinfo>* file_lis
return true;
}
// dirname("//foo") returns "//", so we can't do the obvious `path == "/"`.
static bool is_root_dir(std::string_view path) {
for (char c : path) {
if (c != '/') {
return false;
}
}
return true;
}
static bool copy_local_dir_remote(SyncConnection& sc, std::string lpath,
std::string rpath, bool check_timestamps,
bool list_only) {
@ -862,8 +872,8 @@ static bool copy_local_dir_remote(SyncConnection& sc, std::string lpath,
std::vector<copyinfo> file_list;
std::vector<std::string> directory_list;
for (std::string dirpath = rpath; dirpath != "/"; dirpath = android::base::Dirname(dirpath)) {
directory_list.push_back(dirpath);
for (std::string path = rpath; !is_root_dir(path); path = android::base::Dirname(path)) {
directory_list.push_back(path);
}
std::reverse(directory_list.begin(), directory_list.end());

View File

@ -903,6 +903,18 @@ class FileOperationsTest(DeviceTest):
remote_path += '/filename'
self.device.push(local=tmp_file.name, remote=remote_path)
def test_push_multiple_slash_root(self):
"""Regression test for pushing to //data/local/tmp.
Bug: http://b/141311284
"""
with tempfile.NamedTemporaryFile() as tmp_file:
tmp_file.write('\0' * 1024 * 1024)
tmp_file.flush()
remote_path = '/' + self.DEVICE_TEMP_DIR + '/test_push_multiple_slash_root'
self.device.shell(['rm', '-rf', remote_path])
self.device.push(local=tmp_file.name, remote=remote_path)
def _test_pull(self, remote_file, checksum):
tmp_write = tempfile.NamedTemporaryFile(mode='wb', delete=False)
tmp_write.close()