IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30630


Ignore:
Timestamp:
Feb 14, 2011, 11:35:24 AM (15 years ago)
Author:
bills
Message:

Add new file delete method to PS-IPP-Config called kill_file().
For nebulous files it first moves the key to the trash, then tries
neb-delete. No failure occurs if the delete fails. "It's in the trash".
This method has been used by the method prepare_output for several
weeks now. Refactored prepare_output into prepare_output and
_kill_nebulous_file which does the work for kill_file().

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-Config/lib/PS/IPP/Config.pm

    r30316 r30630  
    11481148    if ($neb->storage_object_exists($output)) {
    11491149        if ($delete_existing) {
    1150             # avoid dead instances by moving the file before deleting it.
    1151             # append current time to form new name
    1152             my $todelete;
    1153             eval {
    1154                 # parse the key so that we can compute the new name
    1155                 require Nebulous::Key;
    1156             };
    1157             if ($@) {
    1158                 carp "Can't find Nebulous::Key";
    1159                 $$r_error = $PS_EXIT_CONFIG_ERROR;
    1160                 return undef;
    1161             }
    1162             eval {
    1163                 # parse the key so that we can compute the new name
    1164                 my $neb_key = Nebulous::Key::parse_neb_key($output);
    1165                 die "parse_neb_key failed" if !$neb_key;
    1166                 my $path = $neb_key->path;
    1167                 die "neb_key has no path" if !$path;
    1168                 my $ticks = time();
    1169                 $todelete = "ipp_trash/$path.$ticks";
    1170                 $neb->move($output, $todelete);
    1171             };
    1172             if ($@) {
    1173                 carp "nebulous move failed for $output";
     1150            $$r_error = $self->_kill_nebulous_file($output);
     1151            if ($$r_error) {
    11741152                $output = undef;
    1175                 $$r_error = $PS_EXIT_SYS_ERROR;
    1176             }
    1177             if ($todelete) {
    1178                 eval {
    1179                     $neb->delete($todelete);
    1180                 };
    1181                 if ($@) {
    1182                     carp "nebulous delete for $todelete failed. Ignoring.\n";
    1183                     $$r_error = $PS_EXIT_SYS_ERROR;
    1184                 }
    11851153            }
    11861154        } else {
    11871155            # Make sure that there is only 1 instance.
    1188 
    11891156            eval {
    11901157                $neb->there_can_be_only_one($output);
     
    11981165    }
    11991166    return $output;
     1167}
     1168
     1169# _kill_nebulous_file: reliably get a nebulous file out of way.
     1170# First move it to the trash then attempt to delete it. No failure if delete fails.
     1171# The file is in the trash.
     1172# Assumes that file is a nebulous file with a storage object that exists
     1173# Users should call kill_file()
     1174# Returns 0 on success otherwise and a PS_EXIT error code on failure
     1175sub _kill_nebulous_file {
     1176    my $self = shift;
     1177    my $filename = shift;
     1178    my $neb = $self->nebulous;
     1179
     1180    # avoid dead instances by moving the file before deleting it.
     1181    # append current time to form new name
     1182    my $todelete;
     1183    eval {
     1184        # parse the key so that we can compute the new name
     1185        require Nebulous::Key;
     1186    };
     1187    if ($@) {
     1188        carp "Can't find Nebulous::Key";
     1189        return $PS_EXIT_CONFIG_ERROR;
     1190    }
     1191    eval {
     1192        # parse the key so that we can compute the new name
     1193        my $neb_key = Nebulous::Key::parse_neb_key($filename);
     1194        die "parse_neb_key failed" if !$neb_key;
     1195        my $path = $neb_key->path;
     1196        die "neb_key has no path" if !$path;
     1197        my $ticks = time();
     1198        $todelete = "ipp_trash/$path.$ticks";
     1199        $neb->move($filename, $todelete);
     1200    };
     1201    if ($@) {
     1202        carp "nebulous move failed for $filename";
     1203        return $PS_EXIT_SYS_ERROR;
     1204    }
     1205    if ($todelete) {
     1206        eval {
     1207            $neb->delete($todelete);
     1208        };
     1209        if ($@) {
     1210            carp "nebulous delete for $todelete failed. Ignoring.\n";
     1211            return $PS_EXIT_SYS_ERROR;
     1212        }
     1213    }
     1214    return 0;
     1215}
     1216
     1217# user level interface to kill_file reliably get a file out of way.
     1218#
     1219# If a nebulous file, move it to the trash then attempt to delete it.
     1220# if non nebulous file just delete it.
     1221# Returns 0 on success otherwise and a PS_EXIT error code on failure
     1222
     1223sub kill_file {
     1224    my $self = shift;
     1225    my $filename = shift;
     1226    my $neb = $self->nebulous;
     1227
     1228    my $scheme = file_scheme($filename);
     1229    if (!$scheme or ($scheme ne 'neb')) {
     1230        if ($self->file_exists($filename)) {
     1231            if (!$self->file_delete($filename)) {
     1232                carp "failed to delete $filename";
     1233                return $PS_EXIT_SYS_ERROR;
     1234            }
     1235        }
     1236    } elsif ($neb->storage_object_exists($filename)) {
     1237        $self->_kill_nebulous_file($filename);
     1238    }
     1239    return 0;
    12001240}
    12011241
  • trunk/ippScripts/scripts/ipp_cleanup.pl

    r30546 r30630  
    19001900{
    19011901    my $files = shift; # reference to a list of files to unlink
    1902 #     my $test_verbose = 1;
    1903 
    1904 #     if ($test_verbose == 1) {
    1905 #       open(TMPLOG,">>/tmp/czw.cleanup.log");
    1906 #       flock(TMPLOG,2);
    1907 #     }
    1908 
    1909     # this script is, of course, very dangerous.
     1902
    19101903    foreach my $file (@$files) {
    19111904        print STDERR "unlinking $stage $stage_id $file";
    1912         unless ($ipprc->file_exists($file)) {
    1913             print STDERR "\t File not found\n";
    1914         }
    1915         else {
    1916             print STDERR "\n";
    1917         }
    1918 
    1919 #       if ($test_verbose == 1) {
    1920 #           print TMPLOG "$stage $stage_id $file";
    1921 
    1922 #           else {
    1923 #               print TMPLOG "\n";
    1924 #           }
    1925 #       }
    1926 
    1927         $ipprc->file_delete($file);
    1928     }
    1929 
    1930 #     if ($test_verbose == 1) {
    1931 #       flock(TMPLOG,8);
    1932 #       close(TMPLOG);
    1933 #     }
     1905
     1906        my $error_code = $ipprc->kill_file($file);
     1907
     1908        &my_die("failed to kill $file", $stage, $stage_id, $PS_EXIT_CONFIG_ERROR) if $error_code;
     1909    }
    19341910
    19351911    return 1;
  • trunk/ippScripts/scripts/magic_destreak_cleanup.pl

    r30520 r30630  
    4444           'magic_ds_id=s'  => \$magic_ds_id,# Magic destreak run identifier
    4545           'camera=s'       => \$camera,     # camera for evaluating file rules
    46            'stage=s'        => \$stage,     # camera for evaluating file rules
     46           'stage=s'        => \$stage,      # ipp stage for this magicDSRun
    4747           'save-temps'     => \$save_temps, # Save temporary files?
    4848           'dbname=s'       => \$dbname,     # Database name
     
    160160        my $backup_path_base = $comp->{backup_path_base};
    161161        my ($bimage, $bmask, $bch_mask, $bweight, $bsources, $bastrom);
    162         my ($rimage, $rmask, $rch_mask, $rweight, $rsources, $rastrom);
     162#        my ($rimage, $rmask, $rch_mask, $rweight, $rsources, $rastrom);
    163163
    164164        if ($stage eq "chip") {
     
    219219        }
    220220
    221         delete_files($bimage, $bmask, $bweight, $bsources, $bastrom, $bch_mask, $rch_mask);
     221        delete_files($bimage, $bmask, $bweight, $bsources, $bastrom, $bch_mask);
    222222
    223223        if ($stage eq "diff" and $warp_warp) {
     
    252252    foreach my $file (@_) {
    253253        if ($file) {
    254             if ($ipprc->file_exists($file)) {
    255                 if (!$no_update) {
    256                     print STDERR "deleting $file\n" if $verbose;
    257                     $ipprc->file_delete($file, 1) or my_die("Failed to delete $file", $magic_ds_id, $PS_EXIT_UNKNOWN_ERROR);
    258                     } else {
    259                     print STDERR "skipping delete $file\n";
    260                 }
    261             } else {
    262                 print STDERR "$file not found\n" if $verbose;
    263             }
     254            my $error_code = $ipprc->kill_file($file);
     255            my_die("Failed to delete $file", $magic_ds_id, $error_code) if $error_code;
    264256        }
    265257    }
Note: See TracChangeset for help on using the changeset viewer.