Changeset 762

Show
Ignore:
Timestamp:
03/08/07 20:43:58 (2 years ago)
Author:
hachi
Message:

Break out the paths parsing, so I can thow the invalid filename failure earlier (during create_open) instead of throwing it late (create_close -> file_stored)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/filepaths-20070306/server/lib/MogileFS/Plugin/FilePaths.pm

    r759 r762  
    1414use MogileFS::Worker::Query; 
    1515 
    16 # FIXME: need to add in the configuration options for domain only 
    17  
    1816# called when this plugin is loaded, this sub must return a true value in order for 
    1917# MogileFS to consider the plugin to have loaded successfully.  if you return a 
    2018# non-true value, you MUST NOT install any handlers or other changes to the system. 
    2119# if you install something here, you MUST uninstall it in the unload sub. 
     20 
     21sub _parse_path { 
     22    my $fullpath = shift; 
     23    return unless defined($fullpath) and length($fullpath); 
     24    my ($path, $file) = $fullpath =~ 
     25        m!^(/(?:[\w\-\.]+/)*)([\w\-\.]+)$!; 
     26    return ($path, $file); 
     27} 
     28 
    2229sub load { 
    2330 
     
    2734        my $args = shift; 
    2835        return 1 unless _check_dmid($args->{dmid}); 
    29         delete $args->{key}; 
     36 
     37        my $fullpath = delete $args->{key}; 
     38        my ($path, $filename) = _parse_path($fullpath); 
     39        return 0 unless defined($path) && length($path) && defined($filename) && length($filename); 
     40        return 1; 
    3041    }); 
    3142 
     
    5263 
    5364        # ensure we got a valid seeming path and filename 
    54         my ($path, $filename) = 
    55             ($args->{logical_path} =~ m!^(/(?:[\w\-\.]+/)*)([\w\-\.]+)$!) ? ($1, $2) : (undef, undef); 
    56  
     65        my ($path, $filename) = _parse_path($args->{logical_path}); 
    5766        return 0 unless defined($path) && length($path) && defined($filename) && length($filename); 
    5867 
     
    8594 
    8695        # ensure we got a valid seeming path and filename 
    87         my ($path, $filename) = 
    88             ($args->{key} =~ m!^(/(?:[\w\-\.]+/)*)([\w\-\.]+)$!) ? ($1, $2) : (undef, undef); 
    89         return 0 unless $path && $filename; 
     96        my ($path, $filename) = _parse_path($args->{key}); 
     97        return 0 unless defined($path) && length($path) && defined($filename) && length($filename); 
    9098 
    9199        # now try to get the end of the path