From 936f8719cef022c4188b002ab51518949be22f3d Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Tue, 24 May 2011 20:24:42 +0530 Subject: [PATCH] make projects.list (and some other files) writes atomic The KDE folks have a projects.list file that gets picked up by rsync and sent elsewhere in some cron-ish manner. They noticed that occasionally the file that went across was truncated, which indicates that maybe it got picked up while it was still being written. oh and this change also affects any files that get written using wrap_print() --- src/gitolite.pm | 3 ++- src/gl-compile-conf | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gitolite.pm b/src/gitolite.pm index 1372d59..62c6791 100644 --- a/src/gitolite.pm +++ b/src/gitolite.pm @@ -101,9 +101,10 @@ sub wrap_open { sub wrap_print { my ($file, @text) = @_; - my $fh = wrap_open(">", $file); + my $fh = wrap_open(">", "$file.$$"); print $fh @text; close($fh) or die "$ABRT close $file failed: $! at ", (caller)[1], " line ", (caller)[2], "\n"; + rename "$file.$$", $file; } sub slurp { diff --git a/src/gl-compile-conf b/src/gl-compile-conf index 9799841..5d59358 100755 --- a/src/gl-compile-conf +++ b/src/gl-compile-conf @@ -560,11 +560,12 @@ for my $repo (@phy_repos) { # write out the project list, but not if GL_NO_DAEMON_NO_GITWEB is set unless ($GL_NO_DAEMON_NO_GITWEB) { - my $projlist_fh = wrap_open( ">", $PROJECTS_LIST); + my $projlist_fh = wrap_open( ">", "$PROJECTS_LIST.$$"); for my $proj (sort keys %projlist) { print $projlist_fh "$proj\n"; } close $projlist_fh; + rename "$PROJECTS_LIST.$$", $PROJECTS_LIST; } # ----------------------------------------------------------------------------