Passed
Pull Request — master (#6702)
by David
15:07 queued 05:16
created

cache_check_diskspace2()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 3
nop 0
dl 0
loc 11
rs 9.9666
c 0
b 0
f 0
1
#! /usr/bin/env php
2
<?php
3
// This file is part of BOINC.
4
// http://boinc.berkeley.edu
5
// Copyright (C) 2008 University of California
6
//
7
// BOINC is free software; you can redistribute it and/or modify it
8
// under the terms of the GNU Lesser General Public License
9
// as published by the Free Software Foundation,
10
// either version 3 of the License, or (at your option) any later version.
11
//
12
// BOINC is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
// See the GNU Lesser General Public License for more details.
16
//
17
// You should have received a copy of the GNU Lesser General Public License
18
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
19
20
// delete files from the web cache until free-space criteria are met
21
22
$cli_only = true;
23
require_once("../inc/cache.inc");
24
require_once("../inc/util_ops.inc");
25
26
set_time_limit(0);
27
28
function main(){
29
    echo "------- Starting at ".time_str(time())."-------\n";
30
31
    echo sprintf("max cache usage: %s\n", size_string(MAX_CACHE_USAGE));
32
    $too_old = 86400*7;
33
    while (1) {
34
        $u = disk_usage("../cache");
35
        echo sprintf("cache usage: %s\n", size_string($u));
36
        if ($u < MAX_CACHE_USAGE) {
37
            echo "criteria met; quitting\n";
38
            break;
39
        }
40
        echo sprintf("deleting files older than %s\n", time_diff($too_old));
41
        clean_cache($too_old, "../cache");
42
        $too_old /= 2;
43
        if ($too_old < 60) {
44
            break;
45
        }
46
    }
47
    echo "------- Finished at ".time_str(time())."-------\n";
48
}
49
50
main();
51
?>
52