From 3bf75a3cdf9ff49cec16c9afa9555b33e96467a2 Mon Sep 17 00:00:00 2001 From: Wouter Verhelst Date: Sat, 1 Feb 2025 14:11:13 +0100 Subject: [PATCH] Allow better debugging of file up/download TODO: actually hook it up --- lib/SReview/Files/Collection/HTTP.pm | 6 ++++++ lib/SReview/Files/Collection/Net.pm | 3 +++ lib/SReview/Files/Collection/S3.pm | 7 +++++++ lib/SReview/Files/Collection/SFTP.pm | 7 ++++++- lib/SReview/Files/Factory.pm | 6 ++++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/SReview/Files/Collection/HTTP.pm b/lib/SReview/Files/Collection/HTTP.pm index 1e17ea5..220296b 100644 --- a/lib/SReview/Files/Collection/HTTP.pm +++ b/lib/SReview/Files/Collection/HTTP.pm @@ -28,6 +28,9 @@ sub _get_file { my $dir = $self->workdir; if($self->has_data) { + if($self->download_verbose) { + print "Downloading " . $self->url . "\n"; + } my ($fh, $file) = tempfile("http-XXXXXX", dir => $dir, SUFFIX => ".$ext"); my $ua = Mojo::UserAgent->new; my $res = $ua->get($self->url)->result; @@ -49,6 +52,9 @@ sub _probe_basepath { sub DEMOLISH { my $self = shift; if($self->has_download) { + if($self->download_verbose) { + print "Deleting " . $self->filename . "\n"; + } unlink($self->filename); } } diff --git a/lib/SReview/Files/Collection/Net.pm b/lib/SReview/Files/Collection/Net.pm index 6fc4593..6c70827 100644 --- a/lib/SReview/Files/Collection/Net.pm +++ b/lib/SReview/Files/Collection/Net.pm @@ -58,6 +58,9 @@ sub valid_path_filename { sub DEMOLISH { my $self = shift; if($self->has_download) { + if($self->download_verbose) { + print "removing " . $self->filename . "\n"; + } unlink($self->filename); } } diff --git a/lib/SReview/Files/Collection/S3.pm b/lib/SReview/Files/Collection/S3.pm index 854bd78..d14016a 100644 --- a/lib/SReview/Files/Collection/S3.pm +++ b/lib/SReview/Files/Collection/S3.pm @@ -24,6 +24,9 @@ sub _get_file { my $dir = $self->workdir; if($self->has_data) { + if($self->download_verbose) { + print "downloading " . $self->relname . " to " . $self->filename . "\n"; + } my ($fh, $file) = tempfile("s3-XXXXXX", dir => $dir, SUFFIX => ".$ext"); $self->s3object->get_key_filename($self->relname, "GET", $file); return $file; @@ -44,6 +47,10 @@ sub store_file { my $self = shift; return if(!$self->has_download); + if($self->download_verbose) { + print "uploading " . $self->filename . " to " . $self->onhost_pathname . " via s3\n"; + } + $self->s3object->add_key_filename($self->relname, $self->filename, {}) or croak($self->s3object->errstr); $self->stored; diff --git a/lib/SReview/Files/Collection/SFTP.pm b/lib/SReview/Files/Collection/SFTP.pm index 2331296..573abf5 100644 --- a/lib/SReview/Files/Collection/SFTP.pm +++ b/lib/SReview/Files/Collection/SFTP.pm @@ -51,6 +51,9 @@ sub _get_file { my $dir = $self->workdir; if($self->has_data) { + if($self->download_verbose) { + print "downloading " . $self->relname . " to " . $self->filename . "\n"; + } my ($fh, $file) = tempfile("sftp-XXXXXX", dir => $dir, SUFFIX => ".$ext"); my $size = $self->sftpobject->stat($self->onhost_pathname)->{size}; my $source = $self->sftpobject->open($self->onhost_pathname, O_RDONLY); @@ -83,7 +86,9 @@ sub store_file { # Copy the file to the server. Algorithm taken straight from the # Net::SSH2::File documentation, so see there to understand what and # why. - say "uploading " . $self->filename . " to " . $self->onhost_pathname . " via sftp"; + if($self->download_verbose) { + print "uploading " . $self->filename . " to " . $self->onhost_pathname . " via sftp\n"; + } open my $fh, "<", $self->filename; my $sf = $self->sftpobject->open($self->onhost_pathname, O_WRONLY | O_CREAT | O_TRUNC); diff --git a/lib/SReview/Files/Factory.pm b/lib/SReview/Files/Factory.pm index 8fb5b8b..0d54c44 100644 --- a/lib/SReview/Files/Factory.pm +++ b/lib/SReview/Files/Factory.pm @@ -197,6 +197,12 @@ has 'fileclass' => ( required => 1, ); +has 'download_verbose' => ( + is => 'rw', + isa => 'Bool', + default => 0, +); + has 'collection_name' => ( isa => 'Str', is => 'ro',