From 9b4c50dd67c337f2d3c927cdd01ae4433bb08b61 Mon Sep 17 00:00:00 2001
From: Evgeniy Taishev <e.taishev@omp.ru>
Date: Mon, 17 Jan 2022 22:07:13 +0300
Subject: [PATCH] Close file before replacing signed

---
 sign/rpmgensig.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sign/rpmgensig.c b/sign/rpmgensig.c
index e88f9b7..b8c68ce 100644
--- a/sign/rpmgensig.c
+++ b/sign/rpmgensig.c
@@ -695,6 +695,10 @@ static int rpmSign(const char *rpm, int deleting, int flags)
 	if (copyFile(&fd, rpm, &ofd, trpm) == 0) {
 	    struct stat st;
 
+	    /* File must be closed before deletion due to different file locking in some file systems*/
+	    if (fd) (void) closeFile(&fd);
+	    if (ofd) (void) closeFile(&ofd);
+
 	    /* Move final target into place, restore file permissions. */
 	    if (stat(rpm, &st) == 0 && unlink(rpm) == 0 &&
 			rename(trpm, rpm) == 0 && chmod(rpm, st.st_mode) == 0) {
-- 
1.8.3.1

