summaryrefslogtreecommitdiff
path: root/scripts/cleanup
blob: 0ccbe7dfb5ec9f42ebcf1b6300a8a311158e93dc (plain)
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
#!/usr/bin/php
<?php
# Run this script by providing it with the top path of AUR.
# In that path you should see a file lib/aur.inc
#
# This will remove files which belong to deleted packages
# in unsupported.
#
# ex: php cleanup dev/aur/web
#
$dir = $argv[1];

if (empty($dir)) {
	echo "Please specify AUR directory.\n";
	exit;
}

set_include_path(get_include_path() . PATH_SEPARATOR . "$dir/lib");
include("confparser.inc.php");
include("aur.inc.php");
include("pkgfuncs.inc.php");

$count = 0;

$incoming_dir = config_get('paths', 'storage');
$buckets = scandir($incoming_dir);
foreach ($buckets as $bucket) {
	$bucketpath = $incoming_dir . $bucket;
	if ($bucket == '.' || $bucket == '..' || !is_dir($bucketpath)) {
		continue;
	}
	$files = scandir($incoming_dir . $bucket);
	foreach ($files as $pkgname) {
		if ($pkgname == '.' || $pkgname == '..') {
			continue;
		}
		$fullpath = $incoming_dir . $bucket . "/" . $pkgname;
		if (!pkg_from_name($pkgname) && is_dir($fullpath)) {
			echo 'Removing ' . $fullpath . "\n";
			rm_tree($fullpath);
			$count++;
		}
	}
}

echo "\nRemoved $count directories.\n";