[lux commit] r125 - trunk/Lux

0 views
Skip to first unread message

codesite...@google.com

unread,
Mar 18, 2008, 2:32:08 PM3/18/08
to lux...@googlegroups.com
Author: rodrigo.moraes
Date: Tue Mar 18 04:58:50 2008
New Revision: 125

Modified:
trunk/Lux/Filesystem.php

Log:
* Added rmdir() recursive.
* Removed unnecesay methods.

Modified: trunk/Lux/Filesystem.php
==============================================================================
--- trunk/Lux/Filesystem.php (original)
+++ trunk/Lux/Filesystem.php Tue Mar 18 04:58:50 2008
@@ -54,17 +54,17 @@

// Fix dir name: always end with a slash.
$to = Solar_Dir::fix($to);
-
+
if (! file_exists($to)) {
// Create destination dir.
- $this->createDir($to);
+ mkdir($to, $this->_config['chmod_dir'], true);
}

- $iter = new DirectoryIterator($from);
+ $iter = new DirectoryIterator($from);

foreach ($iter as $file) {
// Ignore dots and links.
- if ($file->isDot() || (! $file->isFile() && !
$file->isDir())) {
+ if ($file->isDot()) {
continue;
}

@@ -78,39 +78,31 @@

/**
*
- * Creates a directory.
+ * Deletes a directory recursivelly.
*
* @param string $path Directory path.
*
- * @param $chmod Directory permissions.
- *
- * @return bool True on success.
- *
*/
- public function createDir($path, $chmod = null)
+ public function rmDir($path)
{
- if (! $chmod) {
- $chmod = $this->_config['chmod_dir'];
+ if (is_file($path)) {
+ // Single file deletion.
+ unlink($path);
+ return;
}
-
- $base_path = dirname($path);

- if (! is_writable($base_path)) {
- throw $this->_exception('ERR_DIRECTORY_NOT_WRITABLE', array(
- 'path' => $base_path,
- ));
- }
+ $iter = new DirectoryIterator($path);

- $res = false;
- if (! file_exists($path)) {
- $umask = umask(0000);
- if (mkdir($path)) {
- $res = true;
+ // Delete all files and dirs inside the directory.
+ foreach ($iter as $file) {
+ if ($file->isDot()) {
+ continue;
}
- umask($umask);
- chmod($path, $chmod);
+ $this->rmDir($file->getPathname());
}
- return $res;
+
+ // Delete the directory itself.
+ rmdir($path);
}

/**
@@ -129,16 +121,15 @@
if (! $chmod) {
$chmod = $this->_config['chmod_file'];
}
-
- $res = false;
- if (is_file($from)) {
+
+ $res = copy($from, $to);
+
+ if ($res) {
$umask = umask(0000);
- if (copy($from, $to)) {
- $res = true;
- }
- umask($umask);
chmod($to, $chmod);
+ umask($umask);
}
+
return $res;
}

Reply all
Reply to author
Forward
0 new messages