cleanup_results()   B
last analyzed

Complexity

Conditions 7
Paths 7

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 7
eloc 11
c 1
b 1
f 0
nc 7
nop 0
dl 0
loc 13
rs 8.8333
1
#! /usr/bin/env php
2
0 ignored issues
show
Coding Style introduced by
PHP files must only contain PHP code
Loading history...
3
<?php
0 ignored issues
show
Coding Style introduced by
The opening PHP tag must be the first content in the file
Loading history...
4
// This file is part of BOINC.
5
// https://boinc.berkeley.edu
6
// Copyright (C) 2025 University of California
7
//
8
// BOINC is free software; you can redistribute it and/or modify it
9
// under the terms of the GNU Lesser General Public License
10
// as published by the Free Software Foundation,
11
// either version 3 of the License, or (at your option) any later version.
12
//
13
// BOINC is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
// See the GNU Lesser General Public License for more details.
17
//
18
// You should have received a copy of the GNU Lesser General Public License
19
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
20
21
// delete retired batches with no WUs
22
23
require_once('../inc/boinc_db.inc');
24
require_once('../inc/submit_db.inc');
25
require_once('../inc/util.inc');
26
27
function main() {
28
    echo "------- Starting at ".time_str(time())."-------\n";
29
    $batches = BoincBatch::enum(sprintf('state=%d', BATCH_STATE_RETIRED));
30
    foreach ($batches as $batch) {
31
        $wus = BoincWorkunit::enum_fields(
32
            'id',
33
            "batch=$batch->id"
34
        );
35
        if (!$wus) {
36
            echo "deleting batch $batch->id\n";
37
            $batch->delete();
38
        }
39
    }
40
    echo "------- Finished at ".time_str(time())."-------\n";
41
}
42
43
// clean up results/.
44
// In theory should have to do this just once.
45
//
46
function cleanup_results() {
47
    foreach (scandir('../../results') as $d) {
48
        if ($d[0] == '.') continue;
49
        if (!is_numeric($d)) continue;
50
        $id = (int)$d;
51
        if (!$id) continue;
52
        $batch = BoincBatch::lookup_id($id);
53
        if ($batch) {
54
            if ($batch->state != BATCH_STATE_RETIRED) continue;
55
        }
56
        $dir = "../../results/$d";
57
        echo "deleting $dir\n";
58
        system("/bin/rm -rf $dir");
59
    }
60
}
61
62
main();
63
//cleanup_results();
64
65
?>
66