lumia

Archive checksum manager
git clone git://lumidify.org/git/lumia.git
Log | Files | Refs | README

commit a4d16b3c7af854ea44887d829731d1405cbb66f2
parent ae5ceb4ffcbb4205584e4a1e7dc8b055a8c152d6
Author: lumidify <nobody@lumidify.org>
Date:   Wed, 25 Mar 2020 18:35:32 +0100

Add updatespecial command

Diffstat:
Mlumia.pl | 72++++++++++++++++++++++++++++++++++++------------------------------------
Mtests/alltests.sh | 1+
Atests/updatespecial.sh | 29+++++++++++++++++++++++++++++
Atests/updatespecial.txt | 18++++++++++++++++++
4 files changed, 84 insertions(+), 36 deletions(-)

diff --git a/lumia.pl b/lumia.pl @@ -902,6 +902,11 @@ sub update { } } +sub update_special { + my $dir = shift; + write_special_cksums $dir, $CKSUM_FILE, $DIR_FILE; +} + my %args; Getopt::Long::Configure("bundling"); GetOptions(\%args, "f|force", "q|quiet", "v|verbose", "h|help"); @@ -914,35 +919,21 @@ my $cmd = shift; if ($cmd eq "mv") { die "mv requires at least two arguments\n" if @ARGV < 2; my @src = @ARGV[0..$#ARGV-1]; - move_files(\@src, $ARGV[-1], \%args); + move_files \@src, $ARGV[-1], \%args; } elsif ($cmd eq "rm") { - if (@ARGV < 1) { - die "rm requires at least one argument\n"; - } + die "rm requires at least one argument\n" if @ARGV < 1; remove_files \%args, @ARGV; } elsif ($cmd eq "addnew") { - my $dir = "."; - if (@ARGV >= 1) { - $dir = $ARGV[0]; - } + my $dir = @ARGV ? $ARGV[0] : "."; check_add_new_files $dir, \%args; } elsif ($cmd eq "checknew") { - my $dir = "."; - if (@ARGV >= 1) { - $dir = $ARGV[0]; - } + my $dir = @ARGV ? $ARGV[0] : "."; check_new_files $dir; } elsif ($cmd eq "checkold") { - my $dir = "."; - if (@ARGV >= 1) { - $dir = $ARGV[0]; - } + my $dir = @ARGV ? $ARGV[0] : "."; check_old_files $dir; } elsif ($cmd eq "rmold") { - my $dir = "."; - if (@ARGV >= 1) { - $dir = $ARGV[0]; - } + my $dir = @ARGV ? $ARGV[0] : "."; remove_old_files $dir, \%args; } elsif ($cmd eq "check") { if (@ARGV < 1) { @@ -951,21 +942,18 @@ if ($cmd eq "mv") { check_files \%args, @ARGV; } } elsif ($cmd eq "clean") { - my $dir = "."; - if (@ARGV >= 1) { - $dir = $ARGV[0]; - } + my $dir = @ARGV ? $ARGV[0] : "."; clean_files $dir, \%args; } elsif ($cmd eq "extract") { my $src_dir = "."; my $dst_dir; - if (@ARGV >= 2) { + if (@ARGV == 2) { $src_dir = $ARGV[0]; $dst_dir = $ARGV[1]; } elsif (@ARGV == 1) { $dst_dir = $ARGV[0]; } else { - die "ERROR: `extract` requires at least a destination directory.\n"; + die "Invalid number of arguments\n"; } if (!-d $src_dir) { die "ERROR: Directory \"$src_dir\" does not exist.\n"; @@ -975,21 +963,19 @@ if ($cmd eq "mv") { } extract $src_dir, $dst_dir; } elsif ($cmd eq "cp") { - if (@ARGV < 2) { - die "cp requires at least two arguments\n"; - } + die "cp requires at least two arguments\n" if @ARGV < 2; my @src = @ARGV[0..$#ARGV-1]; copy_files \@src, $ARGV[-1], \%args; } elsif ($cmd eq "mkdir") { - if (@ARGV < 1) { - die "mkdir requires at least one argument\n"; - } + die "mkdir requires at least one argument\n" if @ARGV < 1; make_dirs @ARGV; } elsif ($cmd eq "update") { - if (@ARGV < 1) { - die "update requires at least one argument\n"; - } + die "update requires at least one argument\n" if @ARGV < 1; update @ARGV; +} elsif ($cmd eq "updatespecial") { + die "Invalid number of arguments\n" if @ARGV > 1; + my $dir = @ARGV ? $ARGV[0] : "."; + update_special $dir; } __END__ @@ -1040,6 +1026,9 @@ the author has made too many bad decisions to rectify that problem at the moment =head1 COMMANDS +Note that some commands support multiple files/directories as arguments and others, +for which it would make just as much sense, don't. That's just the way it is. + =over 8 =item B<addnew> [-q] [directory] @@ -1120,6 +1109,16 @@ Note: Directories given as arguments are ignored. This is mainly meant to quickly "touch" a file after it was modified (e.g. a notes file that is occasionally updated). +=item B<updatespecial> [directory] + +Recalculates the checksums for the special files C<.lumidify_archive_dirs> and +C<.lumidify_archive_cksums> and writes them to C<.lumidify_archive_cksums.cksum>. +B<directory> defaults to the current directory. + +This is only meant to be used if, for some reason, the checksum files had to +be edited manually and thus don't match the checksums in C<.lumidify_archive_cksums.cksum> +anymore. + =item B<rm> [-f] file ... Removes the given files and directories recursively from the filesystem and @@ -1322,7 +1321,8 @@ B<addnew> command in any subdirectory when you've added new files there. Due to the extensive use of iterators and the author's bad life decisions, some functions, such as B<addnew> and B<check>, run more slowly than they -would if they were programmed more efficiently. Too bad. +would if they were programmed more efficiently, especially on many small +files and folders. Too bad. =head1 PORTABILITY diff --git a/tests/alltests.sh b/tests/alltests.sh @@ -9,3 +9,4 @@ ./runtest.sh mkdir ./runtest.sh extract ./runtest.sh rm +./runtest.sh updatespecial diff --git a/tests/updatespecial.sh b/tests/updatespecial.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +mkdir tmp +cd tmp + +mkdir a +mkdir b +mkdir c + +touch f1 +touch f2 + +../../lumia.pl addnew -q +rm f2 +echo '4294967295 0 "f1"' > .lumidify_archive_cksums +../../lumia.pl check -q +../../lumia.pl updatespecial +../../lumia.pl check | sort +rm -r c +echo '"a" +"b"' > .lumidify_archive_dirs +../../lumia.pl check -q +cd a +../../../lumia.pl updatespecial .. +cd .. +../../lumia.pl check | sort + +cd .. +rm -r tmp diff --git a/tests/updatespecial.txt b/tests/updatespecial.txt @@ -0,0 +1,18 @@ +FAILED ./.lumidify_archive_cksums +OK ./.lumidify_archive_cksums +OK ./.lumidify_archive_dirs +OK ./a/.lumidify_archive_cksums +OK ./a/.lumidify_archive_dirs +OK ./b/.lumidify_archive_cksums +OK ./b/.lumidify_archive_dirs +OK ./c/.lumidify_archive_cksums +OK ./c/.lumidify_archive_dirs +OK ./f1 +FAILED ./.lumidify_archive_dirs +OK ./.lumidify_archive_cksums +OK ./.lumidify_archive_dirs +OK ./a/.lumidify_archive_cksums +OK ./a/.lumidify_archive_dirs +OK ./b/.lumidify_archive_cksums +OK ./b/.lumidify_archive_dirs +OK ./f1