File: php_tar.tpl

package info (click to toggle)
weevely 4.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,336 kB
  • sloc: python: 7,732; php: 1,035; sh: 53; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,337 bytes parent folder | download
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
<%
overwrite_bool = 'true' if overwrite else 'false'
%>
$f='set_time_limit'&&is_callable($f)&&$f(0);
$f='ini_set'&&is_callable($f)&&$f('max_execution_time', 0);
$r=dirname(Phar::running(false)).'/';
$n='${ rtar }';
try {
    $a = new PharData($n);

% if decompress:

if(!file_exists($n) || !is_readable($n)) {
    print("Skipping file '$n', check existance and permission");
} else {
    $o = '${ rfiles[0] if rfiles and rfiles[0] else '.' }';
    $a->extractTo($o, null, ${ overwrite_bool });
}

% else:

if(file_exists($n) || !${ overwrite_bool }) {
    print("File '$n' already exists, skipping compressing");
} else {
    $b = dirname($n);

    function add($a, $b, $f) {
        $p = preg_replace("#^$b/#", '', $f);
        if (is_dir($f)) {
            $a->addEmptyDir($p);
            foreach(glob("$f/*") as $file) {
                add($a, $b, $file);
            }
        } else {
            $a->addFile($f, $p);
        }
    }

    % for f in rfiles:
    add($a, $b, '${ f }');
    % endfor
}

## Since makeTar does not complain for missing $n, just double
## check the existance of the zipped file and print generic error message
if(!file_exists($n)) {
    print("File '$n' not created, check existance and permission");
}

% endif

}catch(Exception $e){
    print("Skipping file '$n', check existance and permission");
}