Commit d23bc2d2 authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Fix long standing bug in how we deal with image URLs. When the URL refers

to a local disk image we were creating a duplicate of the image via
image_import in the project of the experiment. Change LookupByURL() to
notice that the URL refers to a local disk image, and return that image.
parent 4ad8dead
...@@ -46,6 +46,7 @@ my $CONTROL = "@USERNODE@"; ...@@ -46,6 +46,7 @@ my $CONTROL = "@USERNODE@";
my $TBOPS = "@TBOPSEMAIL@"; my $TBOPS = "@TBOPSEMAIL@";
my $TBAUDIT = "@TBAUDITEMAIL@"; my $TBAUDIT = "@TBAUDITEMAIL@";
my $TBBASE = "@TBBASE@"; my $TBBASE = "@TBBASE@";
my $WWWHOST = "@WWWHOST@";
my $PGENISUPPORT = @PROTOGENI_SUPPORT@; my $PGENISUPPORT = @PROTOGENI_SUPPORT@;
my $DOPROVENANCE = @IMAGEPROVENANCE@; my $DOPROVENANCE = @IMAGEPROVENANCE@;
my $TBWWW = "@TBWWW@"; my $TBWWW = "@TBWWW@";
...@@ -271,6 +272,7 @@ sub DESTROY { ...@@ -271,6 +272,7 @@ sub DESTROY {
sub LookupByURL($$) sub LookupByURL($$)
{ {
my ($class, $url) = @_; my ($class, $url) = @_;
my ($pid,$imagename);
return undef return undef
if (! ($url =~ /^(ftp|http|https):/)); if (! ($url =~ /^(ftp|http|https):/));
...@@ -281,12 +283,35 @@ sub LookupByURL($$) ...@@ -281,12 +283,35 @@ sub LookupByURL($$)
DBQueryWarn("select pid,imagename from image_versions ". DBQueryWarn("select pid,imagename from image_versions ".
"where metadata_url=$safe_url and deleted is null"); "where metadata_url=$safe_url and deleted is null");
return undef return undef
if (!$query_result || !$query_result->numrows); if (!$query_result);
my ($pid,$imagename) = $query_result->fetchrow_array(); if ($query_result->numrows) {
my ($pid,$imagename) = $query_result->fetchrow_array();
# Want latest version.
return Image->Lookup($pid, $imagename);
}
else {
#
# If the URL points back to ourself, find the image it refers
# to. Later phases will catch misuse of the URL (not allowed,
# does not exist).
#
require URI;
require URI::QueryParam;
my $uri = URI->new($url);
return undef
if (!defined($uri));
return undef
if ($uri->host() ne $WWWHOST);
my $uuid = $uri->query_param("uuid");
return undef
if (!defined($uuid) || $uuid eq "");
# Want latest version. return Image->Lookup($uuid);
return Image->Lookup($pid, $imagename); }
return undef;
} }
# #
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment