Bug #5208 - Training bacup/restore tool: Cleaning code.
parent
9fd9d928b8
commit
b53ea6cce1
@ -1,39 +0,0 @@ |
||||
<?php // $Id: mkdirr.php 15180 2008-04-29 22:40:16Z yannoo $
|
||||
/** |
||||
* Create a directory structure recursively |
||||
* |
||||
* @author Aidan Lister <aidan@php.net> |
||||
* @version 1.0.0 |
||||
* @param string $pathname The directory structure to create |
||||
* @return bool Returns TRUE on success, FALSE on failure |
||||
*/ |
||||
|
||||
function mkdirr($pathname, $mode = null) { |
||||
// Let us avoid that differency about directory separators in Windows paths. |
||||
$pathname = str_replace("\\", "/", $pathname); |
||||
|
||||
// Check if directory already exists |
||||
if (is_dir($pathname) || empty($pathname)) { |
||||
return true; |
||||
} |
||||
|
||||
// Ensure a file does not already exist with the same name |
||||
if (is_file($pathname)) { |
||||
trigger_error('mkdirr() File exists', E_USER_WARNING); |
||||
return false; |
||||
} |
||||
|
||||
// Crawl up the directory tree |
||||
$next_pathname = substr($pathname, 0, strrpos($pathname, '/')); |
||||
if (mkdirr($next_pathname, $mode)) { |
||||
if (!file_exists($pathname)) { |
||||
$res = @mkdir($pathname, $mode); |
||||
if($res == false) { |
||||
error_log(__FILE__.' line '.__LINE__.': '.(ini_get('track_errors')!=false?$php_errormsg:'error not recorded because track_errors is off in your php.ini'),0); |
||||
} |
||||
return $res; |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
@ -1,52 +0,0 @@ |
||||
<?php // $Id: rmdirr.php 15180 2008-04-29 22:40:16Z yannoo $
|
||||
/** |
||||
* Delete a file, or a folder and its contents |
||||
* |
||||
* @author Aidan Lister <aidan@php.net> |
||||
* @version 1.0.2 |
||||
* @param string $dirname Directory to delete |
||||
* @return bool Returns TRUE on success, FALSE on failure |
||||
*/ |
||||
function rmdirr($dirname) { |
||||
// A sanity check |
||||
if (!file_exists($dirname)) { |
||||
return false; |
||||
} |
||||
|
||||
// Simple delete for a file |
||||
if (is_file($dirname)) { |
||||
$res = @unlink($dirname); |
||||
if ($res === false) { |
||||
error_log(__FILE__.' line '.__LINE__.': '.(ini_get('track_errors')!=false?$php_errormsg:'error not recorded because track_errors is off in your php.ini'),0); |
||||
} |
||||
return $res; |
||||
} |
||||
|
||||
// Loop through the folder |
||||
$dir = dir($dirname); |
||||
// A sanity check |
||||
$is_object_dir = is_object($dir); |
||||
|
||||
if ($is_object_dir) { |
||||
while (false !== $entry = $dir->read()) { |
||||
// Skip pointers |
||||
if ($entry == '.' || $entry == '..') { |
||||
continue; |
||||
} |
||||
// Recurse |
||||
rmdirr("$dirname/$entry"); |
||||
} |
||||
} |
||||
|
||||
// Clean up |
||||
if ($is_object_dir) { |
||||
$dir->close(); |
||||
} |
||||
|
||||
$res = @rmdir($dirname); |
||||
if ($res === false) { |
||||
error_log(__FILE__.' line '.__LINE__.': '.(ini_get('track_errors')!=false?$php_errormsg:'error not recorded because track_errors is off in your php.ini'),0); |
||||
} |
||||
|
||||
return $res; |
||||
} |
||||
Loading…
Reference in new issue