Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Projets publics
Ravada-Mirror
Commits
2b8bee4e
Commit
2b8bee4e
authored
Apr 07, 2017
by
Francesc Guasch
Browse files
[#156] Fetch the filename
parent
0d198e93
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/Ravada/VM/KVM.pm
View file @
2b8bee4e
...
...
@@ -766,9 +766,59 @@ sub _search_iso {
$sth->execute($id_iso);
my $row = $sth->fetchrow_hashref;
die "Missing iso_image id=$id_iso" if !keys %$row;
$self->_fetch_filename($row) if $row->{file_re};
$self->_fetch_md5($row) if !$row->{md5} && $row->{md5_url};
return $row;
}
sub _fetch_filename {
my $self = shift;
my $row = shift;
my $ua = new LWP::UserAgent;
my $req = HTTP::Request->new( GET => $row->{url});
my $res = $ua->request($req);
confess "No file_re" if !$row->{file_re};
die $res->status_line if !$res->is_success;
my $file;
my $lines =
''
;
for my $line (split/\n/,$res->content) {
next if $line !~ /iso"/;
$lines .= "$line\n";
my ($found) = $line =~ qr/"($row->{file_re})"/;
next if !$found;
$file=$found if $found;
}
die "No ".qr($row->{file_re})." found on $row->{url}" if !$file;
$row->{url} .= $file;
}
sub _fetch_md5 {
my $self = shift;
my $row = shift;
my $ua = new LWP::UserAgent;
my $req = HTTP::Request->new( GET => $row->{md5_url});
my $res = $ua->request($req);
die $res->error_line if !$res->is_success;
my ($file) = $row->{url} =~ m{.*/(.*)};
confess "No file for $row->{url}" if !$file;
for my $line (split/\n/,$res->content) {
my ($md5) = $line =~ m{^\s*(.*?)\s+.*?$file};
next if !$md5;
$row->{md5} = $md5;
return;
}
die "No MD5 for $file in $row->{md5_url}\n".$res->content;
}
###################################################################################
#
# XML methods
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment