Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 070c0302 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

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

parents 993d07fc 76b64ba8
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -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());

+12 −0
Original line number Diff line number Diff line
@@ -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()