def test_plain_tgz_common_base(self): tmp_folder = temp_folder() with chdir(tmp_folder): # Create a couple of files ori_files_dir = os.path.join(tmp_folder, "subfolder-1.2.3") file1 = os.path.join(ori_files_dir, "folder", "file1") file2 = os.path.join(ori_files_dir, "folder", "file2") file3 = os.path.join(ori_files_dir, "folder", "file3") save(file1, "") save(file2, "") save(file3, "") tgz_folder = temp_folder() tgz_file = os.path.join(tgz_folder, "file.tar.gz") self._compress_folder(tmp_folder, tgz_file) # Tgz unzipped regularly extract_folder = temp_folder() untargz(tgz_file, destination=extract_folder, strip_root=True) self.assertFalse( os.path.exists(os.path.join(extract_folder, "subfolder-1.2.3"))) self.assertTrue( os.path.exists(os.path.join(extract_folder, "folder", "file1"))) self.assertTrue( os.path.exists(os.path.join(extract_folder, "folder", "file2"))) self.assertTrue( os.path.exists(os.path.join(extract_folder, "folder", "file3")))
def test_linkame_striproot_folder(self): tmp_folder = temp_folder() other_tmp_folder = temp_folder() save(os.path.join(other_tmp_folder, "foo.txt"), "") tgz_path = os.path.join(tmp_folder, "foo.tgz") with open(tgz_path, "wb") as tgz_handle: tgz = gzopen_without_timestamps("name", mode="w", fileobj=tgz_handle) # Regular file info = tarfile.TarInfo(name="common/foo.txt") info.name = "common/subfolder/foo.txt" info.path = "common/subfolder/foo.txt" with open(os.path.join(other_tmp_folder, "foo.txt"), 'rb') as file_handler: tgz.addfile(tarinfo=info, fileobj=file_handler) # A hardlink to the regular file info = tarfile.TarInfo(name="common/foo.txt") info.linkname = "common/subfolder/foo.txt" info.linkpath = "common/subfolder/foo.txt" info.name = "common/subfolder/bar/foo.txt" info.path = "common/subfolder/bar/foo.txt" info.type = b'1' # This indicates a hardlink to the tgz file "common/subfolder/foo.txt" tgz.addfile(tarinfo=info, fileobj=None) tgz.close() assert not os.path.exists( os.path.join(tmp_folder, "subfolder", "foo.txt")) assert not os.path.exists( os.path.join(tmp_folder, "subfolder", "bar", "foo.txt")) untargz(tgz_path, destination=tmp_folder, strip_root=True) assert os.path.exists(os.path.join(tmp_folder, "subfolder", "foo.txt")) assert os.path.exists( os.path.join(tmp_folder, "subfolder", "bar", "foo.txt")) # Check develop2 public unzip rmdir(os.path.join(tmp_folder, "subfolder")) assert not os.path.exists( os.path.join(tmp_folder, "subfolder", "foo.txt")) assert not os.path.exists( os.path.join(tmp_folder, "subfolder", "bar", "foo.txt")) unzip_dev2(ConanFileMock(), tgz_path, destination=tmp_folder, strip_root=True) assert os.path.exists(os.path.join(tmp_folder, "subfolder", "foo.txt")) assert os.path.exists( os.path.join(tmp_folder, "subfolder", "bar", "foo.txt"))
def test_invalid_flat(self): tmp_folder = temp_folder() with chdir(tmp_folder): # Not a single dir containing everything file1 = os.path.join(tmp_folder, "subfolder-1.2.3", "folder2", "file1") file2 = os.path.join(tmp_folder, "other-1.2.3", "folder", "file2") save(file1, "") save(file2, "") tgz_folder = temp_folder() tgz_file = os.path.join(tgz_folder, "file.tar.gz") self._compress_folder(tmp_folder, tgz_file) extract_folder = temp_folder() with six.assertRaisesRegex(self, ConanException, "The tgz file contains more than 1 folder " "in the root"): untargz(tgz_file, destination=extract_folder, strip_root=True)