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

Commit

Permalink
FTP : fix isWriteable call.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jun 25, 2016
1 parent 9dcd012 commit f38b3d5
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions core/src/plugins/access.ftp/FtpAccessDriver.php
Expand Up @@ -49,11 +49,16 @@
*/
class FtpAccessDriver extends FsAccessDriver
{
/**
* Load manifest
* @throws \Exception
*/
public function loadManifest()
{
parent::loadManifest();
// BACKWARD COMPATIBILITY!
$res = $this->getXPath()->query('//param[@name="USER"] | //param[@name="PASS"] | //user_param[@name="USER"] | //user_param[@name="PASS"]');
/** @var \DOMElement $node */
foreach ($res as $node) {
if ($node->getAttribute("name") == "USER") {
$node->setAttribute("name", "FTP_USER");
Expand Down Expand Up @@ -98,6 +103,12 @@ protected function initRepository(ContextInterface $contextInterface)

}

/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return null
* @throws PydioException
*/
public function uploadActions(ServerRequestInterface &$request, ResponseInterface &$response)
{
/** @var ContextInterface $ctx */
Expand Down Expand Up @@ -198,7 +209,7 @@ public function uploadActions(ServerRequestInterface &$request, ResponseInterfac
throw new PydioException("Warning, cannot create folder for temporary copy", false, 413);
}
}
if (!$this->isWriteable($destCopy)) {
if (!is_writable($destCopy)) {
$this->logDebug("Upload error: cannot write into temporary folder");
throw new PydioException("Warning, cannot write into temporary folder", false, 414);
break;
Expand Down Expand Up @@ -229,18 +240,27 @@ public function uploadActions(ServerRequestInterface &$request, ResponseInterfac
return null;
}

public function isWriteable($path, $type="dir")
/**
* Specific isWriteable implementation
* @param AJXP_Node $node
* @return bool
*/
public function isWriteable(AJXP_Node $node)
{
$parts = parse_url($path);
$dir = $parts["path"];
if ($type == "dir" && ($dir == "" || $dir == "/" || $dir == "\\")) { // ROOT, WE ARE NOT SURE TO BE ABLE TO READ THE PARENT
if ($node->isRoot()) { // ROOT, WE ARE NOT SURE TO BE ABLE TO READ THE PARENT
return true;
} else {
return is_writable($path);
return is_writable($node->getUrl());
}

}

/**
* Recursive del dir
* @param string $location
* @param array $repoData
* @throws \Exception
*/
public function deldir($location, $repoData)
{
if (is_dir($location)) {
Expand Down Expand Up @@ -274,6 +294,10 @@ public function deldir($location, $repoData)
}


/**
* @param ContextInterface $ctx
* @param $fileData
*/
public function storeFileToCopy(ContextInterface $ctx, $fileData)
{
$user = $ctx->getUser();
Expand All @@ -283,13 +307,21 @@ public function storeFileToCopy(ContextInterface $ctx, $fileData)
$user->saveTemporaryData("tmp_upload", $files);
}

/**
* @param ContextInterface $ctx
* @return mixed
*/
public function getFileNameToCopy(ContextInterface $ctx)
{
$user = $ctx->getUser();
$files = $user->getTemporaryData("tmp_upload");
return $files[0]["name"];
}

/**
* @param ContextInterface $ctx
* @return string
*/
public function getNextFileToCopy(ContextInterface $ctx)
{
if(!$this->hasFilesToCopy($ctx)) return "";
Expand All @@ -301,13 +333,22 @@ public function getNextFileToCopy(ContextInterface $ctx)
return $fData;
}

/**
* @param ContextInterface $ctx
* @return bool
*/
public function hasFilesToCopy(ContextInterface $ctx)
{
$user = $ctx->getUser();
$files = $user->getTemporaryData("tmp_upload");
return (count($files)?true:false);
}

/**
* @param $params
* @return string
* @throws PydioException
*/
public function testParameters($params)
{
if (empty($params["FTP_USER"])) {
Expand Down

0 comments on commit f38b3d5

Please sign in to comment.