chregu Tue Mar 6 05:25:45 2001 EDT
Modified files:
/php4/pear/Cache/Container file.php
Log:
deleteDir deletes now the created "group"-Directories as well.
Hope it works on windows as well...
Index: php4/pear/Cache/Container/file.php
diff -u php4/pear/Cache/Container/file.php:1.4 php4/pear/Cache/Container/file.php:1.5
--- php4/pear/Cache/Container/file.php:1.4 Sat Mar 3 11:02:54 2001
+++ php4/pear/Cache/Container/file.php Tue Mar 6 05:25:43 2001
@@ -16,7 +16,7 @@
// | Sebastian Bergmann <[EMAIL PROTECTED]> |
// +----------------------------------------------------------------------+
//
-// $Id: file.php,v 1.4 2001/03/03 19:02:54 uw Exp $
+// $Id: file.php,v 1.5 2001/03/06 13:25:43 chregu Exp $
require_once 'Cache/Container.php';
@@ -24,7 +24,7 @@
* Stores cache contents in a file.
*
* @author Ulf Wendel <[EMAIL PROTECTED]>
-* @version $Id: file.php,v 1.4 2001/03/03 19:02:54 uw Exp $
+* @version $Id: file.php,v 1.5 2001/03/06 13:25:43 chregu Exp $
*/
class Cache_Container_file extends Cache_Container {
@@ -53,35 +53,35 @@
* @var string
*/
var $filename_prefix = "";
-
+
/**
* Creates the cache directory if neccessary
*
* @param array Config options: ["cache_dir" => ..., "filename_prefix" => ...]
*/
function Cache_Container_file($options = "") {
-
+
if (is_array($options))
$this->setOptions($options, array("cache_dir", "filename_prefix"));
-
+
clearstatcache();
if (!file_exists($this->cache_dir) || !is_dir($this->cache_dir))
mkdir($this->cache_dir, 0755);
-
+
} // end func contructor
function fetch($id, $group) {
-
+
$file = $this->getFilename($id, $group);
- if (!file_exists($file))
+ if (!file_exists($file))
return array(NULL, NULL, NULL);
-
+
// retrive the content
if (!($fh = @fopen($file, "rb")))
return new CacheError("Can't access cache file '$file'. Check access
rights and path.", __FILE__, __LINE__);
-
+
// file format:
// 1st line: expiration date
// 2nd line: user data
@@ -102,13 +102,13 @@
* otherwise it will break the filestructure.
*/
function save($id, $cachedata, $expires, $group, $userdata) {
-
+
$this->flushPreload($id, $group);
-
+
$file = $this->getFilename($id, $group);
if (!($fh = @fopen($file, "wb")))
return new CacheError("Can't access '$file' to store cache data. Check
access rights and path.", __FILE__, __LINE__);
-
+
// file format:
// 1st line: expiration date
// 2nd line: user data
@@ -123,28 +123,28 @@
// I'm not sure if we need this
touch($file);
- return true;
+ return true;
} // end func save
function delete($id, $group) {
-
+
$this->flushPreload($id, $group);
-
+
$file = $this->getFilename($id, $group);
if (file_exists($file)) {
-
+
$ok = unlink($file);
clearstatcache();
return $ok;
}
-
- return false;
+
+ return false;
} // end func delete
function flush($group) {
-
+
$this->flushPreload();
$dir = ($group) ? $this->cache_dir . $group . "/" : $this->cache_dir;
@@ -153,8 +153,8 @@
return $num_removed;
} // end func flush
-
+
function idExists($id, $group) {
return file_exists($this->getFilename($id, $group));
@@ -176,24 +176,24 @@
* recursive function call!
*/
function garbageCollection($dir = "") {
-
- $this->flushPreload();
+
+ $this->flushPreload();
if (!$dir)
$dir = $this->cache_dir;
if (!($dh = opendir($dir)))
return new CacheError("Can't access cache directory '$dir'. Check
permissions and path.", __FILE__, __LINE__);
-
+
while ($file = readdir($dh)) {
if ("." == $file || ".." == $file)
continue;
-
+
$file = $dir . $file;
if (is_dir($file))
$this->garbageCollection($file . "/");
-
- // skip trouble makers but inform the user
+
+ // skip trouble makers but inform the user
if (!($fh = @fopen($file, "rb"))) {
new CacheError("Can't access cache file '$file', skipping it. Check
permissions and path.", __FILE__, __LINE__);
continue;
@@ -205,8 +205,8 @@
// remove if expired
if ($expire && $expire <= time() && !unlink($file))
new CacheError("Can't unlink cache file '$file', skipping. Check
permissions and path.", __FILE__, __LINE__);
- }
-
+ }
+
closedir($dh);
// flush the disk state cache
@@ -228,14 +228,14 @@
if (isset($group_dirs[$group]))
return $group_dirs[$group] . $this->filename_prefix . $id;
-
-
+
+
$dir = $this->cache_dir . $group . "/";
if (!file_exists($dir)) {
mkdir($dir, 0755);
clearstatcache();
}
-
+
$group_dirs[$group] = $dir;
return $dir . $this->filename_prefix . $id;
@@ -250,16 +250,16 @@
* @throws CacheError
*/
function deleteDir($dir) {
-
+
if (!($dh = opendir($dir)))
return new CacheError("Can't remove directory '$dir'. Check permissions
and path.", __FILE__, __LINE__);
-
+
$num_removed = 0;
-
+
while ($file = readdir($dh)) {
if ("." == $file || ".." == $file)
continue;
-
+
$file = $dir . $file;
if (is_dir($file)) {
@@ -272,15 +272,22 @@
if (unlink($file))
$num_removed++;
-
+
}
-
-
+
+
}
+ // according to php-manual the following is needed for windows installations.
+ closedir($dh);
+ unset( $dh);
+ if ($dir != $this->cache_dir) { //delete the sub-dir entries itself also,
+but not the cache-dir.
+ rmDir($dir);
+ $num_removed++;
+ }
return $num_removed;
} // end func deleteDir
-
+
} // end class file
-?>
\ No newline at end of file
+?>
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]