diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-02-02 20:00:07 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-02-03 10:27:49 +0100 |
commit | db3d1b03a4c3f9a1a934ceed5650461c2842eeb3 (patch) | |
tree | 0b8993ece1bdacd18392be70d64f4862cd3a4399 /build_scripts | |
parent | 457183792dc59056cc09fe57068bfe60beac5614 (diff) |
build scripts: Do not unnecessarily copy files when installing
Check whether files and symlinks already exist before
actually copying or creating links.
Change-Id: I4bf8d04a6a2bd07b02214b675757899fdfaa87ba
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'build_scripts')
-rw-r--r-- | build_scripts/utils.py | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/build_scripts/utils.py b/build_scripts/utils.py index c2435fa17..d80e59a3d 100644 --- a/build_scripts/utils.py +++ b/build_scripts/utils.py @@ -246,31 +246,44 @@ def copyfile(src, dst, force=True, vars=None, force_copy_symlink=False, return if not os.path.islink(src) or force_copy_symlink: + if os.path.isfile(dst): + src_stat = os.stat(src) + dst_stat = os.stat(dst) + if (src_stat.st_size == dst_stat.st_size and + src_stat.st_mtime <= dst_stat.st_mtime): + log.info(f"{dst} is up to date.") + return dst + log.info(f"Copying file {src} to {dst}.") shutil.copy2(src, dst) if make_writable_by_owner: make_file_writable_by_owner(dst) + return dst + + link_target_path = os.path.realpath(src) + if os.path.dirname(link_target_path) == os.path.dirname(src): + link_target = os.path.basename(link_target_path) + link_name = os.path.basename(src) + current_directory = os.getcwd() + try: + target_dir = dst if os.path.isdir(dst) else os.path.dirname(dst) + os.chdir(target_dir) + if os.path.exists(link_name): + if (os.path.islink(link_name) and + os.readlink(link_name) == link_target): + log.info(f"Symlink {link_name} -> {link_target} already exists.") + return dst + os.remove(link_name) + log.info(f"Symlinking {link_name} -> {link_target} in {target_dir}.") + os.symlink(link_target, link_name) + except OSError: + log.error(f"{link_name} -> {link_target}: Error creating symlink") + finally: + os.chdir(current_directory) else: - link_target_path = os.path.realpath(src) - if os.path.dirname(link_target_path) == os.path.dirname(src): - link_target = os.path.basename(link_target_path) - link_name = os.path.basename(src) - current_directory = os.getcwd() - try: - target_dir = dst if os.path.isdir(dst) else os.path.dirname(dst) - os.chdir(target_dir) - if os.path.exists(link_name): - os.remove(link_name) - log.info(f"Symlinking {link_name} -> {link_target} in {target_dir}.") - os.symlink(link_target, link_name) - except OSError: - log.error(f"{link_name} -> {link_target}: Error creating symlink") - finally: - os.chdir(current_directory) - else: - log.error(f"{src} -> {link_target_path}: Can only create symlinks within the same " - "directory") + log.error(f"{src} -> {link_target_path}: Can only create symlinks within the same " + "directory") return dst |