Show
Ignore:
Timestamp:
08/28/06 21:48:45 (2 years ago)
Author:
marksmith
Message:

* make cmd_delete call through to hook system

* add FilePaths plugin support for deleting files

Files:

Legend:

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

    r323 r383  
    7070    }); 
    7171 
    72     # and now the magic for getting files by a path 
    73     MogileFS::register_global_hook( 'cmd_get_paths', sub { 
    74         my $args = shift; 
    75  
    76         # ensure we got a valid seeming path and filename 
    77         my ($path, $filename) = 
    78             ($args->{key} =~ m!^(/(?:[\w\-\.]+/)*)([\w\-\.]+)$!) ? ($1, $2) : (undef, undef); 
    79         return 0 unless $path && $filename; 
    80  
    81         # now try to get the end of the path 
    82         my $parentnodeid = MogileFS::Plugin::FilePaths::load_path( $args->{dmid}, $path ); 
    83         return 0 unless defined $parentnodeid; 
    84  
    85         # great, find this file 
    86         my $fid = MogileFS::Plugin::FilePaths::get_file_mapping( $args->{dmid}, $parentnodeid, $filename ); 
    87         return 0 unless defined $fid && $fid > 0; 
    88  
    89         # now pretend they asked for it and continue 
    90         $args->{key} = "fid:$fid"; 
    91         return 1; 
    92     }); 
     72    # and now magic conversions that make the rest of the MogileFS commands work 
     73    # without having to understand how the path system works 
     74    MogileFS::register_global_hook( 'cmd_get_paths', \&_path_to_key ); 
     75    MogileFS::register_global_hook( 'cmd_delete', \&_path_to_key ); 
    9376 
    9477    # now we want to ensure that the database is setup for us 
     
    173156} 
    174157 
    175 # checks to see if a node exists, and if not, creates it 
     158# checks to see if a node exists, and if not, creates it if $vivify is set 
    176159sub _find_node { 
    177160    my ($dbh, $dmid, $parentnodeid, $node, $vivify) = @_; 
     
    228211} 
    229212 
     213# generic sub that converts a file path to a key name that 
     214# MogileFS will understand 
     215sub _path_to_key { 
     216    my $args = shift; 
     217 
     218    # ensure we got a valid seeming path and filename 
     219    my ($path, $filename) = 
     220        ($args->{key} =~ m!^(/(?:[\w\-\.]+/)*)([\w\-\.]+)$!) ? ($1, $2) : (undef, undef); 
     221    return 0 unless $path && $filename; 
     222 
     223    # now try to get the end of the path 
     224    my $parentnodeid = MogileFS::Plugin::FilePaths::load_path( $args->{dmid}, $path ); 
     225    return 0 unless defined $parentnodeid; 
     226 
     227    # great, find this file 
     228    my $fid = MogileFS::Plugin::FilePaths::get_file_mapping( $args->{dmid}, $parentnodeid, $filename ); 
     229    return 0 unless defined $fid && $fid > 0; 
     230 
     231    # now pretend they asked for it and continue 
     232    $args->{key} = "fid:$fid"; 
     233    return 1; 
     234} 
     235 
    2302361; 
  • branches/server-newrepl/lib/MogileFS/Worker/Query.pm

    r382 r383  
    363363    my $args = shift; 
    364364 
     365    # validate domain for plugins 
     366    $args->{dmid} = $self->check_domain($args) 
     367        or return $self->err_line('domain_not_found'); 
     368 
     369    # now invoke the plugin, abort if it tells us to 
     370    my $rv = MogileFS::run_global_hook('cmd_delete', $args); 
     371    return $self->err_line('plugin_aborted') 
     372        if defined $rv && ! $rv; 
     373 
    365374    # validate parameters 
    366     my $dmid = $self->check_domain($args) 
    367         or return $self->err_line('domain_not_found'); 
    368     my $key = $args->{key}; 
    369     return $self->err_line("no_key") unless length($key); 
     375    my $dmid = $args->{dmid}; 
     376    my $key = $args->{key} or return $self->err_line("no_key"); 
    370377 
    371378    # get DB handle