Skip to content

Commit

Permalink
-n -> -i (thanks Tim)
Browse files Browse the repository at this point in the history
  • Loading branch information
luxagen committed Jan 27, 2023
1 parent b1ad61b commit 68a1583
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions rk
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# Mode options
# -x Clear own metadata from extended attributes
# -e Export hash log to stdout in the same format as `md5deep -zl`
# -n Initial-hash files that are missing metadata
# -v Verify files with metadata
# -a Combination of -n & -v
# -i Initialise files that are missing metadata
# -v Verify initialised files with metadata
# -a Combination of -i & -v

################################################################################
# Output: status column
Expand All @@ -23,7 +23,7 @@ use IPC::Run qw(run);

my $mode = shift;

die "Incorrect usage!\n" if (not defined $mode && $mode =~ m/^-[nvaxe]$/);
die "Incorrect usage!\n" if (not defined $mode && $mode =~ m/^-[ivaxe]$/);

my $no_recurse = 0;
my $no_follow_file_symlinks = 1;
Expand Down Expand Up @@ -65,14 +65,14 @@ sub item_process {
return if (-l $item and $no_follow_file_symlinks);
return &file_remove($item) if ($mode =~ m/-x/);
return &file_export($item) if ($mode =~ m/-e/);
return &file_new ($item) if ($mode =~ m/-n/);
return &file_init ($item) if ($mode =~ m/-i/);
return &file_verify($item) if ($mode =~ m/-v/);
return &file_all ($item) if ($mode =~ m/-a/);
}

################################################################################
# Initial-hash the file if it hasn't already been done
sub file_new {
sub file_init {
my ($file) = @_;

my $m = &meta_get($file);
Expand Down Expand Up @@ -127,7 +127,7 @@ sub file_all {
my %meta = %{$m};

return &file_verify($file) if (defined $meta{md5});
return &file_new($file);
return &file_init($file);
}

################################################################################
Expand Down
10 changes: 5 additions & 5 deletions tests
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ sub test_nx() {
%meta = %{&meta_get("$base/$f1")};
&is(scalar keys %meta,0);

&is(&invoke('n', ("$base/$f1")), "N $base/$p1\n");
&is(&invoke('i', ("$base/$f1")), "N $base/$p1\n");
%meta = %{&meta_get("$base/$f1")};
&is(scalar keys %meta,2);
&is($meta{md5},$h1);
&is(length($meta{htime}),19);

my $htime = $meta{htime};

&is(&invoke('n', ("$base/$f1")), "? $base/$p1\n");
&is(&invoke('i', ("$base/$f1")), "? $base/$p1\n");
%meta = %{&meta_get("$base/$f1")};
&is(scalar keys %meta,2);
&is($meta{md5},$h1);
Expand Down Expand Up @@ -92,7 +92,7 @@ sub test_nv() {
%meta = %{&meta_get("$base/$f1")};
&is(scalar keys %meta,0);

&is(&invoke('n', ("$base/$f1")), "N $base/$p1\n");
&is(&invoke('i', ("$base/$f1")), "N $base/$p1\n");
%meta = %{&meta_get("$base/$f1")};
&is(scalar keys %meta,2);
&is($meta{md5},$h1);
Expand Down Expand Up @@ -207,7 +207,7 @@ sub test_l {
%meta = %{&meta_get("$base/$f2")};
&is(scalar keys %meta,0);

&is(&invoke('n', ("$base/$f2")), '');
&is(&invoke('i', ("$base/$f2")), '');
%meta = %{&meta_get("$base/$f2")};
&is(scalar keys %meta,0);

Expand Down Expand Up @@ -246,7 +246,7 @@ sub test_r() {
"N $base/dir1/dir3/$p3");

my @got = sort(
split(/\n/, &invoke('n', "$base/dir1")));
split(/\n/, &invoke('i', "$base/dir1")));

&is_deeply(\@got,\@expected);

Expand Down

0 comments on commit 68a1583

Please sign in to comment.