From cb159c7f64cc64fafffd9dcc7c605bb12497fd02 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sun, 29 Mar 2015 01:11:30 +0100 Subject: Add a 'rm' command. --- cli/icevault | 27 +++++++++++++++++++++++++++ cli/icevault.1 | 6 ++++++ 2 files changed, 33 insertions(+) diff --git a/cli/icevault b/cli/icevault index fdc1b74..be7902f 100755 --- a/cli/icevault +++ b/cli/icevault @@ -721,6 +721,7 @@ my @USAGE = ( ls => "[-0, --zero] [-r, --recursive] [scheme://[hostname/[identity]] ...]", mv => "[-f, --force] scheme://hostname/identity1 scheme://hostname/identity2", reencrypt => "[scheme://[hostname/[identity]] ...]", + rm => "[-f, --force] [-r, --recursive] scheme://[hostname/[identity]] ...", ); if ($ARGV[0] eq '--help' or $ARGV[0] eq '-?') { @@ -1216,6 +1217,32 @@ elsif ($COMMAND eq 'cp' or $COMMAND eq 'mv') { commit(($COMMAND eq 'cp' ? 'copy' : 'move')." $source to $target", @filenames); } +elsif ($COMMAND eq 'rm') { + getopts( 'force|f' => "-f, --force \tNever prompt" + , 'recursive|r' => "-r, --recursive\tList identities recursively" + ); + + my @matches = list(@ARGV); + my @deleted; + foreach my $m (@matches) { + error "Use C<%s> for recursive deletion", '-r' unless + $m->{id} =~ /\A[A-Za-z0-9-]+:\/\/[^\P{Graph}:\/]+(?::\d+)?\/[^\P{Print}\/]+\z/; + + if ($CONFIG{force} or promptYN "Really delete C<%s>?", 0, $m->{id}) { + unlink $m->{filename} or warning "Can't unlink C<%s>: %s", $m->{filename}, $!; + push @deleted, $m; + } + } + exit 1 unless @deleted; # nothing to do + commit( "Remove ".$deleted[0]->{id}.(scalar @deleted > 1 ? ' ...' : ''), map {$_->{filename}} @deleted ); + + foreach (@deleted) { + # try to delete empty parent directories + my $filename = $_->{filename} =~ s/\/[^\/]+$//r; + rmdir $filename and rmdir $filename =~ s/\/[^\/]+$//r; + } +} + else { print STDERR "Usage: $NAME [COMMAND] [OPTION ...] [ARG ...]\n"; error "Unknown command C<%s>. Try C<%s> for more information.", $COMMAND, "$NAME --help"; diff --git a/cli/icevault.1 b/cli/icevault.1 index 2e40af3..299e591 100644 --- a/cli/icevault.1 +++ b/cli/icevault.1 @@ -152,6 +152,12 @@ reencrypt the entire store. If \fIidentity\fR (resp. \fIidentity\fR/\fIhostname\fR) is omitted, reencrypt all identities found under \fIscheme\fR://\fIhostname\fR/ (resp. \fIscheme\fR://). +.TP +.B rm\fR [\fB-f\fR, \fB--force\fR] [\fB-r\fR, \fB--recursive\fR] [\fIscheme\fR://[\fIhostname\fR/[\fIidentity\fR]] ...] +Delete the given identity prefix(es). Croak if \fIidentity\fR is +omitted, unless \fB-r\fR is set. If \fB-f\fR is set, don't prompt before +each deletion. + .SH GLOBAL OPTIONS .TP -- cgit v1.2.3