-
Notifications
You must be signed in to change notification settings - Fork 1
/
archive_common.php.inc
92 lines (86 loc) · 2.66 KB
/
archive_common.php.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
require_once(__DIR__ . '/settings.inc.php');
if (!isset($wpt_dir)) {
echo "$wpt_dir missing from settings.inc.php";
exit(1);
}
chdir($wpt_dir);
$debug = true;
include 'common.inc';
error_reporting(E_ALL & ~E_NOTICE);
set_time_limit(86000);
$script = basename($_SERVER['PHP_SELF'], '.php');
$lock = Lock("Archive $script", false, 86400);
if (!isset($lock)) {
echo "Archive process for $script is already running\n";
exit(0);
}
register_shutdown_function(function() {
global $lock;
if (isset($lock))
Unlock($lock);
});
function archive_scan_dirs($callback, $every_dir = false) {
$info = array();
$endDate = (int)gmdate('ymd');
$years = scandir('./results');
foreach( $years as $year ) {
$yearDir = realpath("./results/$year");
if (is_numeric($year) && is_dir($yearDir) && $year != '.' && $year != '..') {
$info['year'] = $year;
$info['yearDir'] = $yearDir;
if ($every_dir)
$callback(array('dir' => $yearDir));
$months = scandir($yearDir);
foreach( $months as $month ) {
$monthDir = "$yearDir/$month";
if (is_dir($monthDir) && $month != '.' && $month != '..') {
$info['month'] = $month;
$info['monthDir'] = $monthDir;
if ($every_dir)
$callback(array('dir' => $monthDir));
$days = scandir($monthDir);
foreach( $days as $day ) {
$dayDir = "$monthDir/$day";
if( is_dir($dayDir) && $day != '.' && $day != '..') {
$info['day'] = $day;
$info['dayDir'] = $dayDir;
if ($every_dir)
$callback(array('dir' => $dayDir));
$groups = scandir($dayDir);
foreach ($groups as $group) {
$groupDir = "$dayDir/$group";
if( is_dir($groupDir) && $group != '.' && $group != '..') {
$info['group'] = $group;
$info['groupDir'] = $groupDir;
$info['dir'] = $groupDir;
$info['id'] = "{$year}{$month}{$day}_{$group}";
$callback($info);
}
}
}
}
}
}
}
}
}
function ZipDirectory($dir, $zipFile, $store_only = false) {
$ret = false;
if (is_dir($dir)) {
$cwd = getcwd();
chdir($dir);
$options = $store_only ? '-r0' : '-r7';
exec("zip $options \"$zipFile\" * -x '1_har.json.gz'");
chdir($cwd);
}
return $ret;
}
function logMessage($msg) {
global $logFile;
$out = gmdate('Y/m/d H:i:s - ') . $msg . "\n";
echo $out;
if (isset($logFile))
error_log($out, 3, $logFile);
}
?>