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()
This commit is contained in:
parent
3d9b4fae9f
commit
936f8719ce
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue