From c166eadb7926fc9430279c4d49acd23ef7a08ce8 Mon Sep 17 00:00:00 2001 From: Mathieu Bridon Date: Fri, 29 May 2015 19:07:47 +0200 Subject: [PATCH] distgit: Actually hardlink over the existing source at the old path Without this, the file could exist at both the old and new path, taking the space on the disk twice. This forces a hardlink if the file already existed at the old path. --- roles/distgit/files/dist-git-upload.cgi | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/roles/distgit/files/dist-git-upload.cgi b/roles/distgit/files/dist-git-upload.cgi index a8599caace..297474164c 100644 --- a/roles/distgit/files/dist-git-upload.cgi +++ b/roles/distgit/files/dist-git-upload.cgi @@ -179,14 +179,26 @@ def main(): # Add the file to the old path, where fedpkg is currently looking for it if hash_type == "md5": old_dir = os.path.join(module_dir, filename, checksum) + old_path = os.path.join(old_dir, filename) try: os.makedirs(old_dir) - os.link(dest_file, os.path.join(old_dir, filename)) + except OSError as e: if e.errno != errno.EEXIST: raise e + try: + os.link(dest_file, old_path) + + except OSError as e: + if e.errno != errno.EEXIST: + raise e + + # The file already existed at the old path, hardlink over it + os.unlink(old_path) + os.link(old_path) + # Emit a fedmsg message. Load the config to talk to the fedmsg-relay. try: config = fedmsg.config.load_config([], None)