Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Commit cba75cf

Browse files
author
twojstaryzdomu
committed
extfs/img: Lister improvements.
Use single run of mdir instead of recursive. Improved support for long filenames. Allow leading spaces in filenames. Support for extfs test.
1 parent dc356f7 commit cba75cf

File tree

1 file changed

+26
-17
lines changed
  • src/vfs/extfs/helpers

1 file changed

+26
-17
lines changed

src/vfs/extfs/helpers/img

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ my $size_kb = ( -s $archive ) / 1024;
1010
my $drive = 'b';
1111

1212
my $actions = {
13-
list => "mdir -f -i \'$archive\'",
13+
list => "mdir -s -f -i \'$archive\'",
1414
copyout => "mcopy -m -n -o -p -i \'$archive\'",
1515
copyin => "mcopy -m -n -o -p -i \'$archive\'",
1616
rm => "mdel -i \'$archive\'",
@@ -20,7 +20,8 @@ my $actions = {
2020
test => "logger \'$archive\'"
2121
};
2222

23-
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*$";
23+
my $regex_dir = qr"(?<=^Directory for ::/)(.*)$";
24+
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?(.*)$";
2425

2526
sub print_debug {
2627
print "@_\n" if exists $ENV{DEBUG};
@@ -55,40 +56,48 @@ sub default_handler {
5556
elsif ( $cmd eq 'copyout' ) {
5657
$args[0] = "::$args[0]";
5758
}
58-
my $output = run_cmd "$actions->{ $cmd } @args";
59+
my $input = run_cmd "$actions->{ $cmd } @args";
5960
if ( $cmd eq 'list' ) {
61+
my $output = {};
6062
my $exec = check_mtools( run )
61-
? 'rwxr-xr-x'
62-
: 'rw-r--r--';
63-
foreach ( @{ $output } ) {
63+
? '-rwxr-xr-x'
64+
: '-rw-r--r--';
65+
my $dir;
66+
foreach ( @{ $input } ) {
6467
chomp;
6568
next if /^$/;
69+
if ( /$regex_dir/ ) {
70+
$dir = "$1";
71+
next;
72+
}
6673
if ( my ( $name, $ext, $size, $year, $mon, $day, $hours, $mins, $longname ) = $_ =~ /$regex_list/ ) {
67-
print_debug "list: name = $name, ext = $ext, size = $size, year = $year, mon = $mon, day = $day, hours = $hours, mins = $mins, longname = $longname";
74+
print_debug "list: dir = $dir, name = $name, ext = $ext, size = $size, year = $year, mon = $mon, day = $day, hours = $hours, mins = $mins, longname = $longname;";
6875
next if ( $name eq '.' || $name eq '..' );
69-
my $perms = ( $size ne '<DIR>'
70-
? '-'
71-
: 'd' )
72-
. ( ( $ext eq 'exe' || $ext eq 'com' || $ext eq 'bat' )
76+
my $perms = $size eq '<DIR>'
77+
? 'drwxr-xr-x'
78+
: ( $ext eq 'exe' || $ext eq 'com' || $ext eq 'bat' )
7379
? $exec
74-
: 'rw-r--r--' );
75-
my $path = $longname
76-
? "$args[0]/$longname"
77-
: uc( "$args[0]/$name" . ( $ext ? ".$ext" : "" ) );
80+
: '-rw-r--r--';
81+
my $path = ( $dir ? "/$dir/" : "/" )
82+
. ( $longname ? $longname : $name )
83+
. ( $ext ? ".$ext" : "" );
84+
$path = uc( $path ) unless $longname;
7885
$secs = defined $secs ? $secs : "00";
79-
printf "%-10s 1 %-8d %-8d %8s %s/%s/%s %s:%s:%s %s", $perms, $<,
86+
print_debug "list: path = $path";
87+
$output->{ $path } = sprintf "%-10s 1 %-8d %-8d %8s %s/%s/%s %s:%s:%s %s", $perms, $<,
8088
$(, $size ne '<DIR>' ? $size : 0, $mon, $day, $year, $hours, $mins, $secs, $path
8189
. "\n";
82-
default_handler( $cmd, $archive, $path ) if ( $size eq '<DIR>' );
8390
}
8491
else {
8592
print_debug "list: skipped: $_";
8693
}
8794
}
95+
print foreach map { $output->{ $_ } } sort keys %{ $output };
8896
}
8997
}
9098

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

0 commit comments

Comments
 (0)