Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] egencache --write-timestamp: use write_atomic (bug 577126)
Date: Sat, 12 Mar 2016 08:30:19
Message-Id: 1457771389-8614-1-git-send-email-zmedico@gentoo.org
1 Use write_atomic in order to create a new inode. This leads to
2 copy-on-write behavior with hardlinks, which is useful if someone
3 wants to use hardlinks to create copy-on-write repository
4 snapshots on a filesystem such as ext4 (no need for btrfs or zfs).
5
6 X-Gentoo-bug: 577126
7 X-Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=577126
8 ---
9 bin/egencache | 6 +++---
10 1 file changed, 3 insertions(+), 3 deletions(-)
11
12 diff --git a/bin/egencache b/bin/egencache
13 index 7e3387e..0123d57 100755
14 --- a/bin/egencache
15 +++ b/bin/egencache
16 @@ -1165,9 +1165,9 @@ def egencache_main(args):
17 if options.write_timestamp:
18 timestamp_path = os.path.join(repo_path, 'metadata', 'timestamp.chk')
19 try:
20 - with open(timestamp_path, 'w') as f:
21 - f.write(time.strftime('%s\n' % TIMESTAMP_FORMAT, time.gmtime()))
22 - except IOError:
23 + portage.util.write_atomic(timestamp_path,
24 + time.strftime('%s\n' % TIMESTAMP_FORMAT, time.gmtime()))
25 + except (EnvironmentError, portage.exception.PortageException):
26 ret.append(os.EX_IOERR)
27 else:
28 ret.append(os.EX_OK)
29 --
30 2.7.2

Replies