Skip to content

Commit

Permalink
Allow better debugging of file up/download
Browse files Browse the repository at this point in the history
TODO: actually hook it up
  • Loading branch information
yoe committed Feb 1, 2025
1 parent 9e080ee commit 3bf75a3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/SReview/Files/Collection/HTTP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/SReview/Files/Collection/Net.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
7 changes: 7 additions & 0 deletions lib/SReview/Files/Collection/S3.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion lib/SReview/Files/Collection/SFTP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions lib/SReview/Files/Factory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ has 'fileclass' => (
required => 1,
);

has 'download_verbose' => (
is => 'rw',
isa => 'Bool',
default => 0,
);

has 'collection_name' => (
isa => 'Str',
is => 'ro',
Expand Down

0 comments on commit 3bf75a3

Please sign in to comment.