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

Commit

Permalink
Fixed indexation issue with FTP workspaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Dec 29, 2015
1 parent 71dcc30 commit 86c2fb0
Showing 1 changed file with 44 additions and 30 deletions.
74 changes: 44 additions & 30 deletions core/src/plugins/access.ftp/class.ftpAccessWrapper.php
Expand Up @@ -47,10 +47,10 @@ class ftpAccessWrapper implements AjxpWrapper
protected $crtTarget;

// Shared vars self::
private static $dirContentLoopPath;
private static $dirContent;
private static $dirContentKeys;
private static $dirContentIndex;
private static $dirContentLoopPath = array();
private static $dirContent = array();
private static $dirContentKeys = array();
private static $dirContentIndex = array();

private $monthes = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Juil", "Aug", "Sep", "Oct", "Nov", "Dec");

Expand All @@ -71,6 +71,11 @@ public static function isRemote()
return true;
}

public static function isSeekable()
{
return true;
}

public static function copyFileInStream($path, $stream)
{
$fake = new ftpAccessWrapper();
Expand Down Expand Up @@ -200,11 +205,12 @@ 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 == AJXP_Utils::safeDirname($path)) {
$testLoopPath = AJXP_Utils::safeDirname($path);
if (is_array(self::$dirContent[$testLoopPath])) {
$search = AJXP_Utils::safeBasename($path);
//if($search == "") $search = ".";
if (array_key_exists($search, self::$dirContent)) {
return self::$dirContent[$search];
if (array_key_exists($search, self::$dirContent[$testLoopPath])) {
return self::$dirContent[$testLoopPath][$search];
}
}
$parts = $this->parseUrl($path);
Expand Down Expand Up @@ -249,57 +255,65 @@ public function url_stat($path, $flags)

public function dir_opendir ($url , $options )
{
if(isSet(self::$dirContent[$url])){
array_push(self::$dirContentLoopPath, $url);
return true;
}
$parts = $this->parseUrl($url);
$link = $this->createFTPLink();
$serverPath = AJXP_Utils::securePath($this->path."/".$parts["path"]);
$contents = $this->rawList($link, $serverPath);
$folders = $files = array();
foreach ($contents as $entry) {
$result = $this->rawListEntryToStat($entry);
$result = $this->rawListEntryToStat($entry);
AbstractAccessDriver::fixPermissions($result["stat"], ConfService::getRepositoryById($this->repositoryId), array($this, "getRemoteUserId"));
$isDir = $result["dir"];
$statValue = $result["stat"];
$file = $result["name"];
$isDir = $result["dir"];
$statValue = $result["stat"];
$file = $result["name"];
if ($isDir) {
$folders[$file] = $statValue;
} else {
$files[$file] = $statValue;
}
}
// Append all files keys to folders. Do not use array_merge.
foreach ($files as $key => $value) {
$folders[$key] = $value;
}
AJXP_Logger::debug(__CLASS__,__FUNCTION__,"OPENDIR ", $folders);
self::$dirContentLoopPath = AJXP_Utils::safeDirname($url);
self::$dirContent = $folders;//array_merge($folders, $files);
self::$dirContentKeys = array_keys(self::$dirContent);
self::$dirContentIndex = 0;
return true;
}
// Append all files keys to folders. Do not use array_merge.
foreach ($files as $key => $value) {
$folders[$key] = $value;
}
AJXP_Logger::debug(__CLASS__, __FUNCTION__, "OPENDIR ", $folders);
array_push(self::$dirContentLoopPath, $url);
self::$dirContent[$url] = $folders;
self::$dirContentKeys[$url] = array_keys($folders);
self::$dirContentIndex[$url] = 0;
return true;
}

public function dir_closedir ()
{
AJXP_Logger::debug(__CLASS__,__FUNCTION__,"CLOSEDIR");
self::$dirContent = null;
self::$dirContentKeys = null;
self::$dirContentLoopPath = null;
self::$dirContentIndex = 0;
$loopPath = array_pop(self::$dirContentLoopPath);
self::$dirContentIndex[$loopPath] = 0;
//Make a simple rewind, keep in cache
//self::$dirContent[$loopPath] = null;
//self::$dirContentKeys[$loopPath] = null;
}

public function dir_readdir ()
{
self::$dirContentIndex ++;
if (isSet(self::$dirContentKeys[self::$dirContentIndex-1])) {
return self::$dirContentKeys[self::$dirContentIndex-1];
$loopPath = self::$dirContentLoopPath[count(self::$dirContentLoopPath)-1];
$index = self::$dirContentIndex[$loopPath];
self::$dirContentIndex[$loopPath] ++;
if (isSet(self::$dirContentKeys[$loopPath][$index])) {
return self::$dirContentKeys[$loopPath][$index];
} else {
return false;
}
}

public function dir_rewinddir ()
{
self::$dirContentIndex = 0;
$loopPath = self::$dirContentLoopPath[count(self::$dirContentLoopPath)-1];
self::$dirContentIndex[$loopPath] = 0;
}

protected function rawList($link, $serverPath, $target = 'd', $retry = true)
Expand Down

0 comments on commit 86c2fb0

Please sign in to comment.