Changeset 28525
- Timestamp:
- Jun 28, 2010, 2:59:29 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
Nebulous-Server/bin/nebdiskd (modified) (3 diffs)
-
Nebulous-Server/lib/Nebulous/Server.pm (modified) (2 diffs)
-
Nebulous/bin/neb-ls (modified) (7 diffs)
-
Nebulous/lib/Nebulous/Client.pm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/bin/nebdiskd
r28492 r28525 53 53 # set the process name for easy pgrep-ability 54 54 $0 = 'nebdiskd'; 55 my $rcfile = "$ENV{HOME}/.nebdiskrc"; 55 #my $rcfile = "$ENV{HOME}/.nebdiskrc"; 56 my $rcfile = $ENV{NEBDISKDRC}; 57 unless (defined($rcfile)) { 58 $rcfile = '/etc/nebdiskd.rc'; 59 } 56 60 $rcfile = File::Spec->canonpath($rcfile); 57 61 … … 71 75 my %host_removed = (); 72 76 my $failure_limit = 5; 73 74 75 77 76 78 #my $mounts = $c->get_mounts; … … 143 145 $SIG{HUP} = sub { $c = read_rcfile($rcfile) }; 144 146 147 my $date = localtime(); 148 $log->warn("BEGIN: $date with RCFILE: $rcfile"); 145 149 146 150 while (1) { -
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r28446 r28525 9 9 no warnings qw( uninitialized ); 10 10 11 our $VERSION = '0.1 7';11 our $VERSION = '0.18'; 12 12 13 13 use base qw( Class::Accessor::Fast ); … … 1508 1508 1509 1509 return \@keys; 1510 } 1511 1512 sub find_objects_wildcard 1513 { 1514 my $self = shift; 1515 1516 my $log = $self->log; 1517 $log->debug( "entered - @_" ); 1518 1519 my ($pattern) = validate_pos( @_, 1520 { 1521 type => SCALAR, 1522 optional => 1, 1523 }, 1524 ); 1525 1526 my $sql = $self->sql; 1527 my $db = $self->_db_for_index(0); 1528 1529 # validate that we have a key to deal with 1530 eval { 1531 $pattern = parse_neb_key($pattern) if defined $pattern; 1532 }; 1533 $log->logdie("$@") if $@; 1534 1535 unless (defined $pattern) { 1536 $log->debug( "leaving" ); 1537 $log->logdie("no keys found"); 1538 } 1539 1540 # parse out the directory we're working in, and decide if we are a directory 1541 my $dir_id = $self->_resolve_dir_parent_id(key => $pattern, dir_id => 1); 1542 my $work_dir; 1543 my $file_pattern; 1544 if (defined $dir_id) { 1545 $work_dir = $pattern; 1546 $file_pattern = '%'; 1547 } 1548 else { 1549 my $dir_plain = dirname($pattern); 1550 if ($dir_plain eq 'neb:') { 1551 $dir_plain = 'neb:///'; 1552 } 1553 if ($dir_plain) { 1554 $work_dir = parse_neb_key($dir_plain); 1555 } 1556 else { 1557 $work_dir = parse_neb_key('/'); 1558 } 1559 $log->warn("work dir: $work_dir " . $work_dir->path); 1560 $file_pattern = basename $pattern; 1561 unless ($file_pattern) { 1562 $file_pattern = '%'; 1563 } 1564 1565 $dir_id = $self->_resolve_dir_parent_id(key => $work_dir, dir_id => 1); 1566 unless (defined $dir_id) { 1567 $log->logdie("pattern $work_dir does not match any key or directory"); 1568 } 1569 } 1570 1571 # find dirs under dir 1572 my @dir_keys; 1573 1574 eval { 1575 $log->debug("looking for directories under dir: $dir_id"); 1576 $log->warn("dir_id: $dir_id pattern: $file_pattern"); 1577 my $query = $db->prepare_cached( $sql->find_dir_by_parent_id . " AND dirname LIKE ? "); 1578 $query->execute( $dir_id, $file_pattern ); 1579 1580 while ( my $row = $query->fetchrow_hashref ) { 1581 next if $row->{'dir_id'} == 1; 1582 my $dir = $row->{'dirname'}; 1583 if ($dir_id == 1) { 1584 push @dir_keys, $dir . '/' if $dir; 1585 } else { 1586 push @dir_keys, $work_dir->path . '/' . $dir . '/' if $dir; 1587 } 1588 $log->debug( "matched $dir" ) if $dir; 1589 } 1590 }; 1591 $log->logdie("database error: $@") if $@; 1592 1593 # find files under dir 1594 my @keys; 1595 eval { 1596 $log->debug("looking for objects under dir: $dir_id"); 1597 my $query = $db->prepare_cached( $sql->find_object_by_dir_id . " AND ext_id_basename LIKE ? "); 1598 $query->execute( $dir_id , $file_pattern); 1599 1600 while ( my $row = $query->fetchrow_hashref ) { 1601 my $key = $row->{ 'ext_id' }; 1602 push @keys, $key if $key; 1603 $log->debug( "matched $key" ) if $key; 1604 } 1605 }; 1606 $log->logdie("database error: $@") if $@; 1607 1608 $log->debug( "leaving" ); 1609 1610 return [sort(@dir_keys), sort(@keys)]; 1611 1510 1612 } 1511 1613 -
trunk/Nebulous/bin/neb-ls
r24346 r28525 1 1 #!/usr/bin/env perl 2 2 3 # Copyright (C) 2007-2009 Joshua Hoblitt 3 # Copyright (C) 2007-2009 Joshua Hoblitt, 2010 Chris Waters 4 4 5 5 use strict; … … 16 16 my ( 17 17 $server, 18 $ long,19 # $recursive,18 $path, 19 $column, 20 20 ); 21 21 22 22 $server = $ENV{'NEB_SERVER'} unless $server; 23 23 24 # make --long the default25 $long = 1;26 24 27 25 GetOptions( 28 26 'server|s=s' => \$server, 29 # 'recursive|r' => \$recursive,30 ' l|1' => \$long,27 'path|p' => \$path, 28 'column|c' => \$column, 31 29 ) || pod2usage( 2 ); 30 31 # twiddle column so that it does it by default. 32 33 $column = not $column; 32 34 33 35 my $pattern = shift; … … 47 49 $pattern ||= "/"; 48 50 49 #if ($recursive) { 50 # $pattern = "^" . $pattern . ".*"; 51 #} else { 52 # $pattern = "^" . $pattern . "\$"; 53 #} 51 my $keys = $neb->find_objects_wildcard($pattern); 54 52 55 my $keys = $neb->find_objects($pattern); 56 53 if ($path) { 54 my @files; 55 foreach my $key (@{ $keys }) { 56 my $uris = $neb->find_instances($key); 57 if (defined $uris) { 58 push @files, URI->new(@$uris[0])->file; 59 } 60 } 61 @{ $keys } = @files; 62 } 57 63 if ($keys) { 58 if ($long) { 59 print join("\n", @{ $keys }), "\n"; 60 } else { 61 print join(" ", @{ $keys }), "\n"; 64 if ($column) { 65 open(COLUMN,"|column") || die "Cannot open column command."; 66 print COLUMN join("\n", @{ $keys }), "\n"; 67 close(COLUMN); 68 } 69 else { 70 print join("\n", @{ $keys }), "\n"; 62 71 } 63 72 } 73 64 74 65 75 __END__ … … 73 83 =head1 SYNOPSIS 74 84 75 neb-ls [--server <URL>] [- l|-1] [--recursive] <pattern>85 neb-ls [--server <URL>] [-c] [-p] <pattern> 76 86 77 87 =head1 DESCRIPTION 78 88 79 89 This program list Nebulous keys matched by C<<pattern>>. Call it with no 80 arguments is equival anet to searching with the pattern C<.*>. Where81 C<<pattern>> is a POSIX 1003.2 compatable regular repression.90 arguments is equivalent to searching with the pattern C<neb://>. SQL like 91 wildcards are supported to select out certain files. 82 92 83 93 =head1 OPTIONS … … 85 95 =over 4 86 96 87 =item * - l|-197 =item * --path|-p 88 98 89 Use a long listing format. 99 Find the disk files corresponding to the keys found. 100 101 =item * --column|-c 102 103 Disable column formatting, and output results one to a line. 90 104 91 105 Optional 92 106 93 =cut94 #=item * --recursive|-r95 #96 #By default C<neb-ls> will only try to match the exact string provided to it.97 #With this option set all keys which match C<<pattern>> as a REGEX or substring98 #will be returned.99 #100 #Optional101 #102 107 =item * --server|-s <URL> 103 108 … … 122 127 =back 123 128 124 =head1 CREDITS125 126 Just me, myself, and I.127 128 129 =head1 SUPPORT 129 130 … … 132 133 =head1 AUTHOR 133 134 134 Joshua Hoblitt <jhoblitt@cpan.org> 135 Joshua Hoblitt <jhoblitt@cpan.org>, Chris Waters 135 136 136 137 =head1 COPYRIGHT 137 138 138 Copyright (C) 2007-20 09 Joshua Hoblitt. All rights reserved.139 Copyright (C) 2007-2010 Joshua Hoblitt / Chris Waters. All rights reserved. 139 140 140 141 This program is free software; you can redistribute it and/or modify it under -
trunk/Nebulous/lib/Nebulous/Client.pm
r28446 r28525 9 9 no warnings qw( uninitialized ); 10 10 11 our $VERSION = '0.1 7';11 our $VERSION = '0.18'; 12 12 13 13 use Digest::MD5; … … 741 741 } 742 742 743 sub find_objects_wildcard 744 { 745 my $self = shift; 746 747 my @args = validate_pos( @_, 748 { 749 type => SCALAR, 750 optional => 1, 751 }, 752 ); 753 754 $log->debug( "entered - @_" ); 755 756 my $response = $self->{ 'server' }->find_objects_wildcard( @args ); 757 if ( $response->fault ) { 758 $self->set_err($response->faultstring); 759 760 if ($response->faultstring =~ /no keys found/) { 761 $log->debug( "leaving" ); 762 return; 763 } 764 if ($response->faultstring =~ /does not match any key or directory/) { 765 $log->debug( "leaving" ); 766 return; 767 } 768 769 $log->logdie("unhandled fault - ", $self->err); 770 } 771 772 my $keys = $response->result; 773 774 $log->debug( "server found: @$keys" ); 775 776 # foreach my $path ( @{ $uris } ) { 777 # $path = _get_file_path( $path ); 778 # } 779 780 $log->debug( "leaving" ); 781 782 return $keys; 783 } 784 743 785 744 786 sub find_instances
Note:
See TracChangeset
for help on using the changeset viewer.
