From b27f0f6b13ec6a5053196701ba656e3cab7f0f9a Mon Sep 17 00:00:00 2001 From: Haibo Lin Date: Nov 09 2020 03:52:41 +0000 Subject: Run hardlink on promoted compose This should help with images that are generated in work/ and hardlinked to compose/ during compose process. hardlink >= 1.3 is required for the -x option. JIRA: RHELCMP-2880 Signed-off-by: Haibo Lin --- diff --git a/server/contrib/odcs-promote-compose b/server/contrib/odcs-promote-compose index 951e0dc..96e426e 100755 --- a/server/contrib/odcs-promote-compose +++ b/server/contrib/odcs-promote-compose @@ -8,6 +8,7 @@ import os import stat import errno +from kobo.shortcuts import run from productmd.composeinfo import ComposeInfo from productmd.rpms import Rpms @@ -190,12 +191,33 @@ class ComposePromotion(object): else: raise + def _run_hardlink(self, target): + """Run hardlink on the final destination to save more space. + + This should help with images that are generated in work/ and hardlinked + to compose/ during compose process. + + :param str target: the final destination of promoted compose. + """ + # Make sure hardlink command is available and -x option is supported + # (the default hardlink command in RHEL7 does not support -x option). + hardlink = "/usr/sbin/hardlink" + if not os.path.isfile(hardlink): + return + _, output = run([hardlink, "-h"], can_fail=True) + if "-x" not in str(output): + return + + cmd = [hardlink, "-c", "-vv", "-x", "^Packages$", target] + run(cmd, stdout=True, show_cmd=True) + def promote(self): """ Promotes the compose. """ shutil.copytree(args.compose, args.target, ignore=self._copytree_ignore) self._replace_symlinks_with_hardlinks() + self._run_hardlink(args.target) if __name__ == "__main__":