Anonymous avatar Anonymous committed 7edc071

#i10000# 'deliver' sometimes fails in cases where several platforms simultaneously try to create the same big zip file in solver's 'common.pro' zip directory.

Comments (0)

Files changed (1)

solenv/bin/deliver.pl

             $work_file =~ s/\.zip$//;
             $work_file .= (sprintf('.%d-%d', $$, time())) . ".zip";
             die "Error: temp file $work_file already exists" if ( -e $work_file);
-            copy($zip_file, $work_file) if ( -e $zip_file );
+            if ( -e $zip_file ) {
+                if ( -z $zip_file) {
+                    # sometimes there are files of 0 byte size - remove them
+                    unlink $zip_file or print_error("can't remove empty file '$zip_file': $!",0);
+                } else {
+                    if ( ! copy($zip_file, $work_file)) {
+                        # give a warning, not an error:
+                        # we can zip from scratch instead of just updating the old zip file
+                        print_warning("can't copy'$zip_file' into '$work_file': $!", 0);
+                        unlink $work_file;
+                    }
+                }
+            }
         } else {
             # No pre processing necessary, working directly on solver.
             $work_file = $zip_file;
         } elsif ( $zip_file eq $common_zip_file) {
             # rename work file back
             if ( -e $work_file ) {
-                if (! rename($work_file, $zip_file)) {
-                    print_error("can't rename temporary file to $zip_file: $!",0);
-                    unlink $work_file;
+                if ( -e $zip_file) {
+                    # do some tricks to be fast. otherwise we may disturb other platforms
+                    # by unlinking a file which just gets copied -> stale file handle.
+                    my $buffer_file=$work_file . '_rm';
+                    rename($zip_file, $buffer_file) or warn "Warning: can't rename old zip file '$zip_file': $!";
+                    if (! rename($work_file, $zip_file)) {
+                        print_error("can't rename temporary file to $zip_file: $!",0);
+                        unlink $work_file;
+                    }
+                    unlink $buffer_file;
+                } else {
+                    if (! rename($work_file, $zip_file)) {
+                        print_error("can't rename temporary file to $zip_file: $!",0);
+                        unlink $work_file;
+                    }
                 }
             }
         }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.