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" ||
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.
#
my $userdir = TBExptUserDir($pid, $eid);
# This is special by convention;
$subdir = "$userdir/archive";
$subdir = "/archive";
}
elsif (@ARGV) {
$subdir = $ARGV[0];
......
......@@ -700,20 +700,34 @@ TBSaveExpLogFiles($pid, $eid);
#
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)) {
libArchive::TBExperimentArchiveAddFile($pid, $eid,
"$userdir/tbdata/" . EXPTLOGNAME());
system("cp -p $logname $archivedir/tbdata/log.batchexp") == 0
or fatal("Failed to copy logfile to $archivedir/tbdata");
}
libArchive::TBExperimentArchiveAddFile($pid, $eid, "$userdir/tbdata/$repfile");
#
# Make a copy of the NS file where we can get at it easily. Then add it.
#
system("cp -p $workdir/$nsfile $userdir/archive/$nsfile");
libArchive::TBExperimentArchiveAddFile($pid, $eid,
"$userdir/archive/$nsfile") == 0 or
fatal("Failed to add $userdir/archive/$nsfile to the archive!");
system("cp -p $workdir/$repfile $archivedir/tbdata/tbreport.batchexp") == 0
or fatal("Failed to copy nsfile to $archivedir/tbdata");
# And tell the archive library about the above files.
libArchive::TBExperimentArchiveAddUserFiles($pid, $eid) == 0
or fatal("Failed to add user archive files to the archive!");
#
# Do a SavePoint on the experiment files.
......@@ -1223,14 +1237,14 @@ sub CopyInArchive()
return 0
if (!defined($copyarg));
my $dstdir = "$userdir/archive";
my $dstdir = "$userdir/archive/nsdata";
if ($copyfrom eq "exp") {
#
# Copy in from a current experiment. This is probably a bad thing
# to do, but hey.
#
my $srcdir = TBExptUserDir($copypid, $copyeid) . "/archive";
my $srcdir = TBExptUserDir($copypid, $copyeid) . "/archive/nsdata";
if (-e $srcdir) {
print "Copying experiment archive from ${srcdir}\n";
......@@ -1239,19 +1253,12 @@ sub CopyInArchive()
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 {
#
# 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";
libArchive::TBCheckoutExperimentArchivebyExptIDX($copyidx,
......@@ -1260,12 +1267,6 @@ sub CopyInArchive()
$subdir)
== 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";
}
......
......@@ -319,10 +319,9 @@ sub ValidatePath($)
# temporary store. Later, after all the files are in the tree, must
# commit it to the repo.
#
sub ArchiveAdd($$;$$)
sub ArchiveAdd($$;$$$)
{
my ($archive_idx, $pathname, $view, $exact) = @_;
my $rootdir;
my ($archive_idx, $pathname, $view, $exact, $special) = @_;
$view = $defaultview
if (!defined($view));
......@@ -330,6 +329,9 @@ sub ArchiveAdd($$;$$)
$exact = 0
if (!defined($exact));
$special = 0
if (!defined($special));
# This returns a taint checked value in $pathname.
if (ValidatePath(\$pathname) != 0) {
print STDERR "ArchiveAdd: Could not validate pathname $pathname\n";
......@@ -339,9 +341,32 @@ sub ArchiveAdd($$;$$)
#
# Strip leading /dir from the pathname, we need it below.
#
if ($pathname =~ /^[\/]+(\w+)\/([-\w\/\.\+\@,~]+)$/) {
my ($rootdir, $sourcedir, $sourcefile);
my $rsyncopt = "";
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;
$pathname = $2;
$sourcedir = $1;
$sourcefile = $2;
$rsyncopt = "-R";
}
else {
print STDERR "ArchiveAdd: Illegal characters in pathname $pathname\n";
......@@ -362,7 +387,6 @@ sub ArchiveAdd($$;$$)
return -1;
}
my $repodir = "$directory/repo";
my $checkout = "$directory/checkouts/$view";
my $checkin = "$directory/checkins/$view";
#
......@@ -375,17 +399,18 @@ sub ArchiveAdd($$;$$)
mysystem("$MKDIR $checkin/$rootdir") == 0 or return -1;
}
if (-f "/${rootdir}/${pathname}" || !$exact) {
mysystem("$TAR cf - -C /$rootdir $pathname | ".
if (-f "/${sourcedir}/${sourcefile}" || !$exact) {
mysystem("$TAR cf - -C /$sourcedir $sourcefile | ".
"$TAR xf - -U -C $checkin/$rootdir");
mysystem("$CHMOD 775 $checkin/$rootdir/$pathname");
mysystem("$CHMOD 775 $checkin/$rootdir/$sourcefile");
}
else {
mysystem("cd /$rootdir; ".
"$RSYNC -R -rtgoDlz --delete ${pathname} $checkin/$rootdir");
mysystem("cd /$sourcedir; ".
"$RSYNC $rsyncopt -rtgoDlz ".
" --delete ${sourcefile} $checkin/$rootdir");
}
if ($?) {
print STDERR "ArchiveAdd: Could not copy in /$rootdir/$pathname\n";
print STDERR "ArchiveAdd: Could not copy in $pathname\n";
return -1;
}
return 0;
......@@ -1418,6 +1443,19 @@ sub TBExperimentArchiveAddTracedFiles($$)
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
#
......@@ -1439,7 +1477,7 @@ sub TBExperimentArchiveAddUserFiles($$)
my $userarch = "$userdir/archive";
if (-e $userarch) {
$rval = ArchiveAdd($archive_idx, $userarch, $view, 1);
$rval = ArchiveAdd($archive_idx, $userarch, $view, 1, 1);
return $rval
if ($rval != 0);
......
......@@ -1079,17 +1079,38 @@ TBSaveExpLogFiles($pid, $eid);
#
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)) {
libArchive::TBExperimentArchiveAddFile($pid, $eid,
"$userdir/tbdata/" . EXPTLOGNAME());
system("cp -p $logname $archivedir/tbdata/log.$tag") == 0
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.
system("cp -p $workdir/$eid.ns $userdir/archive/$eid.ns");
libArchive::TBExperimentArchiveAddFile($pid, $eid,
"$userdir/archive/$eid.ns") == 0 or
fatal("Failed to add $userdir/$eid.ns to the archive!");
# And tell the archive library about the above files.
libArchive::TBExperimentArchiveAddUserFiles($pid, $eid) == 0
or fatal("Failed to add user archive files to the archive!");
#
# The archive gets different treatment when doing a swapmod.
......
......@@ -17,46 +17,51 @@ $isadmin = ISADMIN($uid);
#
# Verify page arguments.
#
if (!isset($pid) ||
if (isset($exptidx) && $exptidx != "") {
if (!TBvalid_integer($exptidx)) {
PAGEARGERROR("Invalid experiment index.");
}
PAGEHEADER("Experiment Archive ($exptidx)");
unset($pid);
unset($eid);
unset($gid);
TBExptidx2PidEid($exptidx, $pid, $eid, $gid);
$url = preg_replace("/archive_view/", "cvsweb/cvsweb",
$_SERVER['REQUEST_URI']);
}
else {
if (!isset($pid) ||
strcmp($pid, "") == 0) {
USERERROR("You must provide a Project ID.", 1);
}
if (!isset($eid) ||
}
if (!isset($eid) ||
strcmp($eid, "") == 0) {
USERERROR("You must provide an Experiment ID.", 1);
}
if (!TBvalid_pid($pid)) {
}
if (!TBvalid_pid($pid)) {
PAGEARGERROR("Invalid project ID.");
}
if (!TBvalid_eid($eid)) {
}
if (!TBvalid_eid($eid)) {
PAGEARGERROR("Invalid experiment ID.");
}
}
#
# Standard Testbed Header now that we have the pid/eid okay.
#
PAGEHEADER("Experiment Archive ($pid/$eid)");
#
# Check to make sure this is a valid PID/EID tuple.
#
if (! TBValidExperiment($pid, $eid)) {
#
# Check to make sure this is a valid PID/EID tuple.
#
if (! TBValidExperiment($pid, $eid)) {
USERERROR("The experiment $eid is not a valid experiment ".
"in project $pid.", 1);
}
#
# Verify Permission.
#
if (! TBExptAccessCheck($uid, $pid, $eid, $TB_EXPT_READINFO)) {
USERERROR("You do not have permission to view experiment $eid!", 1);
}
$exptidx = TBExptIndex($pid, $eid);
if ($exptidx < 0) {
}
$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.
$style = 'style="float:left; width:33%;"';
......@@ -64,20 +69,26 @@ $style = 'style="float:left; width:33%;"';
echo "<center>\n";
echo "<font size=+1>
This is the Subversion archive for your experiment.<br></font>";
echo "<form action='archive_tag.php3' $style method=get>\n";
echo "<b><input type=submit name=tag value='Tag Archive'></b>";
echo "<input type=hidden name=pid value='$pid'>";
echo "<input type=hidden name=eid value='$eid'>";
echo "</form>";
echo "<form action='archive_tags.php3' $style method=get>";
if (isset($pid)) {
echo "<form action='${TBBASE}/archive_tag.php3' $style method=get>\n";
echo "<b><input type=submit name=tag value='Tag Archive'></b>";
echo "<input type=hidden name=pid value='$pid'>";
echo "<input type=hidden name=eid value='$eid'>";
echo "</form>";
}
echo "<form action='${TBBASE}/archive_tags.php3' $style method=get>";
echo "<b><input type=submit name=tag value='Show Tags'></b>";
echo "<input type=hidden name=which value='$exptidx'>";
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 "<input type=hidden name=pid value='$pid'>";
echo "<input type=hidden name=eid value='$eid'>";
echo "</form>";
}
echo "</center>\n";
echo "<iframe width=100% height=800 scrolling=yes src='$url' border=2>".
......
......@@ -1362,6 +1362,22 @@ function TBExptIndex($pid, $eid)
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)
{
$query_result =
......
......@@ -537,7 +537,7 @@ class Template
"<img border=0 alt='Show' src='greenball.gif'>");
echo " <td align=center>
<a href=cvsweb/cvswebwrap.php3/$exptidx/history/$tag/".
<a href=archive_view.php3/$exptidx/history/$tag/".
"?exptidx=$exptidx>
<img border=0 alt='i' src='greenball.gif'></a></td>";
......@@ -991,7 +991,7 @@ class TemplateInstance
if (isset($tag) && $tag != "") {
$archive_link =
"<a href=cvsweb/cvswebwrap.php3".
"<a href=archive_view.php3".
"/$exptidx/history/$tag/?exptidx=$exptidx>".
"<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