about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-12-29T19·04+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-12-29T19·04+0000
commit2fdb27e7f21c99174d35556575e3d25bf2bdc23e (patch)
tree303a1fc8b8c6907f49441554b0b5da3076d4d931 /scripts
parente1e9c036f9313ac6bf160dba67e694b7868f1567 (diff)
* Atomic file replacement is good.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/generate-patches.pl12
-rw-r--r--scripts/readmanifest.pm.in5
2 files changed, 14 insertions, 3 deletions
diff --git a/scripts/generate-patches.pl b/scripts/generate-patches.pl
index e084b994db..7d957839bb 100755
--- a/scripts/generate-patches.pl
+++ b/scripts/generate-patches.pl
@@ -198,9 +198,17 @@ foreach my $p (keys %dstOutPaths) {
     
         my $finalName =
             "$narBz2Hash-$name-$closestVersion-to-$version.nar-diff";
-    
-        system("cp '$tmpdir/DIFF' '$patchesDir/$finalName'") == 0
+
+        if (-e "$patchesDir/$finalName") {
+            print "    not copying, already exists\n";
+            next;
+        }
+        
+        system("cp '$tmpdir/DIFF' '$patchesDir/$finalName.tmp'") == 0
             or die "cannot copy diff";
+
+        rename("$patchesDir/$finalName.tmp", "$patchesDir/$finalName")
+            or die "cannot rename $patchesDir/$finalName.tmp";
         
         # Add the patch to the manifest.
         addPatch \%dstPatches, $p,
diff --git a/scripts/readmanifest.pm.in b/scripts/readmanifest.pm.in
index 766aa42199..31ea5f43cc 100644
--- a/scripts/readmanifest.pm.in
+++ b/scripts/readmanifest.pm.in
@@ -146,7 +146,7 @@ sub writeManifest
     my $patches = shift;
     my $successors = shift;
 
-    open MANIFEST, ">$manifest";
+    open MANIFEST, ">$manifest.tmp"; # !!! check exclusive
 
     foreach my $storePath (keys %{$narFiles}) {
         my $narFileList = $$narFiles{$storePath};
@@ -184,6 +184,9 @@ sub writeManifest
     
     
     close MANIFEST;
+
+    rename("$manifest.tmp", $manifest)
+        or die "cannot rename $manifest.tmp: $!";
 }