Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix #332: Error when renaming on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Oct 19, 2013
1 parent d8bbe88 commit de1be97
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
11 changes: 11 additions & 0 deletions core/src/core/classes/class.AJXP_Utils.php
Expand Up @@ -111,6 +111,17 @@ public static function securePath($path)
return $path;
}

public static function safeDirname($path)
{
return (DIRECTORY_SEPARATOR === "\\" ? str_replace("\\", "/", dirname($path)): dirname($path));
}

public static function safeBasename($path)
{
return (DIRECTORY_SEPARATOR === "\\" ? str_replace("\\", "/", basename($path)): basename($path));
}


/**
* Function to clean a string from specific characters
*
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/access.fs/class.fsAccessDriver.php
Expand Up @@ -499,7 +499,7 @@ public function switchAction($action, $httpVars, $fileVars)
//$reloadContextNode = true;
//$pendingSelection = $filename_new;
if(!isSet($nodesDiffs)) $nodesDiffs = $this->getNodesDiffArray();
if($dest == null) $dest = dirname($file);
if($dest == null) $dest = AJXP_Utils::safeDirname($file);
$nodesDiffs["UPDATE"][$file] = new AJXP_Node($this->urlBase.$dest."/".$filename_new);
$this->logInfo("Rename", array("original"=>$this->addSlugToPath($file), "new"=>$filename_new));

Expand Down
24 changes: 7 additions & 17 deletions core/src/plugins/access.ftp/class.ftpAccessWrapper.php
Expand Up @@ -200,8 +200,8 @@ public function url_stat($path, $flags)
{
// We are in an opendir loop
AJXP_Logger::debug(__CLASS__,__FUNCTION__,"URL_STAT", $path);
if (self::$dirContent != null && self::$dirContentLoopPath == $this->safeDirname($path)) {
$search = $this->safeBasename($path);
if (self::$dirContent != null && self::$dirContentLoopPath == AJXP_Utils::safeDirname($path)) {
$search = AJXP_Utils::safeBasename($path);
//if($search == "") $search = ".";
if (array_key_exists($search, self::$dirContent)) {
return self::$dirContent[$search];
Expand All @@ -213,10 +213,10 @@ public function url_stat($path, $flags)
if ($parts["path"] == "/") {
$basename = ".";
} else {
$basename = $this->safeBasename($serverPath);
$basename = AJXP_Utils::safeBasename($serverPath);
}

$serverParent = $this->safeDirname($parts["path"]);
$serverParent = AJXP_Utils::safeDirname($parts["path"]);
$serverParent = AJXP_Utils::securePath($this->path."/".$serverParent);

$testCd = @ftp_chdir($link, $serverPath);
Expand Down Expand Up @@ -270,7 +270,7 @@ public function dir_opendir ($url , $options )
$folders[$key] = $value;
}
AJXP_Logger::debug(__CLASS__,__FUNCTION__,"OPENDIR ", $folders);
self::$dirContentLoopPath = $this->safeDirname($url);
self::$dirContentLoopPath = AJXP_Utils::safeDirname($url);
self::$dirContent = $folders;//array_merge($folders, $files);
self::$dirContentKeys = array_keys(self::$dirContent);
self::$dirContentIndex = 0;
Expand Down Expand Up @@ -304,8 +304,8 @@ public function dir_rewinddir ()
protected function rawList($link, $serverPath, $target = 'd', $retry = true)
{
if ($target == 'f') {
$parentDir = $this->safeDirname($serverPath);
$fileName = $this->safeBasename($serverPath);
$parentDir = AJXP_Utils::safeDirname($serverPath);
$fileName = AJXP_Utils::safeBasename($serverPath);
ftp_chdir($link, $parentDir);
$rl_dirlist = @ftp_rawlist($link, "-a .");
//AJXP_Logger::debug(__CLASS__,__FUNCTION__,"FILE RAWLIST FROM ".$parentDir);
Expand Down Expand Up @@ -570,14 +570,4 @@ protected function convertingChmod($permissions, $filterForStat = false)
return $mode;
}

protected function safeDirname($path)
{
return (DIRECTORY_SEPARATOR === "\\" ? str_replace("\\", "/", dirname($path)): dirname($path));
}

protected function safeBasename($path)
{
return (DIRECTORY_SEPARATOR === "\\" ? str_replace("\\", "/", basename($path)): basename($path));
}

}

0 comments on commit de1be97

Please sign in to comment.