diff options
| -rw-r--r-- | vcx | 40 |
1 files changed, 35 insertions, 5 deletions
@@ -70,7 +70,7 @@ sub run_init { } sub run_status { - scan_dir('.', sub { + scan_tree('.', sub { my ($dir, $files) = @_; foreach my $f (@$files) { my $size = $f->{size}; @@ -327,9 +327,35 @@ sub hash_file_content { return $sha->hexdigest; } -sub scan_dir { - my ($root, $cb) = @_; - my @stack = ($root); +sub scan_tree { + my $cb = pop @_; + my @paths = @_; + + my @stack; + my @input_files; + + # If input contains files, process them first + foreach my $p (@paths) { + my @p_stats = lstat($p); + unless (@p_stats) { + warn "Can't lstat '$p': $!\n"; + next; + } + if (-f _ || -l _) { + push @input_files, { + path => $p =~ s|^\./||r, + size => $p_stats[7], + mtime => $p_stats[9], + }; + } elsif (-d _) { + push @stack, $p; + } + } + + if (@input_files) { + @input_files = sort { $a->{path} cmp $b->{path} } @input_files; + $cb->('.', \@input_files); + } while (@stack) { my $dir = pop @stack; @@ -346,7 +372,11 @@ sub scan_dir { next if $ent eq '.' or $ent eq '..' or $ent eq REPO; my $path = File::Spec->catfile($dir, $ent) =~ s|^\./||r; my @stats = lstat($path); - unless (@stats) { warn "Can't lstat $dir\n"; next; } + unless (@stats) { + warn "Can't lstat $dir\n"; + next; + } + if (-f _ || -l _) { push @files, { path => $path, |
