#!/usr/bin/env perl use warnings; use strict; use Getopt::Long; use DBIx::FileStore; use DBIx::FileStore::UtilityFunctions qw( convert_bytes_to_human_size ); #use Data::Dumper; my $long = 0; my $human = 0; # like du's -h my $md5 = 0; my $debug = 0; my $all = 0; main(); sub Usage { "fdbls [--long] [--human] [--md5] [-all] [--debug] [files/dirs]:\n" . " Shows files in FileDB. Note that if you have files like\n" . " /a/b/c.txt and /a/b/d.txt in the db, then\n" . " % fdbls /a/b/\n" . " will show both files.\n"; } sub main { # fdbls: shows files in FileDB GetOptions( "long!" => \$long, "human!" => \$human, "all!" => \$all, "md5!" => \$md5, "debug!" => \$debug, ) || die Usage(); my $filestore = new DBIx::FileStore(); @ARGV = ( "" ) unless @ARGV; my %shown; for my $name (@ARGV) { my $files; # $level iis used to support directory-like viewing my $level = $all ? 0 : countslashes($name); # so we don't show things that appear # as if they're in SUB-folders print "Level of $name is $level\n" if ($debug); # fetch all files with b_num = 0-- either all of them, or the ones # matching $name if ($name eq "") { $files = $filestore->get_all_filenames(); } else { $files = $filestore->get_filenames_matching_prefix( $name ); } #print Dumper($files); print( "fdbls: got " . scalar(@$files) . " rows back for '$name'\n") if $debug; for my $f (@$files) { # each row is (name, c_len, c_md5, lasttimeasint) # # $toshow becomes the 'folder' to show, # or the full filename from $f my $toshow = $level ? filename_to_show($f->[0], $level) : $f->[0]; $toshow =~ s/ 0+//; next if $shown{$toshow}++; # build up a line to show in $line, then show it my $line = ""; if ($long || $human) { if ($human) { $line .= sprintf("%-7s ", convert_bytes_to_human_size( $f->[1] ) ); } else { $line .= sprintf("%9d ", $f->[1]); # c_len } my $date = $f->[3]; $line .= sprintf("%08d %02d:%02d ", substr($date, 0, 8), substr($date, 8, 2), substr($date, 10, 2) ); # date and time: first 8, and last four chars of date (split into hours:minutes) } $line .= sprintf("%s ", $f->[2]) if $md5; $line .= $toshow; print "$line\n"; } } } sub filename_to_show { my ($f, $level) = @_; #$f = "/" . $f unless (substr($f, 0, 1) eq "/"); # This was to pretend that all incoming names started with / # (as if / were the working directory, since there are no # directories in the filestore.) We decided against this, # so the above code is commented out. my $cnt = 0; for(my $i=0; $i =head1 SEE ALSO L, L, L, L, L, L, L, L =cut