diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2026-04-09 22:57:46 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2026-04-09 22:57:46 +0800 |
| commit | 41a9e0db19abc7aa02c75a6ccc34d6ea5374ac43 (patch) | |
| tree | 99125083329c2930c98f80d9fe7157dbedfe95e6 | |
| parent | 822f4dc2b2ae461f5376467584d9993062c4f428 (diff) | |
| download | cvn-41a9e0db19abc7aa02c75a6ccc34d6ea5374ac43.tar.gz | |
wip: handle files in input in scan_tree.
| -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, |
