Commit 60f7d7f9 authored by Leigh Stoller's avatar Leigh Stoller

Change to UUID; an image has a UUID, but so does each version. Using

the UUID of the image gets you the most recent released version, but
you can use the UUID of a specific version.
parent b74e3f9b
......@@ -91,7 +91,8 @@ sub Lookup($$;$$)
if (!defined($arg2)) {
if ($arg1 =~ /^(\d*)$/) {
my $result =
DBQueryWarn("select v.* from images as i ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
" from images as i ".
"left join image_versions as v on ".
" v.imageid=i.imageid and v.version=i.version ".
"where i.imageid='$arg1'");
......@@ -103,7 +104,8 @@ sub Lookup($$;$$)
elsif ($arg1 =~ /^([-\w]*),([-\w\.\+]*)$/ ||
$arg1 =~ /^([-\w]*)\/([-\w\.\+]*)$/) {
my $result =
DBQueryWarn("select v.* from images as i ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
" from images as i ".
"left join image_versions as v on ".
" v.imageid=i.imageid and v.version=i.version ".
"where i.pid='$1' and i.imagename='$2'");
......@@ -115,7 +117,8 @@ sub Lookup($$;$$)
elsif ($arg1 =~ /^([-\w]*),([-\w\.\+]*):(\d*)$/ ||
$arg1 =~ /^([-\w]*)\/([-\w\.\+]*):(\d*)$/) {
my $result =
DBQueryWarn("select v.* from images as i ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
" from images as i ".
"left join image_versions as v on ".
" v.imageid=i.imageid ".
"where i.pid='$1' and i.imagename='$2' and ".
......@@ -126,10 +129,29 @@ sub Lookup($$;$$)
return BlessRow($class, $result->fetchrow_hashref())
}
elsif ($arg1 =~ /^\w+\-\w+\-\w+\-\w+\-\w+$/) {
#
# First look to see if the uuid is for the image itself,
# which means current version. Otherwise look for a
# version with the uuid.
#
my $result =
DBQueryWarn("select * from image_versions ".
"where uuid='$arg1' and deleted is null");
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
" from images as i ".
"left join image_versions as v on ".
" v.imageid=i.imageid and v.version=i.version ".
"where i.uuid='$arg1'");
return undef
if (!$result);
return BlessRow($class, $result->fetchrow_hashref())
if ($result->numrows);
$result =
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
" from image_versions as v ".
"left join images as i on ".
" v.imageid=i.imageid ".
"where v.uuid='$arg1' and ".
" v.deleted is null");
return undef
if (! $result || !$result->numrows);
......@@ -140,7 +162,8 @@ sub Lookup($$;$$)
elsif (!defined($arg3)) {
if ($arg1 =~ /^\d+$/ && $arg2 =~ /^\d+$/) {
my $result =
DBQueryWarn("select v.* from images as i ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
" from images as i ".
"left join image_versions as v on ".
" v.imageid=i.imageid ".
"where i.imageid='$arg1' and v.version='$arg2' ".
......@@ -152,7 +175,8 @@ sub Lookup($$;$$)
}
elsif ($arg1 =~ /^[-\w]*$/ && $arg2 =~ /^([-\w\.\+]*):(\d+)$/) {
my $result =
DBQueryWarn("select v.* from images as i ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
" from images as i ".
"left join image_versions as v on ".
" v.imageid=i.imageid ".
"where i.pid='$arg1' and i.imagename='$1' and ".
......@@ -164,7 +188,8 @@ sub Lookup($$;$$)
}
elsif ($arg1 =~ /^[-\w]*$/ && $arg2 =~ /^[-\w\.\+]*$/) {
my $result =
DBQueryWarn("select v.* from images as i ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
" from images as i ".
"left join image_versions as v on ".
" v.imageid=i.imageid and v.version=i.version ".
"where i.pid='$arg1' and i.imagename='$arg2'");
......@@ -179,7 +204,8 @@ sub Lookup($$;$$)
if ($arg1 =~ /^[-\w]*$/ &&
$arg2 =~ /^[-\w\.\+]*$/ && $arg3 =~ /^\d+$/) {
my $result =
DBQueryWarn("select v.* from images as i ".
DBQueryWarn("select i.*,v.*,i.uuid as image_uuid ".
" from images as i ".
"left join image_versions as v on ".
" v.imageid=i.imageid ".
"where i.pid='$arg1' and i.imagename='$arg2' and ".
......@@ -322,9 +348,11 @@ sub Refresh($)
my $version = $self->version();
my $query_result =
DBQueryWarn("select * from image_versions ".
"where imageid=$imageid and version='$version'");
DBQueryWarn("select v.*,i.uuid as image_uuid ".
" from image_versions as v ".
"left join images as i on ".
" v.imageid=i.imageid ".
"where v.imageid='$imageid' and v.version='$version'");
return -1
if (!$query_result || !$query_result->numrows);
......@@ -424,8 +452,13 @@ sub Create($$$$$$$$)
#
$imageid = TBGetUniqueIndex("next_osid", undef, 1);
}
my $uuid = NewUUID();
#
# The image UUID refers to the image, current version. Then each
# version has its own uuid so it can be referred to.
#
my $image_uuid = NewUUID();
my $version_uuid = NewUUID();
#
# Some fields special cause of quoting.
#
my $desc = "''";
......@@ -435,7 +468,6 @@ sub Create($$$$$$$$)
my $bquery = "imagename='$imagename'";
$bquery .= ",imageid='$imageid'";
$bquery .= ",uuid='$uuid'";
$bquery .= ",pid='$pid',pid_idx='$pid_idx'";
$bquery .= ",gid='$gid',gid_idx='$gid_idx'";
......@@ -443,6 +475,7 @@ sub Create($$$$$$$$)
join(",", map("$_='" . $argref->{$_} . "'", @arg_slots));
$query .= ",creator='$uid',creator_idx='$uid_idx'";
$query .= ",uuid='$version_uuid'";
$query .= ",created=now()";
$query .= ",description=$desc";
$query .= ",hash=" . DBQuoteSpecial($argref->{'hash'})
......@@ -458,7 +491,7 @@ sub Create($$$$$$$$)
}
# Create the main entry:
if (! DBQueryWarn("insert into images set $bquery")) {
if (! DBQueryWarn("insert into images set $bquery,uuid='$image_uuid'")) {
DBQueryWarn("unlock tables");
tberror("Error inserting new images record for $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