From c45d2aca51fd25a2ae97106729bf22d3bb42f1ca Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Fri, 10 Apr 2026 22:32:05 +0800 Subject: wip: compare streams logic. --- vcx | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/vcx b/vcx index 17648a9..c062fc8 100644 --- a/vcx +++ b/vcx @@ -72,15 +72,6 @@ sub run_init { } sub run_status { - scan_tree('.', sub { - my ($dir, $files) = @_; - foreach my $f (@$files) { - my $size = $f->{size}; - my $mtime = $f->{mtime}; - my $path = File::Spec->catdir($dir, $f->{path}); - print "$path: $size [$mtime]\n"; - } - }); } sub run_add { @@ -329,7 +320,7 @@ sub hash_file_content { return $sha->hexdigest; } -sub dir_streamer { +sub stream_tree { my (@paths) = @_; my $chunk_size = 1024 * 64; # 64 KB chunks for IO buffering @@ -415,7 +406,7 @@ sub dir_streamer { } } -sub index_streamer { +sub stream_index { $index = INDEX; open(my $fh, "<:utf8", $index) or die "Could not open index: $!"; @@ -425,10 +416,8 @@ sub index_streamer { close $fh; return; } - chomp $line; my ($path, $size, $mtime, $hash) = split(/\t/, $line); - return { path => $path, size => $size, @@ -437,3 +426,32 @@ sub index_streamer { }; }; } + +sub compare_streams { + my (@paths, $func) = @_; + + my $ixs = stream_index(); + my $wss = stream_tree($paths); + + $old = $ixs->(); + $new = $wss->(); + + # TODO: fix compare logic + while (defined $old || defined $new) { + if (defined $new && + (!defined $old || $new->{path} lt $old->{path})) { + $func->($new, 'N'); + $new = $wss->(); + } elsif (defined $old && + (!defined $new || $old->{path} lt $new->{path})) { + $func->($old, 'D'); + $old = $ixs->(); + } else { + if ($new->{mtime} != $old->{mtime} || $new->{size} != $old->{size}) { + $func->($new, 'M'); + } + $old = $ixs->(); + $new = $wss->(); + } + } +} -- cgit v1.2.3