summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vcx44
1 files 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->();
+ }
+ }
+}