diff --git a/tools/deps.py b/tools/deps.py index ffdf074be8f..e0d8a45044d 100755 --- a/tools/deps.py +++ b/tools/deps.py @@ -61,18 +61,23 @@ def install_dependencies(in_name): def replace_duplicates_with_symlinks(): hash_to_file = collections.defaultdict(list) - for txt_file_name in PIN_FOLDER.glob("*.txt"): - if not txt_file_name.is_symlink(): - with open(txt_file_name, "rb") as f: - digest = hashlib.sha1(f.read()).hexdigest() - hash_to_file[digest].append(txt_file_name) - - for digest, files in hash_to_file.items(): - if len(files) > 1: - base_file, *other_files = files - for other_file in other_files: - os.unlink(other_file) - os.symlink(base_file, other_file) + orig_dir = os.getcwd() + os.chdir(PIN_FOLDER) + try: + for txt_fname in pathlib.Path(".").glob("*.txt"): + if not txt_fname.is_symlink(): + with open(txt_fname, "rb") as f: + digest = hashlib.sha1(f.read()).hexdigest() + hash_to_file[digest].append(txt_fname) + + for digest, files in hash_to_file.items(): + if len(files) > 1: + base_file, *other_files = files + for other_file in other_files: + os.unlink(other_file) + os.symlink(base_file, other_file) + finally: + os.chdir(orig_dir) if __name__ == "__main__":