1: <?php
2: /**
3: * Class for providing garbage collection for any VFS instance.
4: *
5: * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
6: *
7: * See the enclosed file COPYING for license information (LGPL). If you
8: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
9: *
10: * @author Michael Slusarz <slusarz@horde.org>
11: * @package Vfs
12: */
13: class Horde_Vfs_Gc
14: {
15: /**
16: * Garbage collect files in the VFS storage system.
17: *
18: * @param VFS $vfs The VFS object to perform garbage collection on.
19: * @param string $path The VFS path to clean.
20: * @param integer $secs The minimum amount of time (in seconds) required
21: * before a file is removed.
22: */
23: public function gc($vfs, $path, $secs = 345600)
24: {
25: /* A 1% chance we will run garbage collection during a call. */
26: if (rand(0, 99) != 0) {
27: return;
28: }
29:
30: /* Use a backend-specific method if one exists. */
31: if (is_callable(array($vfs, 'gc'))) {
32: return $vfs->gc($path, $secs);
33: }
34:
35: /* Make sure cleaning is done recursively. */
36: try {
37: $modtime = time() - $secs;
38: foreach ($vfs->listFolder($path, null, true, false, true) as $val) {
39: if ($val['date'] < $modtime) {
40: $vfs->deleteFile($path, $val['name']);
41: }
42: }
43: } catch (Horde_Vfs_Exception $e) {
44: }
45: }
46: }
47: