From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1352852-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 7ECB3158003
	for <garchives@archives.gentoo.org>; Sun, 26 Dec 2021 13:59:59 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 778632BC026;
	Sun, 26 Dec 2021 13:59:58 +0000 (UTC)
Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id A03472BC02D
	for <gentoo-commits@lists.gentoo.org>; Sun, 26 Dec 2021 13:59:57 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 7D6B3342EE7
	for <gentoo-commits@lists.gentoo.org>; Sun, 26 Dec 2021 13:59:55 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id BCFCD261
	for <gentoo-commits@lists.gentoo.org>; Sun, 26 Dec 2021 13:59:53 +0000 (UTC)
From: "Fabian Groffen" <grobian@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" <grobian@gentoo.org>
Message-ID: <1640526861.8165933c5b9986b536cf91b8ba82f7e76c9cc758.grobian@gentoo>
Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/
X-VCS-Repository: proj/portage-utils
X-VCS-Files: libq/move_file.c
X-VCS-Directories: libq/
X-VCS-Committer: grobian
X-VCS-Committer-Name: Fabian Groffen
X-VCS-Revision: 8165933c5b9986b536cf91b8ba82f7e76c9cc758
X-VCS-Branch: master
Date: Sun, 26 Dec 2021 13:59:53 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: 5653a1a5-9413-4d49-8a42-7a43f9249134
X-Archives-Hash: 8f9f8318fe7af9d5f2023655f00f3938

commit:     8165933c5b9986b536cf91b8ba82f7e76c9cc758
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Dec 26 13:54:21 2021 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Dec 26 13:54:21 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=8165933c

libq/move_file: remove source file when done

move suggests the source is gone, so make sure it is :)

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/move_file.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libq/move_file.c b/libq/move_file.c
index 07cf69f..b98c8e2 100644
--- a/libq/move_file.c
+++ b/libq/move_file.c
@@ -85,7 +85,7 @@ move_file(int rootfd_src, const char *name_src,
 			return -1;
 		}
 
-		/* Preserve the file times */
+		/* preserve the file times */
 		times[0] = get_stat_atime(&st);
 		times[1] = get_stat_mtime(&st);
 		futimens(fd_dst, times);
@@ -93,12 +93,15 @@ move_file(int rootfd_src, const char *name_src,
 		close(fd_src);
 		close(fd_dst);
 
-		/* finally move the new tmp dst file to the right place, which
+		/* move the new tmp dst file to the right place, which
 		 * should be on the same FS/device now */
 		if (renameat(rootfd_dst, tmpname_dst, rootfd_dst, name_dst)) {
 			warnp("could not rename %s to %s", tmpname_dst, name_dst);
 			return -1;
 		}
+
+		/* finally remove the source file */
+		return unlinkat(rootfd_src, name_src, 0);
 	}
 
 	return 0;