From 694b7f3d28f4f7b08f184100b54de56ffecd6a09 Mon Sep 17 00:00:00 2001 From: Bohdan Khomutskyi Date: Tue, 19 May 2020 16:11:43 +0200 Subject: [PATCH] Optimize the _link_file function to not call os.stat redundantly. This will eliminate 2 calls to os.stat per one invocation of the _link_file function. Assuming during the compose build 50000 files are linked, this change will eliminate 100000 redundant calls to os.stat. Jira: RHELCMP-797 Signed-off-by: Bohdan Khomutskyi --- pungi/linker.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pungi/linker.py b/pungi/linker.py index 7d85a38f..95229924 100644 --- a/pungi/linker.py +++ b/pungi/linker.py @@ -213,12 +213,13 @@ class Linker(kobo.log.LoggingBase): relative = link_type != "abspath-symlink" self.symlink(src, dst, relative) elif link_type == "hardlink-or-copy": - src_stat = os.stat(src) - dst_stat = os.stat(os.path.dirname(dst)) - if src_stat.st_dev == dst_stat.st_dev: + try: self.hardlink(src, dst) - else: - self.copy(src, dst) + except OSError as ex: + if ex.errno == errno.EXDEV: + self.copy(src, dst) + else: + raise else: raise ValueError("Unknown link_type: %s" % link_type)