From 41a9e0db19abc7aa02c75a6ccc34d6ea5374ac43 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Thu, 9 Apr 2026 22:57:46 +0800 Subject: wip: handle files in input in scan_tree. --- vcx | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'vcx') diff --git a/vcx b/vcx index 0947e4f..dbcd117 100644 --- a/vcx +++ b/vcx @@ -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, -- cgit v1.2.3