Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Koha/File/Transport.pm
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,19 @@ sub list_files {
die "Subclass must implement list_files";
}

=head3 delete_file

my $success = $transport->delete_file($filename);

Method for deleting a file from the current file server

=cut

sub delete_file {
my ( $self, $remote_file ) = @_;
die "Subclass must implement delete_file";
}

=head3 rename_file

my $success = $transport->rename_file($old_name, $new_name);
Expand Down
28 changes: 28 additions & 0 deletions Koha/File/Transport/FTP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,34 @@ sub list_files {
return \@file_list;
}

=head3 delete_file

my $success = $server->delete_file($filename);

Deletes a file on the server connection.

Returns true on success or undefined on failure.

=cut

sub delete_file {
my ( $self, $remote_file ) = @_;
my $operation = "delete";

$self->{connection}->delete($remote_file)
or return $self->_abort_operation($operation);

$self->add_message(
{
message => $operation,
type => 'success',
payload => { remote_file => $remote_file }
}
);

return 1;
}

=head3 rename_file

my $success = $server->rename_file($old_name, $new_name);
Expand Down
62 changes: 62 additions & 0 deletions Koha/File/Transport/Local.pm
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,68 @@ sub list_files {
return \@files;
}

=head3 delete_file

my $success = $server->delete_file($remote_file);

Deletes a file in the current directory.

Returns true on success or undefined on failure.

=cut

sub delete_file {
my ( $self, $remote_file ) = @_;
my $operation = 'delete';

my $base_directory = $self->{current_directory}
|| $self->download_directory
|| $self->upload_directory
|| '.';

my $target_path = File::Spec->file_name_is_absolute($remote_file)
? $remote_file
: File::Spec->catfile( $base_directory, $remote_file );

unless ( -f $target_path ) {
$self->add_message(
{
message => $operation,
type => 'error',
payload => {
error => "File not found: $target_path",
path => $target_path
}
}
);
return;
}

unless ( unlink $target_path ) {
$self->add_message(
{
message => $operation,
type => 'error',
payload => {
error => $!,
path => $target_path
}
}
);
return;
}

$self->add_message(
{
message => $operation,
type => 'success',
payload => { path => $target_path }
}
);

return 1;
}

=head3 rename_file

my $success = $server->rename_file($old_name, $new_name);
Expand Down
33 changes: 33 additions & 0 deletions Koha/File/Transport/SFTP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,39 @@ sub list_files {
return $file_list;
}

=head3 delete_file

my $success = $transport->delete_file($filename);

Deletes a file on the server connection.

Returns true on success or undefined on failure.

=cut

sub delete_file {
my ( $self, $remote_file ) = @_;
my $operation = 'delete';

$self->{connection}->remove($remote_file)
or return $self->_abort_operation( $operation, $remote_file );

$self->add_message(
{
message => $operation,
type => 'success',
payload => {
status => $self->{connection}->status,
error => $self->{connection}->error,
path => $self->{connection}->cwd,
detail => $remote_file
}
}
);

return 1;
}

=head3 rename_file

my $success = $server->rename_file($old_name, $new_name);
Expand Down
Loading