Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
emulab
emulab-devel
Commits
7eb07802
Commit
7eb07802
authored
Jul 24, 2017
by
Leigh B Stoller
Browse files
Allow file:// urls for the metdata and image URLs so that offline
sites can work around being offline.
parent
e9619108
Changes
2
Hide whitespace changes
Inline
Side-by-side
db/Image.pm.in
View file @
7eb07802
...
...
@@ -364,7 +364,7 @@ sub LookupByURL($$)
my
($
pid
,$
imagename
);
return
undef
if
(
! ($url =~ /^(ftp|http|https):/));
if
(
! ($url =~ /^(ftp|http|https
|file
):/));
my
$
safe_url
=
DBQuoteSpecial
($
url
);
...
...
utils/image_import.in
View file @
7eb07802
...
...
@@ -358,7 +358,10 @@ if ($newhash =~/^(.*)$/) {
if
(
!
$update
)
{
# New mysal 5.7 limit of 64 chars on locks. Use the uuid.
my
$lockname
;
if
(
$url
=~
/uuid=([-\w]+)$/
)
{
if
(
length
(
$url
)
<
64
)
{
$lockname
=
$
1
;
}
elsif
(
$url
=~
/uuid=([-\w]+)$/
)
{
$lockname
=
$
1
;
}
else
{
...
...
@@ -839,6 +842,18 @@ sub FetchImageFile($$$)
}
$UID
=
$SAVEUID
;
}
elsif
(
$url
=~
/^file:\/\/(.*)/
)
{
system
("
/bin/cp -fp '$1'
$localfile
");
if
(
$?
)
{
print
STDERR
"
Could not copy $1 to
$localfile
\n
";
return
-
1
;
}
system
("
$SHA1
$localfile
>
${localfile}
.sha1
");
if
(
$?
)
{
print
STDERR
"
Could not generate sha1 hash of
$localfile
\n
";
return
-
1
;
}
}
else
{
print
"
Downloading
$url
...
\n
";
...
...
@@ -867,23 +882,34 @@ sub FetchImageFile($$$)
sub
FetchMetadata
($)
{
my
(
$url
)
=
@_
;
$url
.=
"
&clientversion=
"
.
$METADATA_CLIENTVERSION
;
my
$safe_url
=
User::
escapeshellarg
(
$url
);
my
$xml
=
"";
my
$opts
=
(
$debug
?
""
:
"
-q
");
my
$cmd
=
"
$WGET
$opts
--no-check-certificate -O -
$safe_url
";
$cmd
.=
"
|
$DD
bs=1 count=5k
";
if
(
$debug
)
{
print
"
$cmd
\n
";
if
(
$url
=~
/^file:\/\/(.*)/
)
{
open
(
META
,
$
1
)
or
fatal
("
Could not open $1: $!
");
while
(
<
META
>
)
{
$xml
.=
$_
;
}
close
(
META
);
}
open
(
META
,
"
$cmd
|
")
or
fatal
("
Could not fetch metadata from
$url
");
while
(
<
META
>
)
{
$xml
.=
$_
;
else
{
$url
.=
"
&clientversion=
"
.
$METADATA_CLIENTVERSION
;
my
$safe_url
=
User::
escapeshellarg
(
$url
);
my
$opts
=
(
$debug
?
""
:
"
-q
");
my
$cmd
=
"
$WGET
$opts
--no-check-certificate -O -
$safe_url
";
$cmd
.=
"
|
$DD
bs=1 count=5k
";
if
(
$debug
)
{
print
"
$cmd
\n
";
}
open
(
META
,
"
$cmd
|
")
or
fatal
("
Could not fetch metadata from
$url
");
while
(
<
META
>
)
{
$xml
.=
$_
;
}
close
(
META
)
or
fatal
("
Could not read metadata from
$url
");
}
close
(
META
)
or
fatal
("
Could not read metadata from
$url
");
if
(
$xml
eq
"")
{
fatal
("
Failed to get metadata from
$url
");
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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