aboutsummaryrefslogtreecommitdiff
path: root/perl/lib/Wallet/Server.pm
diff options
context:
space:
mode:
authorRuss Allbery <eagle@eyrie.org>2014-12-08 20:57:57 -0800
committerRuss Allbery <eagle@eyrie.org>2014-12-08 20:57:57 -0800
commit7856dc7cc5e16140c0084474fe54338f293bf77e (patch)
tree5948678fb9c0a30b7d72057c9952ac8836ae2499 /perl/lib/Wallet/Server.pm
parentdd295a55a6f02e7585a9f5be9e8b434c6d14d040 (diff)
parente73a80c6bc23f16544c35e7dc3bf61ca9292c3b5 (diff)
Imported Upstream version 1.2upstream/1.2
Diffstat (limited to 'perl/lib/Wallet/Server.pm')
-rw-r--r--perl/lib/Wallet/Server.pm46
1 files changed, 46 insertions, 0 deletions
diff --git a/perl/lib/Wallet/Server.pm b/perl/lib/Wallet/Server.pm
index 95fd4e6..f6ea342 100644
--- a/perl/lib/Wallet/Server.pm
+++ b/perl/lib/Wallet/Server.pm
@@ -244,6 +244,52 @@ sub autocreate {
return 1;
}
+# Rename an object. We validate that the new name also falls within naming
+# constraints, then need to change all references to that. If any updates
+# fail, we'll revert the entire commit.
+sub rename {
+ my ($self, $type, $name, $new_name) = @_;
+
+ my $schema = $self->{schema};
+ my $user = $self->{user};
+ my $host = $self->{host};
+
+ # Currently we only can rename file objects.
+ if ($type ne 'file') {
+ $self->error ('rename is only supported for file objects');
+ return;
+ }
+
+ # Validate the new name.
+ if (defined (&Wallet::Config::verify_name)) {
+ my $error = Wallet::Config::verify_name ($type, $new_name, $user);
+ if ($error) {
+ $self->error ("${type}:${name} rejected: $error");
+ return;
+ }
+ }
+
+ # Get the object and error if it does not already exist.
+ my $class = $self->type_mapping ($type);
+ unless ($class) {
+ $self->error ("unknown object type $type");
+ return;
+ }
+ my $object = eval { $class->new ($type, $name, $schema) };
+ if ($@) {
+ $self->error ($@);
+ return;
+ }
+
+ # Rename the object.
+ eval { $object->rename ($new_name, $schema, $user, $host) };
+ if ($@) {
+ $self->error ($@);
+ return;
+ }
+ return $object;
+}
+
# Given the name and type of an object, returns a Perl object representing it
# or returns undef and sets the internal error.
sub retrieve {