Commit 41b3033c authored by Leigh B. Stoller's avatar Leigh B. Stoller

A bunch more little tweaks wrt the archive support. This stuff needs

a huge amount of work, but really needs someone to test drive it.
parent 7034b6d5
...@@ -301,13 +301,11 @@ elsif ($action eq "list" || ...@@ -301,13 +301,11 @@ elsif ($action eq "list" ||
if ($action eq "missing") { if ($action eq "missing") {
# #
# Figure out what files were accessed by NFS, but not from the # Figure out what files were accessed by NFS, but are not in
# archive directory. # archive directory.
# #
my $userdir = TBExptUserDir($pid, $eid);
# This is special by convention; # This is special by convention;
$subdir = "$userdir/archive"; $subdir = "/archive";
} }
elsif (@ARGV) { elsif (@ARGV) {
$subdir = $ARGV[0]; $subdir = $ARGV[0];
......
...@@ -700,20 +700,34 @@ TBSaveExpLogFiles($pid, $eid); ...@@ -700,20 +700,34 @@ TBSaveExpLogFiles($pid, $eid);
# #
system("cp -Rfp $workdir/ $userdir/tbdata"); system("cp -Rfp $workdir/ $userdir/tbdata");
# Now add that copy to the archive. #
# Copy out some files to the archive directory so that they get saved later.
#
my $archivedir = libArchive::TBUserFileArchiveDirectory($pid, $eid);
if (! -e "$archivedir/tbdata") {
mkdir("$archivedir/tbdata")
or fatal("Failed to mkdir $archivedir/tbdata");
}
if (! -e "$archivedir/nsdata") {
mkdir("$archivedir/nsdata")
or fatal("Failed to mkdir $archivedir/nsdata");
}
system("cp -p $workdir/$nsfile $archivedir/nsdata/nsfile.ns") == 0
or fatal("Failed to copy nsfile to $archivedir/tbdata");
if (defined($logname)) { if (defined($logname)) {
libArchive::TBExperimentArchiveAddFile($pid, $eid, system("cp -p $logname $archivedir/tbdata/log.batchexp") == 0
"$userdir/tbdata/" . EXPTLOGNAME()); or fatal("Failed to copy logfile to $archivedir/tbdata");
} }
libArchive::TBExperimentArchiveAddFile($pid, $eid, "$userdir/tbdata/$repfile");
# system("cp -p $workdir/$repfile $archivedir/tbdata/tbreport.batchexp") == 0
# Make a copy of the NS file where we can get at it easily. Then add it. or fatal("Failed to copy nsfile to $archivedir/tbdata");
#
system("cp -p $workdir/$nsfile $userdir/archive/$nsfile"); # And tell the archive library about the above files.
libArchive::TBExperimentArchiveAddFile($pid, $eid, libArchive::TBExperimentArchiveAddUserFiles($pid, $eid) == 0
"$userdir/archive/$nsfile") == 0 or or fatal("Failed to add user archive files to the archive!");
fatal("Failed to add $userdir/archive/$nsfile to the archive!");
# #
# Do a SavePoint on the experiment files. # Do a SavePoint on the experiment files.
...@@ -1223,14 +1237,14 @@ sub CopyInArchive() ...@@ -1223,14 +1237,14 @@ sub CopyInArchive()
return 0 return 0
if (!defined($copyarg)); if (!defined($copyarg));
my $dstdir = "$userdir/archive"; my $dstdir = "$userdir/archive/nsdata";
if ($copyfrom eq "exp") { if ($copyfrom eq "exp") {
# #
# Copy in from a current experiment. This is probably a bad thing # Copy in from a current experiment. This is probably a bad thing
# to do, but hey. # to do, but hey.
# #
my $srcdir = TBExptUserDir($copypid, $copyeid) . "/archive"; my $srcdir = TBExptUserDir($copypid, $copyeid) . "/archive/nsdata";
if (-e $srcdir) { if (-e $srcdir) {
print "Copying experiment archive from ${srcdir}\n"; print "Copying experiment archive from ${srcdir}\n";
...@@ -1239,19 +1253,12 @@ sub CopyInArchive() ...@@ -1239,19 +1253,12 @@ sub CopyInArchive()
fatal("CopyInArchive: Failed to copy ${srcdir} to $dstdir"); fatal("CopyInArchive: Failed to copy ${srcdir} to $dstdir");
} }
} }
# This is for backwards compatability, and the mv below.
if (! -e "$dstdir/$copyeid.ns") {
my $srcfile = TBExptUserDir($copypid, $copyeid) .
"/tbdata/$copyeid.ns";
system("/bin/cp -p $srcfile $dstdir/$copyeid.ns");
}
} }
else { else {
# #
# Ask for a checkout of the archive. # Ask for a checkout of the archive.
# #
my $subdir = "/proj/$copypid/exp/$copyeid/archive"; my $subdir = "/archive/nsdata";
print "Checking out experiment archive to $dstdir\n"; print "Checking out experiment archive to $dstdir\n";
libArchive::TBCheckoutExperimentArchivebyExptIDX($copyidx, libArchive::TBCheckoutExperimentArchivebyExptIDX($copyidx,
...@@ -1260,12 +1267,6 @@ sub CopyInArchive() ...@@ -1260,12 +1267,6 @@ sub CopyInArchive()
$subdir) $subdir)
== 0 or fatal("CopyInArchive: Checking out archive"); == 0 or fatal("CopyInArchive: Checking out archive");
} }
# The directory contains the old NS file. Move that out of the way
# and set the tempnsfile.
system("/bin/mv -f $dstdir/$copyeid.ns $dstdir/nsfile.ns") == 0
or fatal("CopyInArchive: ".
"Could not mv $dstdir/$copyeid.ns $dstdir/nsfile.ns");
$tempnsfile = "$dstdir/nsfile.ns"; $tempnsfile = "$dstdir/nsfile.ns";
} }
......
...@@ -319,10 +319,9 @@ sub ValidatePath($) ...@@ -319,10 +319,9 @@ sub ValidatePath($)
# temporary store. Later, after all the files are in the tree, must # temporary store. Later, after all the files are in the tree, must
# commit it to the repo. # commit it to the repo.
# #
sub ArchiveAdd($$;$$) sub ArchiveAdd($$;$$$)
{ {
my ($archive_idx, $pathname, $view, $exact) = @_; my ($archive_idx, $pathname, $view, $exact, $special) = @_;
my $rootdir;
$view = $defaultview $view = $defaultview
if (!defined($view)); if (!defined($view));
...@@ -330,6 +329,9 @@ sub ArchiveAdd($$;$$) ...@@ -330,6 +329,9 @@ sub ArchiveAdd($$;$$)
$exact = 0 $exact = 0
if (!defined($exact)); if (!defined($exact));
$special = 0
if (!defined($special));
# This returns a taint checked value in $pathname. # This returns a taint checked value in $pathname.
if (ValidatePath(\$pathname) != 0) { if (ValidatePath(\$pathname) != 0) {
print STDERR "ArchiveAdd: Could not validate pathname $pathname\n"; print STDERR "ArchiveAdd: Could not validate pathname $pathname\n";
...@@ -339,9 +341,32 @@ sub ArchiveAdd($$;$$) ...@@ -339,9 +341,32 @@ sub ArchiveAdd($$;$$)
# #
# Strip leading /dir from the pathname, we need it below. # Strip leading /dir from the pathname, we need it below.
# #
if ($pathname =~ /^[\/]+(\w+)\/([-\w\/\.\+\@,~]+)$/) { my ($rootdir, $sourcedir, $sourcefile);
$rootdir = $1; my $rsyncopt = "";
$pathname = $2;
if ($special) {
#
# Last parth of path must be a directory.
#
if (! -d $pathname) {
print STDERR "ArchiveAdd: Must be a direcotory: $pathname\n";
return -1;
}
my ($filename,$directory,undef) = fileparse($pathname);
#
# Basically, copy the last part (directory) to / of the checkin.
# eg: cp /proj/pid/exp/eid/archive/... /archive of the checkins.
#
$rootdir = $filename;
$sourcedir = $directory;
$sourcefile = $filename . "/";
}
elsif ($pathname =~ /^[\/]+(\w+)\/([-\w\/\.\+\@,~]+)$/) {
$rootdir = $1;
$sourcedir = $1;
$sourcefile = $2;
$rsyncopt = "-R";
} }
else { else {
print STDERR "ArchiveAdd: Illegal characters in pathname $pathname\n"; print STDERR "ArchiveAdd: Illegal characters in pathname $pathname\n";
...@@ -362,7 +387,6 @@ sub ArchiveAdd($$;$$) ...@@ -362,7 +387,6 @@ sub ArchiveAdd($$;$$)
return -1; return -1;
} }
my $repodir = "$directory/repo"; my $repodir = "$directory/repo";
my $checkout = "$directory/checkouts/$view";
my $checkin = "$directory/checkins/$view"; my $checkin = "$directory/checkins/$view";
# #
...@@ -375,17 +399,18 @@ sub ArchiveAdd($$;$$) ...@@ -375,17 +399,18 @@ sub ArchiveAdd($$;$$)
mysystem("$MKDIR $checkin/$rootdir") == 0 or return -1; mysystem("$MKDIR $checkin/$rootdir") == 0 or return -1;
} }
if (-f "/${rootdir}/${pathname}" || !$exact) { if (-f "/${sourcedir}/${sourcefile}" || !$exact) {
mysystem("$TAR cf - -C /$rootdir $pathname | ". mysystem("$TAR cf - -C /$sourcedir $sourcefile | ".
"$TAR xf - -U -C $checkin/$rootdir"); "$TAR xf - -U -C $checkin/$rootdir");
mysystem("$CHMOD 775 $checkin/$rootdir/$pathname"); mysystem("$CHMOD 775 $checkin/$rootdir/$sourcefile");
} }
else { else {
mysystem("cd /$rootdir; ". mysystem("cd /$sourcedir; ".
"$RSYNC -R -rtgoDlz --delete ${pathname} $checkin/$rootdir"); "$RSYNC $rsyncopt -rtgoDlz ".
" --delete ${sourcefile} $checkin/$rootdir");
} }
if ($?) { if ($?) {
print STDERR "ArchiveAdd: Could not copy in /$rootdir/$pathname\n"; print STDERR "ArchiveAdd: Could not copy in $pathname\n";
return -1; return -1;
} }
return 0; return 0;
...@@ -1418,6 +1443,19 @@ sub TBExperimentArchiveAddTracedFiles($$) ...@@ -1418,6 +1443,19 @@ sub TBExperimentArchiveAddTracedFiles($$)
return 0; return 0;
} }
#
# Return the archive directory for an experiment.
#
sub TBUserFileArchiveDirectory($$)
{
my ($pid, $eid) = @_;
my $userdir = TBExptUserDir($pid, $eid);
my $userarch = "$userdir/archive";
return $userarch;
}
# #
# Add files the user explicitly wants archived # Add files the user explicitly wants archived
# #
...@@ -1425,7 +1463,7 @@ sub TBExperimentArchiveAddUserFiles($$) ...@@ -1425,7 +1463,7 @@ sub TBExperimentArchiveAddUserFiles($$)
{ {
my ($pid, $eid) = @_; my ($pid, $eid) = @_;
my ($archive_idx, $view); my ($archive_idx, $view);
return 0 return 0
if (!doarchiving($pid)); if (!doarchiving($pid));
...@@ -1439,7 +1477,7 @@ sub TBExperimentArchiveAddUserFiles($$) ...@@ -1439,7 +1477,7 @@ sub TBExperimentArchiveAddUserFiles($$)
my $userarch = "$userdir/archive"; my $userarch = "$userdir/archive";
if (-e $userarch) { if (-e $userarch) {
$rval = ArchiveAdd($archive_idx, $userarch, $view, 1); $rval = ArchiveAdd($archive_idx, $userarch, $view, 1, 1);
return $rval return $rval
if ($rval != 0); if ($rval != 0);
......
...@@ -1079,17 +1079,38 @@ TBSaveExpLogFiles($pid, $eid); ...@@ -1079,17 +1079,38 @@ TBSaveExpLogFiles($pid, $eid);
# #
system("cp -Rfp $workdir/ $userdir/tbdata/"); system("cp -Rfp $workdir/ $userdir/tbdata/");
# Now add that copy to the archive. #
# Copy out some files to the archive directory so that they get saved later.
#
$archivedir = libArchive::TBUserFileArchiveDirectory($pid, $eid);
if (! -e "$archivedir/tbdata") {
mkdir("$archivedir/tbdata")
or fatal("Failed to mkdir $archivedir/tbdata");
}
if (! -e "$archivedir/nsdata") {
mkdir("$archivedir/nsdata")
or fatal("Failed to mkdir $archivedir/nsdata");
}
if ($inout eq "modify") {
system("cp -p $workdir/$eid.ns $archivedir/nsdata/nsfile.ns") == 0
or fatal("Failed to copy nsfile to $archivedir/tbdata");
}
if (defined($logname)) { if (defined($logname)) {
libArchive::TBExperimentArchiveAddFile($pid, $eid, system("cp -p $logname $archivedir/tbdata/log.$tag") == 0
"$userdir/tbdata/" . EXPTLOGNAME()); or fatal("Failed to copy logfile to $archivedir/tbdata");
}
if (-e $repfile) {
system("cp -p $workdir/$repfile $archivedir/tbdata/tbreport.$tag") == 0
or fatal("Failed to copy nsfile to $archivedir/tbdata");
} }
# Always copy the NS file into the archive. # And tell the archive library about the above files.
system("cp -p $workdir/$eid.ns $userdir/archive/$eid.ns"); libArchive::TBExperimentArchiveAddUserFiles($pid, $eid) == 0
libArchive::TBExperimentArchiveAddFile($pid, $eid, or fatal("Failed to add user archive files to the archive!");
"$userdir/archive/$eid.ns") == 0 or
fatal("Failed to add $userdir/$eid.ns to the archive!");
# #
# The archive gets different treatment when doing a swapmod. # The archive gets different treatment when doing a swapmod.
......
...@@ -16,47 +16,52 @@ $isadmin = ISADMIN($uid); ...@@ -16,47 +16,52 @@ $isadmin = ISADMIN($uid);
# #
# Verify page arguments. # Verify page arguments.
#
if (!isset($pid) ||
strcmp($pid, "") == 0) {
USERERROR("You must provide a Project ID.", 1);
}
if (!isset($eid) ||
strcmp($eid, "") == 0) {
USERERROR("You must provide an Experiment ID.", 1);
}
if (!TBvalid_pid($pid)) {
PAGEARGERROR("Invalid project ID.");
}
if (!TBvalid_eid($eid)) {
PAGEARGERROR("Invalid experiment ID.");
}
#
# Standard Testbed Header now that we have the pid/eid okay.
# #
PAGEHEADER("Experiment Archive ($pid/$eid)"); if (isset($exptidx) && $exptidx != "") {
if (!TBvalid_integer($exptidx)) {
PAGEARGERROR("Invalid experiment index.");
}
PAGEHEADER("Experiment Archive ($exptidx)");
# unset($pid);
# Check to make sure this is a valid PID/EID tuple. unset($eid);
# unset($gid);
if (! TBValidExperiment($pid, $eid)) { TBExptidx2PidEid($exptidx, $pid, $eid, $gid);
USERERROR("The experiment $eid is not a valid experiment ".
"in project $pid.", 1);
}
# $url = preg_replace("/archive_view/", "cvsweb/cvsweb",
# Verify Permission. $_SERVER['REQUEST_URI']);
#
if (! TBExptAccessCheck($uid, $pid, $eid, $TB_EXPT_READINFO)) {
USERERROR("You do not have permission to view experiment $eid!", 1);
} }
else {
if (!isset($pid) ||
strcmp($pid, "") == 0) {
USERERROR("You must provide a Project ID.", 1);
}
if (!isset($eid) ||
strcmp($eid, "") == 0) {
USERERROR("You must provide an Experiment ID.", 1);
}
if (!TBvalid_pid($pid)) {
PAGEARGERROR("Invalid project ID.");
}
if (!TBvalid_eid($eid)) {
PAGEARGERROR("Invalid experiment ID.");
}
$exptidx = TBExptIndex($pid, $eid); #
if ($exptidx < 0) { # Check to make sure this is a valid PID/EID tuple.
TBERROR("Could not get experiment index for $pid/$eid!", 1); #
if (! TBValidExperiment($pid, $eid)) {
USERERROR("The experiment $eid is not a valid experiment ".
"in project $pid.", 1);
}
$exptidx = TBExptIndex($pid, $eid);
if ($exptidx < 0) {
TBERROR("Could not get experiment index for $pid/$eid!", 1);
}
PAGEHEADER("Experiment Archive ($pid/$eid)");
$url = "cvsweb/cvsweb.php3/${exptidx}?exptidx=$exptidx";
} }
$url = "cvsweb/cvsweb.php3/${exptidx}?exptidx=$exptidx";
# This is how you get forms to align side by side across the page. # This is how you get forms to align side by side across the page.
$style = 'style="float:left; width:33%;"'; $style = 'style="float:left; width:33%;"';
...@@ -64,20 +69,26 @@ $style = 'style="float:left; width:33%;"'; ...@@ -64,20 +69,26 @@ $style = 'style="float:left; width:33%;"';
echo "<center>\n"; echo "<center>\n";
echo "<font size=+1> echo "<font size=+1>
This is the Subversion archive for your experiment.<br></font>"; This is the Subversion archive for your experiment.<br></font>";
echo "<form action='archive_tag.php3' $style method=get>\n"; if (isset($pid)) {
echo "<b><input type=submit name=tag value='Tag Archive'></b>"; echo "<form action='${TBBASE}/archive_tag.php3' $style method=get>\n";
echo "<input type=hidden name=pid value='$pid'>"; echo "<b><input type=submit name=tag value='Tag Archive'></b>";
echo "<input type=hidden name=eid value='$eid'>"; echo "<input type=hidden name=pid value='$pid'>";
echo "</form>"; echo "<input type=hidden name=eid value='$eid'>";
echo "<form action='archive_tags.php3' $style method=get>"; echo "</form>";
}
echo "<form action='${TBBASE}/archive_tags.php3' $style method=get>";
echo "<b><input type=submit name=tag value='Show Tags'></b>"; echo "<b><input type=submit name=tag value='Show Tags'></b>";
echo "<input type=hidden name=which value='$exptidx'>"; echo "<input type=hidden name=which value='$exptidx'>";
echo "</form>"; echo "</form>";
echo "<form action='archive_missing.php3' $style method=get>";
if (isset($pid)) {
echo "<form action='${TBBASE}/archive_missing.php3' $style method=get>";
echo "<b><input type=submit name=missing value='Show Missing Files'></b>"; echo "<b><input type=submit name=missing value='Show Missing Files'></b>";
echo "<input type=hidden name=pid value='$pid'>"; echo "<input type=hidden name=pid value='$pid'>";
echo "<input type=hidden name=eid value='$eid'>"; echo "<input type=hidden name=eid value='$eid'>";
echo "</form>"; echo "</form>";
}
echo "</center>\n"; echo "</center>\n";
echo "<iframe width=100% height=800 scrolling=yes src='$url' border=2>". echo "<iframe width=100% height=800 scrolling=yes src='$url' border=2>".
......
...@@ -1362,6 +1362,22 @@ function TBExptIndex($pid, $eid) ...@@ -1362,6 +1362,22 @@ function TBExptIndex($pid, $eid)
return $idx; return $idx;
} }
function TBExptidx2PidEid($exptidx, &$pid, &$eid, &$gid)
{
$query_result =
DBQueryFatal("select pid,eid,gid from experiments ".
"where idx='$exptidx'");
if (mysql_num_rows($query_result) == 0) {
return -1;
}
$row = mysql_fetch_array($query_result);
$pid = $row[pid];
$eid = $row[eid];
$gid = $row[gid];
return 0;
}
function TBrsrcIndex($pid, $eid) function TBrsrcIndex($pid, $eid)
{ {
$query_result = $query_result =
......
...@@ -537,7 +537,7 @@ class Template ...@@ -537,7 +537,7 @@ class Template
"<img border=0 alt='Show' src='greenball.gif'>"); "<img border=0 alt='Show' src='greenball.gif'>");
echo " <td align=center> echo " <td align=center>
<a href=cvsweb/cvswebwrap.php3/$exptidx/history/$tag/". <a href=archive_view.php3/$exptidx/history/$tag/".
"?exptidx=$exptidx> "?exptidx=$exptidx>
<img border=0 alt='i' src='greenball.gif'></a></td>"; <img border=0 alt='i' src='greenball.gif'></a></td>";
...@@ -991,7 +991,7 @@ class TemplateInstance ...@@ -991,7 +991,7 @@ class TemplateInstance
if (isset($tag) && $tag != "") { if (isset($tag) && $tag != "") {
$archive_link = $archive_link =
"<a href=cvsweb/cvswebwrap.php3". "<a href=archive_view.php3".
"/$exptidx/history/$tag/?exptidx=$exptidx>". "/$exptidx/history/$tag/?exptidx=$exptidx>".
"<img border=0 alt='i' src='greenball.gif'></a>"; "<img border=0 alt='i' src='greenball.gif'></a>";
} }
......
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