aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2011-09-27 16:51:05 -0700
committerH. Peter Anvin <hpa@zytor.com>2011-09-27 16:51:05 -0700
commit2b6318317808e1d0e66c4e6a098693ca776f171b (patch)
treedd9d69d8f48015949bfa1a74845bc02816903eb9
parent3d00d09810f0825cc8a07f6af1585876a6621f75 (diff)
downloadkup-2b6318317808e1d0e66c4e6a098693ca776f171b.tar.gz
Add LINK command (very similar to MOVE!)
MOVE and LINK are so similar that they can share virtually all the infrastructure.
-rwxr-xr-xkorgupload46
-rwxr-xr-xkup13
2 files changed, 33 insertions, 26 deletions
diff --git a/korgupload b/korgupload
index 60ba873..250ef48 100755
--- a/korgupload
+++ b/korgupload
@@ -600,41 +600,43 @@ sub do_mkdir(@)
unlock_tree();
}
-sub move_file(@)
+sub move_or_link_file($@)
{
- my @args = @_;
+ my($cmd, @args) = @_;
if (scalar(@args) != 2) {
- fatal("Bad MOVE command");
+ fatal("Bad $cmd command");
}
+ my $op = ($cmd eq 'MOVE') ? \&rename : \&link;
+
my($from, $to) = @args;
if (!is_valid_filename($from) || !is_valid_filename($to)) {
- fatal("Invalid filename in MOVE command");
+ fatal("Invalid filename in $cmd command");
}
if ($from =~ /\.(bz2|xz|sign)$/) {
- fatal("MOVE of individual .bz2, .xz, or .sign files not supported");
+ fatal("$cmd of individual .bz2, .xz, or .sign files not supported");
}
if ($to =~ /\.(bz2|xz|sign)$/) {
- fatal("MOVE to filename ending in .bz2, .xz or .sign");
+ fatal("$cmd to filename ending in .bz2, .xz or .sign");
}
if ($from =~ /\.gz$/ && $to !~ /\.gz$/) {
- fatal("MOVE of .gz file must itself end in .gz");
+ fatal("$cmd of .gz file must itself end in .gz");
}
if ($from !~ /\.gz$/ && $to =~ /\.gz$/) {
- fatal("MOVE of non-.gz file must not end in .gz");
+ fatal("$cmd of non-.gz file must not end in .gz");
}
lock_tree();
if (!-e $data_path.$from) {
- fatal("MOVE of nonexistent object");
+ fatal("$cmd of nonexistent object");
} elsif (-d $data_path.$from) {
- if (!rename($data_path.$from, $data_path.$to)) {
- fatal("MOVE of directory failed");
+ if (!$op->($data_path.$from, $data_path.$to)) {
+ fatal("$cmd of directory failed");
}
} elsif (-f $data_path.$from) {
if ($from =~ /^(.*)\.gz$/) {
@@ -654,11 +656,11 @@ sub move_file(@)
fatal("Trying to overwrite a non-file");
}
- if (!rename($data_path.$from_stem.'.gz', $data_path.$to_stem.'.gz') ||
- !rename($data_path.$from_stem.'.bz2', $data_path.$to_stem.'.bz2') ||
- !rename($data_path.$from_stem.'.xz', $data_path.$to_stem.'.xz') ||
- !rename($data_path.$from_stem.'.sign', $data_path.$to_stem.'.sign')) {
- fatal("MOVE of compressed file failed");
+ if (!$op->($data_path.$from_stem.'.gz', $data_path.$to_stem.'.gz') ||
+ !$op->($data_path.$from_stem.'.bz2', $data_path.$to_stem.'.bz2') ||
+ !$op->($data_path.$from_stem.'.xz', $data_path.$to_stem.'.xz') ||
+ !$op->($data_path.$from_stem.'.sign', $data_path.$to_stem.'.sign')) {
+ fatal("$cmd of compressed file failed");
}
} else {
if (-e $data_path.$to.'.gz' ||
@@ -672,13 +674,13 @@ sub move_file(@)
fatal("Trying to overwrite non-file");
}
- if (!rename($data_path.$from, $data_path.$to) ||
- !rename($data_path.$from.'.sign', $data_path.$to.'.sign')) {
- fatal("MOVE of plain file failed");
+ if (!$op->($data_path.$from, $data_path.$to) ||
+ !$op->($data_path.$from.'.sign', $data_path.$to.'.sign')) {
+ fatal("$cmd of plain file failed");
}
}
} else {
- fatal("MOVE of non-directory/non-file not currently supported");
+ fatal("$cmd of non-directory/non-file not currently supported");
}
unlock_tree();
@@ -716,8 +718,8 @@ while (defined($line = <STDIN>)) {
put_file(@args);
} elsif ($cmd eq 'MKDIR') {
do_mkdir(@args);
- } elsif ($cmd eq 'MOVE') {
- move_file(@args);
+ } elsif ($cmd eq 'MOVE' || $cmd eq 'LINK') {
+ move_or_link_file($cmd, @args);
} elsif ($cmd eq 'DONE') {
last;
} else {
diff --git a/kup b/kup
index 0e878de..3efd57e 100755
--- a/kup
+++ b/kup
@@ -53,6 +53,7 @@ sub usage($) {
print STDERR " put --diff remote_tree ref1 ref2 signature remote_path\n";
print STDERR " mkdir remote_path\n";
print STDERR " mv|move old_path new_path\n";
+ print STDERR " ln|link old_path new_path\n";
exit $err;
}
@@ -304,9 +305,11 @@ sub cmd_mkdir()
}
}
-# MOVE command
-sub cmd_move()
+# MOVE or LINK command
+sub cmd_move_link($)
{
+ my($cmd) = @_;
+
my $from = shift @args;
my $to = shift @args;
@@ -344,7 +347,7 @@ sub cmd_move()
}
if ($real) {
- print 'MOVE ', url_encode($from), ' ', url_encode($to), "\n";
+ print $cmd, ' ', url_encode($from), ' ', url_encode($to), "\n";
}
}
@@ -365,7 +368,9 @@ sub process_commands()
} elsif ($cmd eq 'mkdir') {
cmd_mkdir();
} elsif ($cmd eq 'move' || $cmd eq 'mv') {
- cmd_move();
+ cmd_move_link('MOVE');
+ } elsif ($cmd eq 'link' || $cmd eq 'ln') {
+ cmd_move_link('LINK');
} else {
die "$0: unknown command: $cmd\n";
}