Skip to content

Commit

Permalink
extfs/img: Lister improvements.
Browse files Browse the repository at this point in the history
Use single run of mdir instead of recursive.
Improved support for long filenames.
Allow leading spaces in filenames.
Support for extfs test.
  • Loading branch information
twojstaryzdomu committed Sep 6, 2021
1 parent dc356f7 commit cba75cf
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/vfs/extfs/helpers/img
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ my $size_kb = ( -s $archive ) / 1024;
my $drive = 'b';

my $actions = {
list => "mdir -f -i \'$archive\'",
list => "mdir -s -f -i \'$archive\'",
copyout => "mcopy -m -n -o -p -i \'$archive\'",
copyin => "mcopy -m -n -o -p -i \'$archive\'",
rm => "mdel -i \'$archive\'",
Expand All @@ -20,7 +20,8 @@ my $actions = {
test => "logger \'$archive\'"
};

my $regex_list = qr"^(\S+)\s+(\S*)\s+(\S+)\s+(\d{4})-(\d{2})-(\d{2})\s+(\d{1,2}):(\d{1,2})(?:\s*)(\S+)*\s*$";
my $regex_dir = qr"(?<=^Directory for ::/)(.*)$";
my $regex_list = qr"^(\S+)\s+(\S*)\s+(\S+)\s+(\d{4})-(\d{2})-(\d{2})\s+(\d{1,2}):(\d{1,2})\s\s?(.*)$";

sub print_debug {
print "@_\n" if exists $ENV{DEBUG};
Expand Down Expand Up @@ -55,40 +56,48 @@ sub default_handler {
elsif ( $cmd eq 'copyout' ) {
$args[0] = "::$args[0]";
}
my $output = run_cmd "$actions->{ $cmd } @args";
my $input = run_cmd "$actions->{ $cmd } @args";
if ( $cmd eq 'list' ) {
my $output = {};
my $exec = check_mtools( run )
? 'rwxr-xr-x'
: 'rw-r--r--';
foreach ( @{ $output } ) {
? '-rwxr-xr-x'
: '-rw-r--r--';
my $dir;
foreach ( @{ $input } ) {
chomp;
next if /^$/;
if ( /$regex_dir/ ) {
$dir = "$1";
next;
}
if ( my ( $name, $ext, $size, $year, $mon, $day, $hours, $mins, $longname ) = $_ =~ /$regex_list/ ) {
print_debug "list: name = $name, ext = $ext, size = $size, year = $year, mon = $mon, day = $day, hours = $hours, mins = $mins, longname = $longname";
print_debug "list: dir = $dir, name = $name, ext = $ext, size = $size, year = $year, mon = $mon, day = $day, hours = $hours, mins = $mins, longname = $longname;";
next if ( $name eq '.' || $name eq '..' );
my $perms = ( $size ne '<DIR>'
? '-'
: 'd' )
. ( ( $ext eq 'exe' || $ext eq 'com' || $ext eq 'bat' )
my $perms = $size eq '<DIR>'
? 'drwxr-xr-x'
: ( $ext eq 'exe' || $ext eq 'com' || $ext eq 'bat' )
? $exec
: 'rw-r--r--' );
my $path = $longname
? "$args[0]/$longname"
: uc( "$args[0]/$name" . ( $ext ? ".$ext" : "" ) );
: '-rw-r--r--';
my $path = ( $dir ? "/$dir/" : "/" )
. ( $longname ? $longname : $name )
. ( $ext ? ".$ext" : "" );
$path = uc( $path ) unless $longname;
$secs = defined $secs ? $secs : "00";
printf "%-10s 1 %-8d %-8d %8s %s/%s/%s %s:%s:%s %s", $perms, $<,
print_debug "list: path = $path";
$output->{ $path } = sprintf "%-10s 1 %-8d %-8d %8s %s/%s/%s %s:%s:%s %s", $perms, $<,
$(, $size ne '<DIR>' ? $size : 0, $mon, $day, $year, $hours, $mins, $secs, $path
. "\n";
default_handler( $cmd, $archive, $path ) if ( $size eq '<DIR>' );
}
else {
print_debug "list: skipped: $_";
}
}
print foreach map { $output->{ $_ } } sort keys %{ $output };
}
}

print_debug "$0: cmd = $cmd; archive = $archive; args = @args";
$actions->{ $cmd } = $ENV{MC_TEST_EXTFS_LIST_CMD} if exists $ENV{MC_TEST_EXTFS_LIST_CMD};
die "Cannot find command $cmd, are mtools installed?\n" unless check_mtools( $cmd );
exists $actions->{ $cmd } ? default_handler( $cmd, $archive, @args )
: die "mode $cmd not available\n";

0 comments on commit cba75cf

Please sign in to comment.