Passed
Push — master ( 9c3e3e...0c5617 )
by Vitalii
10:27 queued 10s
created

cleanup_results()   B

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
26
function main() {
27
    $batches = BoincBatch::enum(sprintf('state=%d', BATCH_STATE_RETIRED));
28
    foreach ($batches as $batch) {
29
        $wus = BoincWorkunit::enum_fields(
30
            'id',
31
            "batch=$batch->id"
32
        );
33
        if (!$wus) {
34
            echo "deleting batch $batch->id\n";
35
            $batch->delete();
36
        }
37
    }
38
}
39
40
// clean up results/.
41
// In theory should have to do this just once.
42
//
43
function cleanup_results() {
44
    foreach (scandir('../../results') as $d) {
45
        if ($d[0] == '.') continue;
46
        if (!is_numeric($d)) continue;
47
        $id = (int)$d;
48
        if (!$id) continue;
49
        $batch = BoincBatch::lookup_id($id);
50
        if ($batch) {
51
            if ($batch->state != BATCH_STATE_RETIRED) continue;
52
        }
53
        $dir = "../../results/$d";
54
        echo "deleting $dir\n";
55
        system("/bin/rm -rf $dir");
56
    }
57
}
58
59
main();
60
//cleanup_results();
61
62
?>
63