File inc/artifacts.inc.php changed (mode: 100644) (index e7a7c33..89853c6) |
1 |
1 |
<?php |
<?php |
|
2 |
|
require_once(__DIR__ . '/mime.inc.php'); |
2 |
3 |
|
|
3 |
4 |
function rg_artifacts_set_error($str) |
function rg_artifacts_set_error($str) |
4 |
5 |
{ |
{ |
|
... |
... |
function rg_artifacts_error() |
16 |
17 |
/* |
/* |
17 |
18 |
* Load info about a file in the artifacts directory |
* Load info about a file in the artifacts directory |
18 |
19 |
*/ |
*/ |
19 |
|
function rg_artifacts_load_file($repo_path, $path) |
|
|
20 |
|
function rg_artifacts_load_file($uid, $repo_id, $path) |
20 |
21 |
{ |
{ |
21 |
22 |
rg_log_enter('artifacts_load_one: path=' . $path); |
rg_log_enter('artifacts_load_one: path=' . $path); |
22 |
23 |
|
|
|
... |
... |
function rg_artifacts_load_file($repo_path, $path) |
27 |
28 |
break; |
break; |
28 |
29 |
} |
} |
29 |
30 |
|
|
30 |
|
$fpath = $repo_path . '/rocketgit/artifacts/' . $path; |
|
|
31 |
|
$apath = rg_repo_artifacts_path_by_id($uid, $repo_id); |
|
32 |
|
$fpath = $apath . '/' . $path; |
31 |
33 |
$ret = @rg_unserialize(file_get_contents($fpath . '.rg.meta')); |
$ret = @rg_unserialize(file_get_contents($fpath . '.rg.meta')); |
32 |
34 |
if ($ret === FALSE) { |
if ($ret === FALSE) { |
33 |
35 |
rg_log('DEBUG: cannot load metadata from ' . $fpath . '.rg.data'); |
rg_log('DEBUG: cannot load metadata from ' . $fpath . '.rg.data'); |
|
... |
... |
function rg_artifacts_load_file($repo_path, $path) |
35 |
37 |
} |
} |
36 |
38 |
rg_log_ml('DEBUG: data loaded from .rg.meta: ' . print_r($ret, TRUE)); |
rg_log_ml('DEBUG: data loaded from .rg.meta: ' . print_r($ret, TRUE)); |
37 |
39 |
|
|
|
40 |
|
$ret['full_path'] = $fpath; |
38 |
41 |
$ret['path'] = dirname($path); |
$ret['path'] = dirname($path); |
39 |
42 |
$ret['path_file'] = $path; |
$ret['path_file'] = $path; |
40 |
43 |
$ret['e_path_file'] = rg_path2url($ret['path_file']); |
$ret['e_path_file'] = rg_path2url($ret['path_file']); |
|
... |
... |
function rg_artifacts_load_file($repo_path, $path) |
56 |
59 |
/* |
/* |
57 |
60 |
* Load the list of artifacts in a specific dir |
* Load the list of artifacts in a specific dir |
58 |
61 |
*/ |
*/ |
59 |
|
function rg_artifacts_load($repo_path, $dir) |
|
|
62 |
|
function rg_artifacts_load($uid, $repo_id, $dir) |
60 |
63 |
{ |
{ |
61 |
64 |
rg_log_enter('artifacts_load'); |
rg_log_enter('artifacts_load'); |
62 |
65 |
|
|
|
... |
... |
function rg_artifacts_load($repo_path, $dir) |
67 |
70 |
break; |
break; |
68 |
71 |
} |
} |
69 |
72 |
|
|
70 |
|
$fdir = $repo_path . '/rocketgit/artifacts/' . $dir; |
|
|
73 |
|
$apath = rg_repo_artifacts_path_by_id($uid, $repo_id); |
|
74 |
|
$fdir = $apath . '/' . $dir; |
71 |
75 |
if (!is_dir($fdir)) { |
if (!is_dir($fdir)) { |
72 |
76 |
$ret = array(); |
$ret = array(); |
73 |
77 |
break; |
break; |
|
... |
... |
function rg_artifacts_load($repo_path, $dir) |
87 |
91 |
if (strcmp($last, '.rg.meta') == 0) |
if (strcmp($last, '.rg.meta') == 0) |
88 |
92 |
continue; |
continue; |
89 |
93 |
|
|
90 |
|
$ret[] = rg_artifacts_load_file($repo_path, $dir . '/' . $v); |
|
|
94 |
|
$ret[] = rg_artifacts_load_file($uid, $repo_id, $dir . '/' . $v); |
91 |
95 |
continue; |
continue; |
92 |
96 |
} |
} |
93 |
97 |
|
|
|
... |
... |
function rg_artifacts_load($repo_path, $dir) |
115 |
119 |
/* |
/* |
116 |
120 |
* Add several variables to the list |
* Add several variables to the list |
117 |
121 |
*/ |
*/ |
118 |
|
function rg_artifacts_cosmetic($list) |
|
|
122 |
|
function rg_artifacts_cosmetic_one(&$a) |
119 |
123 |
{ |
{ |
120 |
|
return $list; |
|
|
124 |
|
if (isset($a['upload_ts'])) |
|
125 |
|
$a['upload_ts_nice'] = gmdate('Y-m-d H:i:s', $a['upload_ts']); |
|
126 |
|
else |
|
127 |
|
$a['upload_ts_nice'] = 'n/a'; |
|
128 |
|
} |
|
129 |
|
|
|
130 |
|
/* |
|
131 |
|
* Add several variables to the list |
|
132 |
|
*/ |
|
133 |
|
function rg_artifacts_cosmetic(&$list) |
|
134 |
|
{ |
|
135 |
|
foreach ($list as $i => &$v) |
|
136 |
|
rg_artifacts_cosmetic_one($v); |
|
137 |
|
unset($v); |
121 |
138 |
} |
} |
122 |
139 |
|
|
File inc/repo.inc.php changed (mode: 100644) (index 4f50e21..d42a15c) |
... |
... |
function rg_repo_path_by_id($uid, $repo_id) |
910 |
910 |
return rg_user_path_by_id($uid) . "/repos/by_id/" . $repo_id . ".git"; |
return rg_user_path_by_id($uid) . "/repos/by_id/" . $repo_id . ".git"; |
911 |
911 |
} |
} |
912 |
912 |
|
|
|
913 |
|
/* |
|
914 |
|
* Returns the path to a artifacts based on id |
|
915 |
|
*/ |
|
916 |
|
function rg_repo_artifacts_path_by_id($uid, $repo_id) |
|
917 |
|
{ |
|
918 |
|
return rg_user_path_by_id($uid) . '/repos/by_id/' . $repo_id . '.a'; |
|
919 |
|
} |
|
920 |
|
|
913 |
921 |
/* |
/* |
914 |
922 |
* Returns the path to a repository based on name |
* Returns the path to a repository based on name |
915 |
923 |
*/ |
*/ |
|
... |
... |
function rg_repo_search($db, $login_ui, $q) |
1363 |
1371 |
} |
} |
1364 |
1372 |
|
|
1365 |
1373 |
/* |
/* |
1366 |
|
* Computes the size of a repository |
|
1367 |
|
* @all - if TRUE, take in account all files. If FALSE, ignore the files with |
|
1368 |
|
* many links (a clone). |
|
|
1374 |
|
* Computes the sizes of a repository |
1369 |
1375 |
*/ |
*/ |
1370 |
|
function rg_repo_size($path, $all) |
|
|
1376 |
|
function rg_repo_size($uid, $repo_id) |
1371 |
1377 |
{ |
{ |
1372 |
|
//rg_log("repo_disk_mb: path=$path"); |
|
1373 |
|
|
|
1374 |
|
$ret = FALSE; |
|
1375 |
|
while (1) { |
|
1376 |
|
$dir = @opendir($path); |
|
1377 |
|
if ($dir === FALSE) { |
|
1378 |
|
rg_repo_set_error("Cannot open $path!"); |
|
1379 |
|
break; |
|
1380 |
|
} |
|
1381 |
|
|
|
1382 |
|
$total = 0; |
|
1383 |
|
$error = FALSE; |
|
1384 |
|
while (($f = readdir($dir)) !== FALSE) { |
|
1385 |
|
if (strcmp($f, ".") == 0) |
|
1386 |
|
continue; |
|
1387 |
|
|
|
1388 |
|
if (strcmp($f, "..") == 0) |
|
1389 |
|
continue; |
|
1390 |
|
|
|
1391 |
|
if (is_dir($path . "/" . $f)) { |
|
1392 |
|
$r = rg_repo_size($path . "/" . $f, $all); |
|
1393 |
|
if ($r === FALSE) { |
|
1394 |
|
$error = TRUE; |
|
1395 |
|
break; |
|
1396 |
|
} |
|
1397 |
|
$total += $r; |
|
1398 |
|
} |
|
1399 |
|
|
|
1400 |
|
if (is_file($path . "/" . $f)) { |
|
1401 |
|
$s = stat($path . "/" . $f); |
|
1402 |
|
if ($s === FALSE) { |
|
1403 |
|
$error = TRUE; |
|
1404 |
|
break; |
|
1405 |
|
} |
|
1406 |
|
|
|
1407 |
|
$r = $s['size']; |
|
1408 |
|
if ($all === FALSE) { |
|
1409 |
|
if ($s['nlink'] > 1) |
|
1410 |
|
$r = 0; |
|
1411 |
|
} |
|
1412 |
|
|
|
1413 |
|
$total += $r; |
|
1414 |
|
} |
|
1415 |
|
} |
|
1416 |
|
closedir($dir); |
|
1417 |
|
|
|
1418 |
|
if ($error === FALSE) |
|
1419 |
|
$ret = $total; |
|
1420 |
|
break; |
|
1421 |
|
} |
|
|
1378 |
|
$git_path = rg_repo_path_by_id($uid, $repo_id); |
|
1379 |
|
$git = rg_dir_size($git_path); |
|
1380 |
|
if ($git === FALSE) |
|
1381 |
|
return FALSE; |
|
1382 |
|
//rg_log_ml('DEBUG: XXX: git:' . print_r($git, TRUE)); |
|
1383 |
|
$git_size = intval($git['blocks'] / 2 / 1024); |
1422 |
1384 |
|
|
1423 |
|
return $ret; |
|
|
1385 |
|
$artifact_path = rg_repo_artifacts_path_by_id($uid, $repo_id); |
|
1386 |
|
$a = rg_dir_size($artifact_path); |
|
1387 |
|
if ($a === FALSE) |
|
1388 |
|
return FALSE; |
|
1389 |
|
//rg_log_ml('DEBUG: XXX: a:' . print_r($a, TRUE)); |
|
1390 |
|
$a_size = intval($a['blocks'] / 2 / 1024); |
|
1391 |
|
|
|
1392 |
|
return array( |
|
1393 |
|
'disk_used_mb' => $git_size + $a_size, |
|
1394 |
|
'git_mb' => $git_size, |
|
1395 |
|
'artifacts_mb' => $a_size |
|
1396 |
|
); |
1424 |
1397 |
} |
} |
1425 |
1398 |
|
|
1426 |
1399 |
/* |
/* |
File inc/user/repo/artifacts/main.php changed (mode: 100644) (index 4651280..bc2a682) |
... |
... |
switch ($_op) { |
39 |
39 |
// break; |
// break; |
40 |
40 |
|
|
41 |
41 |
case 'download': |
case 'download': |
42 |
|
$i = rg_artifacts_load_file($rg['repo_path'], $path); |
|
|
42 |
|
$i = rg_artifacts_load_file($rg['page_ui']['uid'], $rg['ri']['repo_id'], $path); |
43 |
43 |
if ($i === FALSE) { |
if ($i === FALSE) { |
44 |
44 |
$rg['HTML:artifacts_error'] = rg_artifacts_error(); |
$rg['HTML:artifacts_error'] = rg_artifacts_error(); |
45 |
45 |
$_artifacts_body .= rg_template('repo/artifacts/error.html', $rg, TRUE /*xss*/); |
$_artifacts_body .= rg_template('repo/artifacts/error.html', $rg, TRUE /*xss*/); |
|
... |
... |
case 'download': |
51 |
51 |
header('Content-Disposition: attachment; filename="' . $fn . '"'); |
header('Content-Disposition: attachment; filename="' . $fn . '"'); |
52 |
52 |
header('Content-Length: ' . $i['size']); |
header('Content-Length: ' . $i['size']); |
53 |
53 |
|
|
54 |
|
readfile($rg['repo_path'] . '/rocketgit/artifacts/' . $i['path_file'], 'rb'); |
|
|
54 |
|
readfile($i['full_path']); |
55 |
55 |
exit(0); |
exit(0); |
56 |
56 |
|
|
57 |
57 |
default: // list |
default: // list |
58 |
58 |
rg_log('DEBUG: path=' . $path); |
rg_log('DEBUG: path=' . $path); |
59 |
|
$d = rg_artifacts_load($rg['repo_path'], $path); |
|
|
59 |
|
$d = rg_artifacts_load($rg['page_ui']['uid'], $rg['ri']['repo_id'], $path); |
60 |
60 |
if ($d === FALSE) { |
if ($d === FALSE) { |
61 |
61 |
$rg['HTML:artifacts_error'] = rg_artifacts_error(); |
$rg['HTML:artifacts_error'] = rg_artifacts_error(); |
62 |
62 |
$_artifacts_body .= rg_template('repo/artifacts/error.html', $rg, TRUE /*xss*/); |
$_artifacts_body .= rg_template('repo/artifacts/error.html', $rg, TRUE /*xss*/); |
63 |
63 |
break; |
break; |
64 |
64 |
} |
} |
65 |
65 |
|
|
66 |
|
$list = rg_artifacts_cosmetic($d); |
|
|
66 |
|
rg_artifacts_cosmetic($d); |
67 |
67 |
$rg['url_artifacts'] = $rg['url_repo'] . '/artifacts'; |
$rg['url_artifacts'] = $rg['url_repo'] . '/artifacts'; |
68 |
68 |
$rg['HTML:artifacts_paths'] = rg_url_segments($rg['url_artifacts'] . '/list', $path); |
$rg['HTML:artifacts_paths'] = rg_url_segments($rg['url_artifacts'] . '/list', $path); |
69 |
|
$_artifacts_body .= rg_template_table('repo/artifacts/list', $list, $rg); |
|
|
69 |
|
$_artifacts_body .= rg_template_table('repo/artifacts/list', $d, $rg); |
70 |
70 |
break; |
break; |
71 |
71 |
} |
} |
72 |
72 |
|
|
File scripts/builder.php changed (mode: 100644) (index 8abc0d9..e937551) |
... |
... |
function xdispatch_one($key, $data) |
392 |
392 |
// TODO: Move this where the job is prepared - where?! |
// TODO: Move this where the job is prepared - where?! |
393 |
393 |
if (!isset($job['repo_path'])) |
if (!isset($job['repo_path'])) |
394 |
394 |
$job['repo_path'] = rg_repo_path_by_id($job['request']['uid'], $job['repo_id']); |
$job['repo_path'] = rg_repo_path_by_id($job['request']['uid'], $job['repo_id']); |
|
395 |
|
if (!isset($job['artifacts_path'])) |
|
396 |
|
$job['artifacts_path'] = rg_repo_artifacts_path_by_id($job['request']['uid'], $job['repo_id']); |
395 |
397 |
|
|
396 |
398 |
if (!isset($s['artifacts'][$jid])) |
if (!isset($s['artifacts'][$jid])) |
397 |
399 |
$s['artifacts'][$jid] = array(); |
$s['artifacts'][$jid] = array(); |
|
... |
... |
function xdispatch_one($key, $data) |
481 |
483 |
} |
} |
482 |
484 |
$s['artifacts'][$jid][$aid]['ready_to_write'] = 0; |
$s['artifacts'][$jid][$aid]['ready_to_write'] = 0; |
483 |
485 |
|
|
484 |
|
$adir = $job['repo_path'] . '/rocketgit/artifacts'; |
|
|
486 |
|
$adir = $job['artifacts_path']; |
485 |
487 |
if (!is_dir($adir)) { |
if (!is_dir($adir)) { |
486 |
488 |
$r = @mkdir($adir, 0770, TRUE); |
$r = @mkdir($adir, 0770, TRUE); |
487 |
489 |
if ($r === FALSE) { |
if ($r === FALSE) { |