summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2026-04-09 22:57:46 +0800
committerSadeep Madurange <sadeep@asciimx.com>2026-04-09 22:57:46 +0800
commit41a9e0db19abc7aa02c75a6ccc34d6ea5374ac43 (patch)
tree99125083329c2930c98f80d9fe7157dbedfe95e6
parent822f4dc2b2ae461f5376467584d9993062c4f428 (diff)
downloadcvn-41a9e0db19abc7aa02c75a6ccc34d6ea5374ac43.tar.gz
wip: handle files in input in scan_tree.
-rw-r--r--vcx40
1 files changed, 35 insertions, 5 deletions
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,