submit.php: enable downloading result files of individual Workunit

svn path=/trunk/boinc/; revision=25740
This commit is contained in:
Wenjing Wu 2012-06-06 05:35:39 +00:00
parent 567fdc45fc
commit 4fdfe8d4dd
4 changed files with 65 additions and 11 deletions

View File

@ -42,26 +42,24 @@ function sandbox_write_link_file($path, $size, $md5) {
// check if a newly update files already exists in sandbox via its md5 sum
//
function sandbox_lf_exist($user,$md5){
function sandbox_lf_exist($user, $md5) {
$exist = 0;
$elf = "";
$dir = sandbox_dir($user);
$files = sandbox_file_names($user);
foreach ($files as $file){
foreach ($files as $file) {
$path = $dir."/".$file;
list($err, $file_size, $file_md5) = sandbox_parse_link_file($path);
if (!$err){
if (strcmp($md5, $file_md5) == 0){
if (strcmp($md5, $file_md5) == 0) {
//echo "this file with $md5 already exisits with another name $file";
$exist = 1;
$elf = $file;
break;
}
}
}
return array($exist, $elf);
}
// parse a link file and return (error, size, md5)
@ -137,7 +135,6 @@ function sandbox_file_in_use($user, $file){
foreach($wus as $wu){
$x = "<in>".$wu->xml_doc."</in>";
$x = simplexml_load_string($x);
global $fanout;
foreach($x->workunit->file_ref as $fr){
$pname = (string)$fr->file_name;

View File

@ -130,4 +130,10 @@ function boinc_get_output_files_url($user, $batch_id) {
return "get_output.php?batch_id=$batch_id&auth_str=$auth_str";
}
function boinc_get_wu_output_files_url($user, $wu_id) {
//echo "url: user authenticator= $user->authenticator, wu_id=$wu_id<br/>";
$auth_str = md5($user->authenticator.$wu_id);
return "get_output.php?wu_id=$wu_id&auth_str=$auth_str";
}
?>

View File

@ -56,7 +56,7 @@ function get_output_file($instance_name, $file_num, $auth_str) {
// get all the output files of a batch (canonical instances only)
// and make a zip of all of them
//
function get_output_files($batch_id, $auth_str) {
function get_batch_output_files($batch_id, $auth_str) {
$batch = BoincBatch::lookup_id($batch_id);
if (!$batch) die("no batch $batch_id");
$user = BoincUser::lookup_id($batch->user_id);
@ -95,13 +95,61 @@ function get_output_files($batch_id, $auth_str) {
unlink($zip_filename);
}
// get all the output files of a workunit (canonical instances only)
// and make a zip of all of them
//
function get_wu_output_files($wu_id, $auth_str) {
$wu = BoincWorkunit::lookup_id($wu_id);
if (!$wu) die("no workunit $wu_id");
$batch = BoincBatch::lookup_id($wu->batch);
if (!batch) die("no batch $wu->batch");
$user = BoincUser::lookup_id($batch->user_id);
if (!$user) die("no user $batch->user_id");
$x = md5($user->authenticator.$wu_id);
echo "user authenticator= $user->authenticator, wu_id=$wu_id<br/>";
if ($x != $auth_str) die("bad auth str: x=$x, auth_str=$auth_str");
$zip_basename = tempnam("/tmp", "boinc_wu_".$wu->name."_");
$zip_filename = $zip_basename.".zip";
$fanout = parse_config(get_config(), "<uldl_dir_fanout>");
$upload_dir = parse_config(get_config(), "<upload_dir>");
if (!$wu->canonical_resultid) die("no canonical result for wu $wu->name");
$result = BoincResult::lookup_id($wu->canonical_resultid);
$names = get_outfile_names($result);
foreach ($names as $name) {
$path = dir_hier_path($name, $upload_dir, $fanout);
if (is_file($path)) {
system("zip -jq $zip_basename $path");
}
}
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($zip_filename));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($zip_filename));
flush();
readfile("$zip_filename");
unlink($zip_filename);
unlink($zip_basename);
}
$auth_str = get_str('auth_str');
$instance_name = get_str('instance_name', true);
if ($instance_name) {
$file_num = get_int('file_num');
get_output_file($instance_name, $file_num, $auth_str);
} else {
$batch_id = get_int('batch_id');
get_output_files($batch_id, $auth_str);
$batch_id = get_int('batch_id' , true);
if ($batch_id) {
get_batch_output_files($batch_id, $auth_str);
} else {
$wu_id=get_int('wu_id');
get_wu_output_files($wu_id,$auth_str);
}
}
?>

View File

@ -233,7 +233,8 @@ function handle_query_batch($user) {
table_header(
"Job ID and name<br><span class=note>click for details or to get output files</span>",
"status",
"Canonical instance<br><span class=note>click to see result page on BOINC server</span>"
"Canonical instance<br><span class=note>click to see result page on BOINC server</span>",
"Download Results"
);
$wus = BoincWorkunit::enum("batch = $batch->id");
foreach($wus as $wu) {
@ -245,11 +246,13 @@ function handle_query_batch($user) {
$x = "---";
$y = "in progress";
}
$url = boinc_get_wu_output_files_url($user,$wu->id);
$text = "<a href=$url> Download Result Files</a>";
echo "<tr>
<td><a href=submit.php?action=query_job&wuid=$wu->id>$wu->id &middot; $wu->name</a></td>
<td>$y</td>
<td>$x</td>
<td>$text</td>
</tr>
";
}