Skip to content

Commit

Permalink
[VD:LocalFileSystem] fix Studio-42#1882 option copyJoin does not wo…
Browse files Browse the repository at this point in the history
…rk on extract
  • Loading branch information
nao-pon committed Feb 15, 2017
1 parent 1036ec6 commit c978846
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 29 deletions.
93 changes: 69 additions & 24 deletions php/elFinderVolumeDriver.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -5640,30 +5640,7 @@ protected function getFullPath($path, $base) {
* @author Naoki Sawada
*/
public function rmdirRecursive($dir) {
if (!is_link($dir) && is_dir($dir)) {
chmod($dir, 0777);
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file === '.' || $file === '..') {
continue;
}
elFinder::extendTimeLimit(30);
$path = $dir . DIRECTORY_SEPARATOR . $file;
if (!is_link($dir) && is_dir($path)) {
$this->rmdirRecursive($path);
} else {
chmod($path, 0666);
unlink($path);
}
}
closedir($handle);
}
return rmdir($dir);
} elseif (is_file($dir) || is_link($dir)) {
chmod($dir, 0666);
return unlink($dir);
}
return false;
return self::localRmdirRecursive($dir);
}

/**
Expand Down Expand Up @@ -5755,6 +5732,74 @@ protected static function localScandir($dir) {
return $files;
}

/**
* Remove directory recursive on local file system
*
* @param string $dir Target dirctory path
* @return boolean
* @author Naoki Sawada
*/
protected static function localRmdirRecursive($dir) {
if (!is_link($dir) && is_dir($dir)) {
chmod($dir, 0777);
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file === '.' || $file === '..') {
continue;
}
elFinder::extendTimeLimit(30);
$path = $dir . DIRECTORY_SEPARATOR . $file;
if (!is_link($dir) && is_dir($path)) {
self::localRmdirRecursive($path);
} else {
chmod($path, 0666);
unlink($path);
}
}
closedir($handle);
}
return rmdir($dir);
} elseif (is_file($dir) || is_link($dir)) {
chmod($dir, 0666);
return unlink($dir);
}
return false;
}

/**
* Move item recursive on local file system
*
* @param string $src
* @param string $target
* @param string $overWrite
* @param string $copyJoin
* @return boolean
* @author Naoki Sawada
*/
protected static function localMoveRecursive($src, $target, $overWrite = true, $copyJoin = true) {
$res = false;
if (! file_exists($target)) {
return rename($src, $target);
}
if (! $copyJoin || ! is_dir($target)) {
if ($overWrite) {
if (is_dir($target)) {
$del = self::localRmdirRecursive($target);
} else {
$del = unlink($target);
}
if ($del) {
return rename($src, $target);
}
}
} else {
foreach(self::localScandir($src) as $item) {
$res |= self::localMoveRecursive($src.DIRECTORY_SEPARATOR.$item, $target.DIRECTORY_SEPARATOR.$item, $overWrite, $copyJoin);
}
}
return (bool)$res;
}

/**
* Create Zip archive using PHP class ZipArchive
*
Expand Down
6 changes: 1 addition & 5 deletions php/elFinderVolumeLocalFileSystem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1102,14 +1102,10 @@ protected function _extract($path, $arc) {
}
} else {
$dstDir = dirname($path);
$res = false;
$result = array();
foreach($ls as $name) {
$target = $dstDir.DIRECTORY_SEPARATOR.$name;
if (is_dir($target)) {
$this->delTree($target);
}
if (rename($dir.DIRECTORY_SEPARATOR.$name, $target)) {
if (self::localMoveRecursive($dir.DIRECTORY_SEPARATOR.$name, $target, true, $this->options['copyJoin'])) {
$result[] = $target;
}
}
Expand Down

0 comments on commit c978846

Please sign in to comment.