IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 35714


Ignore:
Timestamp:
Jun 26, 2013, 4:42:05 PM (13 years ago)
Author:
bills
Message:

add file_rename function

File:
1 edited

Legend:

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

    r32652 r35714  
    730730}
    731731
     732sub file_rename {
     733    my $self = shift;
     734    my $old_name = shift;
     735    my $name = shift;
     736
     737    my $scheme = file_scheme($old_name);
     738    my $newscheme = file_scheme($name);
     739    if ($scheme and $scheme eq 'neb') {
     740        if (!$newscheme or $newscheme ne 'neb') {
     741            carp "cannot rename nebulous file to non nebulous path";
     742            return undef;
     743        }
     744        my $neb = $self->nebulous;
     745        if ($neb->storage_object_exists($old_name)) {
     746            eval {
     747                $neb->move($old_name, $name);
     748            };
     749            if ($@) {
     750                carp "nebulous move failed for $old_name";
     751                return undef;
     752            }
     753        } else {
     754            carp "$old_name not found";
     755            return undef;
     756        }
     757    } else {
     758        if ($newscheme and $newscheme eq 'neb') {
     759            carp "cannot rename non-nebulous file to nebulous path";
     760            return undef;
     761        }
     762        if ($self->file_exists($old_name)) {
     763            my $resolved = $self->file_resolve($old_name);
     764            my $resolved_new = $self->file_resolve($name);
     765            if (!rename($resolved, $resolved_new)) {
     766                carp "Failed to rename $resolved $resolved_new";
     767                return undef;
     768            }
     769        } else {
     770            carp "$old_name not found";
     771            return undef;
     772        }
     773    }
     774    return $name;
     775}
     776
    732777# redirect stderr and stdout streams to log file. If file already exists rename it and record
    733778# the name in the new log file.
Note: See TracChangeset for help on using the changeset viewer.