Changeset 772

Show
Ignore:
Timestamp:
03/15/07 20:27:44 (2 years ago)
Author:
hachi
Message:

Switch the way the list_directory command returns the list of files, and add the fetching of Metadata (mtime) from the other plugin.

Files:

Legend:

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

    r762 r772  
    1313 
    1414use MogileFS::Worker::Query; 
     15use MogileFS::Plugin::MetaData; 
    1516 
    1617# called when this plugin is loaded, this sub must return a true value in order for 
     
    4647        my $args = shift; 
    4748        return 1 unless _check_dmid($args->{dmid}); 
     49         
    4850 
    4951        # the key is the path, so we need to move that into the logical_path argument 
     
    177179            unless defined $nodeid; 
    178180 
     181        if (get_file_mapping($nodeid)) { 
     182            return $self->err_line('not_a_directory', 'Path provided is not a directory'); 
     183        } 
     184 
    179185        # get files in path, return as an array 
    180186        my %res; 
     
    183189        my $dbh = Mgd::get_dbh(); 
    184190 
    185         foreach my $node (@nodes) { 
    186             my ($nodename, $fid) = @$node; 
    187             if ($fid) { # thjs object is a file 
     191        my $node_count = $res{'files'} = scalar @nodes; 
     192 
     193        for(my $i = 0; $i < $node_count; $i++) { 
     194            my ($nodename, $fid) = @{$nodes[$i]}; 
     195            my $prefix = "file$i"; 
     196            $res{$prefix} = $nodename; 
     197 
     198            if ($fid) { # This file is a regular file 
     199                $res{"$prefix.type"} = "F"; 
    188200                my $length = $dbh->selectrow_array("SELECT length FROM file WHERE fid=?", undef, $fid); 
    189                 $res{$nodename} = "F:$length"; 
    190             } else { # This is a directory 
    191                 $res{$nodename} = "D"; 
     201                $res{"$prefix.size"} = $length if defined($length); 
     202                my $metadata = MogileFS::Plugin::MetaData::get_metadata($fid); 
     203                $res{"$prefix.mtime"} = $metadata->{mtime} if $metadata->{mtime}; 
     204            } else {    # This file is a directory 
     205                $res{"$prefix.type"} = "D"; 
    192206            } 
    193207        }