commit:     4ec443f2ac57040304107720f24cad6b4651c7a4
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Mar 12 07:50:31 2016 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Mar 12 18:42:57 2016 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=4ec443f2

egencache --write-timestamp: use write_atomic (bug 577126)

Use write_atomic in order to create a new inode. This leads to
copy-on-write behavior with hardlinks, which is useful if someone
wants to use hardlinks to create copy-on-write repository
snapshots on a filesystem such as ext4 (no need for btrfs or zfs).

X-Gentoo-bug: 577126
X-Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=577126
Acked-by: Brian Dolbec <dolsen <AT> gentoo.org>

 bin/egencache | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/bin/egencache b/bin/egencache
index 7e3387e..0123d57 100755
--- a/bin/egencache
+++ b/bin/egencache
@@ -1165,9 +1165,9 @@ def egencache_main(args):
        if options.write_timestamp:
                timestamp_path = os.path.join(repo_path, 'metadata', 
'timestamp.chk')
                try:
-                       with open(timestamp_path, 'w') as f:
-                               f.write(time.strftime('%s\n' % 
TIMESTAMP_FORMAT, time.gmtime()))
-               except IOError:
+                       portage.util.write_atomic(timestamp_path,
+                               time.strftime('%s\n' % TIMESTAMP_FORMAT, 
time.gmtime()))
+               except (EnvironmentError, portage.exception.PortageException):
                        ret.append(os.EX_IOERR)
                else:
                        ret.append(os.EX_OK)

Reply via email to