From 9ba7516ab4195b940e9d1eb49d51133082770b93 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 10 Jan 2013 12:25:09 -0500 Subject: [PATCH] Support FTP/SCP delete operation in RemoteAccount Signed-off-by: Bill Erickson Signed-off-by: Mike Rylander --- .../lib/OpenILS/Utils/RemoteAccount.pm | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/RemoteAccount.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/RemoteAccount.pm index 164e227149..34a725729f 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/RemoteAccount.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/RemoteAccount.pm @@ -226,7 +226,6 @@ sub key_check { # TOP LEVEL methods -# TODO: delete for both FTP and SSH2 sub get { my $self = shift; @@ -322,6 +321,31 @@ sub ls { } } +sub delete { + my $self = shift; + my $params = shift; + + $params = {remote_file => $params} unless ref $params; + $self->init($params); # secondary init + + my $file = $params->{remote_file}; + + if (!$file) { + $logger->warn("No file specified for deletion"); + return undef; + } + + $logger->info("Deleting remote file '$file'"); + + if ($self->type eq "FTP") { + return $self->delete_ftp($file); + } else { + my %keys = $self->key_check($params); + return $self->delete_ssh2(\%keys, $file); + } +} + + # Checks if the filename part of a pathname has one or more glob characters # We split out the filename portion of the path # Detect glob or no glob. @@ -499,6 +523,14 @@ sub ls_ssh2_full { } +sub delete_ssh2 { + my $self = shift; + my $keys = shift; + my $file = shift; + my $sftp = $self->_ssh2($keys)->sftp; + return $sftp->unlink($file); +} + sub _slash_path { my $self = shift; my $dir = shift || '.'; @@ -634,8 +666,10 @@ sub ls_ftp { # returns full path like: dir/path/file.ext return @list; } -sub delete_ftp { # XXX not yet used - $_[0]->_ftp->delete($_[1]); +sub delete_ftp { + my $self = shift; + my $file = shift; + return $self->_ftp->delete($file); } sub _pkg { # Not OO -- 2.43.2