diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2026-04-10 22:32:05 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2026-04-10 22:32:05 +0800 |
| commit | c45d2aca51fd25a2ae97106729bf22d3bb42f1ca (patch) | |
| tree | e5a13fce2f37785041e5486d2d06249822ca36d1 | |
| parent | 714acb5a1500239e6c968254ba4448c35e047c8f (diff) | |
| download | cvn-c45d2aca51fd25a2ae97106729bf22d3bb42f1ca.tar.gz | |
wip: compare streams logic.
| -rw-r--r-- | vcx | 44 |
1 files changed, 31 insertions, 13 deletions
@@ -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->(); + } + } +} |
