Commit 2a38a18d authored by Leigh B Stoller's avatar Leigh B Stoller

Need to make sure that the image directory is created when doing the

initial import of an image, Normally this is done in create_image, but
need to do it here as well.
parent b7027d41
......@@ -2764,6 +2764,28 @@ sub CreateImageDir($)
print STDERR "Could not mkdir " . $self->path() . ": $!";
return -1;
}
# If we are root and had to create the directory, then the owner
# and group are going to be set wrong.
if ($EUID == 0) {
my $group = $self->GetGroup();
if (!defined($group)) {
print STDERR "Could not get group for $self\n";
return -1;
}
my $leader = $group->GetLeader();
if (!defined($leader)) {
print STDERR "Could not get leader for $group\n";
return -1;
}
my $uid = $leader->unix_uid();
my $gid = $group->unix_gid();
if (! chown($uid, $gid, $self->path())) {
print STDERR "Could not chown($uid,$gid) " .
$self->path() . ": $!\n";
return -1;
}
}
return 0;
}
......
......@@ -810,8 +810,8 @@ if ($pid ne TBOPSPID()) {
# sure the target directory exists in the image path is a directory.
#
# Make sure the path directory exists.
if ($image->IsDirPath() && ! -e $image->path() && !mkdir($image->path(), 0775)){
fatal("Could not mkdir " . $image->path() . ": $!");
if ($image->CreateImageDir()) {
fatal("Could not create image directory");
}
open(FILE, "> $filename") or
fatal("Could not create $filename: $!");
......
#!/usr/bin/perl -w
#
# Copyright (c) 2010-2016 University of Utah and the Flux Group.
# Copyright (c) 2010-2017 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -450,6 +450,11 @@ if ($getimage) {
# Run as root to access /proj
$EUID = $UID = 0;
if (! -e $image->FullImageFile() || $newhash ne $image->hash() || $force) {
# Make sure the path directory exists.
if ($image->CreateImageDir()) {
$image->Unlock();
exit(1);
}
$EUID = $UID = $SAVEUID;
if (DownLoadImage($image, $newhash, $user, $group)) {
......
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