Merge "adb: symlinks to dirs count as dirs for pull destination."

am: 543093cb97

* commit '543093cb97958049d175ecd77d5232659b014f7d':
  adb: symlinks to dirs count as dirs for pull destination.
This commit is contained in:
Josh Gao 2016-03-03 00:50:20 +00:00 committed by android-build-merger
commit 3b198fd8bb
2 changed files with 69 additions and 1 deletions

View file

@ -153,7 +153,9 @@ bool mkdirs(const std::string& path) {
// - Recursive, so it uses stack space relative to number of directory
// components.
if (directory_exists(path)) {
// If path points to a symlink to a directory, that's fine.
struct stat sb;
if (stat(path.c_str(), &sb) != -1 && S_ISDIR(sb.st_mode)) {
return true;
}

View file

@ -845,6 +845,72 @@ class FileOperationsTest(DeviceTest):
if host_dir is not None:
shutil.rmtree(host_dir)
def test_pull_dir_symlink(self):
"""Pull a directory into a symlink to a directory.
Bug: http://b/27362811
"""
if os.name != "posix":
raise unittest.SkipTest('requires POSIX')
try:
host_dir = tempfile.mkdtemp()
real_dir = os.path.join(host_dir, "dir")
symlink = os.path.join(host_dir, "symlink")
os.mkdir(real_dir)
os.symlink(real_dir, symlink)
self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])
self.device.shell(['mkdir', '-p', self.DEVICE_TEMP_DIR])
# Populate device directory with random files.
temp_files = make_random_device_files(
self.device, in_dir=self.DEVICE_TEMP_DIR, num_files=32)
self.device.pull(remote=self.DEVICE_TEMP_DIR, local=symlink)
for temp_file in temp_files:
host_path = os.path.join(
real_dir, posixpath.basename(self.DEVICE_TEMP_DIR),
temp_file.base_name)
self._verify_local(temp_file.checksum, host_path)
self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])
finally:
if host_dir is not None:
shutil.rmtree(host_dir)
def test_pull_dir_symlink_collision(self):
"""Pull a directory into a colliding symlink to directory."""
if os.name != "posix":
raise unittest.SkipTest('requires POSIX')
try:
host_dir = tempfile.mkdtemp()
real_dir = os.path.join(host_dir, "real")
tmp_dirname = os.path.basename(self.DEVICE_TEMP_DIR)
symlink = os.path.join(host_dir, tmp_dirname)
os.mkdir(real_dir)
os.symlink(real_dir, symlink)
self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])
self.device.shell(['mkdir', '-p', self.DEVICE_TEMP_DIR])
# Populate device directory with random files.
temp_files = make_random_device_files(
self.device, in_dir=self.DEVICE_TEMP_DIR, num_files=32)
self.device.pull(remote=self.DEVICE_TEMP_DIR, local=host_dir)
for temp_file in temp_files:
host_path = os.path.join(real_dir, temp_file.base_name)
self._verify_local(temp_file.checksum, host_path)
self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])
finally:
if host_dir is not None:
shutil.rmtree(host_dir)
def test_pull_symlink_dir(self):
"""Pull a symlink to a directory of symlinks to files."""
try: