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@";
my $TBBASE = "@TBBASE@";
my $TBWWW = "@TBWWW@";
......@@ -271,6 +272,7 @@ sub DESTROY {
sub LookupByURL($$)
my ($class, $url) = @_;
my ($pid,$imagename);
return undef
if (! ($url =~ /^(ftp|http|https):/));
......@@ -281,12 +283,35 @@ sub LookupByURL($$)
DBQueryWarn("select pid,imagename from image_versions ".
"where metadata_url=$safe_url and deleted is null");
return undef
if (!$query_result || !$query_result->numrows);
if (!$query_result);
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 "");
return Image->Lookup($uuid);
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