Properly import used classes
This commit is contained in:
parent
75adee1ebd
commit
8450b6aa2d
|
@ -36,8 +36,19 @@
|
||||||
|
|
||||||
namespace OC\Files\Storage;
|
namespace OC\Files\Storage;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use OC\Files\Filesystem;
|
||||||
|
use OC\Files\Stream\Close;
|
||||||
|
use OC\Files\Stream\Dir;
|
||||||
|
use OC\MemCache\ArrayCache;
|
||||||
|
use OCP\Constants;
|
||||||
|
use OCP\Files;
|
||||||
|
use OCP\Files\FileInfo;
|
||||||
use OCP\Files\StorageInvalidException;
|
use OCP\Files\StorageInvalidException;
|
||||||
use OCP\Files\StorageNotAvailableException;
|
use OCP\Files\StorageNotAvailableException;
|
||||||
|
use OCP\Util;
|
||||||
|
use Sabre\DAV\Client;
|
||||||
|
use Sabre\DAV\Exception\NotFound;
|
||||||
use Sabre\HTTP\ClientException;
|
use Sabre\HTTP\ClientException;
|
||||||
use Sabre\HTTP\ClientHttpException;
|
use Sabre\HTTP\ClientHttpException;
|
||||||
|
|
||||||
|
@ -46,24 +57,25 @@ use Sabre\HTTP\ClientHttpException;
|
||||||
*
|
*
|
||||||
* @package OC\Files\Storage
|
* @package OC\Files\Storage
|
||||||
*/
|
*/
|
||||||
class DAV extends \OC\Files\Storage\Common {
|
class DAV extends Common {
|
||||||
|
/** @var string */
|
||||||
protected $password;
|
protected $password;
|
||||||
|
/** @var string */
|
||||||
protected $user;
|
protected $user;
|
||||||
|
/** @var string */
|
||||||
protected $host;
|
protected $host;
|
||||||
|
/** @var bool */
|
||||||
protected $secure;
|
protected $secure;
|
||||||
|
/** @var string */
|
||||||
protected $root;
|
protected $root;
|
||||||
|
/** @var string */
|
||||||
protected $certPath;
|
protected $certPath;
|
||||||
|
/** @var bool */
|
||||||
protected $ready;
|
protected $ready;
|
||||||
/**
|
/** @var Client */
|
||||||
* @var \Sabre\DAV\Client
|
|
||||||
*/
|
|
||||||
private $client;
|
private $client;
|
||||||
|
/** @var ArrayCache */
|
||||||
/**
|
|
||||||
* @var \OC\MemCache\ArrayCache
|
|
||||||
*/
|
|
||||||
private $statCache;
|
private $statCache;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private static $tempFiles = [];
|
private static $tempFiles = [];
|
||||||
|
|
||||||
|
@ -72,7 +84,7 @@ class DAV extends \OC\Files\Storage\Common {
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function __construct($params) {
|
public function __construct($params) {
|
||||||
$this->statCache = new \OC\MemCache\ArrayCache();
|
$this->statCache = new ArrayCache();
|
||||||
if (isset($params['host']) && isset($params['user']) && isset($params['password'])) {
|
if (isset($params['host']) && isset($params['user']) && isset($params['password'])) {
|
||||||
$host = $params['host'];
|
$host = $params['host'];
|
||||||
//remove leading http[s], will be generated in createBaseUri()
|
//remove leading http[s], will be generated in createBaseUri()
|
||||||
|
@ -120,7 +132,7 @@ class DAV extends \OC\Files\Storage\Common {
|
||||||
'password' => $this->password,
|
'password' => $this->password,
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->client = new \Sabre\DAV\Client($settings);
|
$this->client = new Client($settings);
|
||||||
$this->client->setThrowExceptions(true);
|
$this->client->setThrowExceptions(true);
|
||||||
|
|
||||||
if ($this->secure === true && $this->certPath) {
|
if ($this->secure === true && $this->certPath) {
|
||||||
|
@ -200,7 +212,7 @@ class DAV extends \OC\Files\Storage\Common {
|
||||||
$file = basename($file);
|
$file = basename($file);
|
||||||
$content[] = $file;
|
$content[] = $file;
|
||||||
}
|
}
|
||||||
\OC\Files\Stream\Dir::register($id, $content);
|
Dir::register($id, $content);
|
||||||
return opendir('fakedir://' . $id);
|
return opendir('fakedir://' . $id);
|
||||||
} catch (ClientHttpException $e) {
|
} catch (ClientHttpException $e) {
|
||||||
if ($e->getHttpStatus() === 404) {
|
if ($e->getHttpStatus() === 404) {
|
||||||
|
@ -225,14 +237,14 @@ class DAV extends \OC\Files\Storage\Common {
|
||||||
*
|
*
|
||||||
* @return array propfind response
|
* @return array propfind response
|
||||||
*
|
*
|
||||||
* @throws Exception\NotFound
|
* @throws NotFound
|
||||||
*/
|
*/
|
||||||
private function propfind($path) {
|
private function propfind($path) {
|
||||||
$path = $this->cleanPath($path);
|
$path = $this->cleanPath($path);
|
||||||
$cachedResponse = $this->statCache->get($path);
|
$cachedResponse = $this->statCache->get($path);
|
||||||
if ($cachedResponse === false) {
|
if ($cachedResponse === false) {
|
||||||
// we know it didn't exist
|
// we know it didn't exist
|
||||||
throw new Exception\NotFound();
|
throw new NotFound();
|
||||||
}
|
}
|
||||||
// we either don't know it, or we know it exists but need more details
|
// we either don't know it, or we know it exists but need more details
|
||||||
if (is_null($cachedResponse) || $cachedResponse === true) {
|
if (is_null($cachedResponse) || $cachedResponse === true) {
|
||||||
|
@ -250,7 +262,7 @@ class DAV extends \OC\Files\Storage\Common {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->statCache->set($path, $response);
|
$this->statCache->set($path, $response);
|
||||||
} catch (Exception\NotFound $e) {
|
} catch (NotFound $e) {
|
||||||
// remember that this path did not exist
|
// remember that this path did not exist
|
||||||
$this->statCache->clear($path . '/');
|
$this->statCache->clear($path . '/');
|
||||||
$this->statCache->set($path, false);
|
$this->statCache->set($path, false);
|
||||||
|
@ -347,7 +359,7 @@ class DAV extends \OC\Files\Storage\Common {
|
||||||
curl_exec($curl);
|
curl_exec($curl);
|
||||||
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
if ($statusCode !== 200) {
|
if ($statusCode !== 200) {
|
||||||
\OCP\Util::writeLog("webdav client", 'curl GET ' . curl_getinfo($curl, CURLINFO_EFFECTIVE_URL) . ' returned status code ' . $statusCode, \OCP\Util::ERROR);
|
Util::writeLog("webdav client", 'curl GET ' . curl_getinfo($curl, CURLINFO_EFFECTIVE_URL) . ' returned status code ' . $statusCode, Util::ERROR);
|
||||||
}
|
}
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
rewind($fp);
|
rewind($fp);
|
||||||
|
@ -379,9 +391,9 @@ class DAV extends \OC\Files\Storage\Common {
|
||||||
if (!$this->isCreatable(dirname($path))) {
|
if (!$this->isCreatable(dirname($path))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$tmpFile = \OCP\Files::tmpFile($ext);
|
$tmpFile = Files::tmpFile($ext);
|
||||||
}
|
}
|
||||||
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
|
Close::registerCallback($tmpFile, array($this, 'writeBack'));
|
||||||
self::$tempFiles[$tmpFile] = $path;
|
self::$tempFiles[$tmpFile] = $path;
|
||||||
return fopen('close://' . $tmpFile, $mode);
|
return fopen('close://' . $tmpFile, $mode);
|
||||||
}
|
}
|
||||||
|
@ -407,10 +419,10 @@ class DAV extends \OC\Files\Storage\Common {
|
||||||
if (isset($response['{DAV:}quota-available-bytes'])) {
|
if (isset($response['{DAV:}quota-available-bytes'])) {
|
||||||
return (int)$response['{DAV:}quota-available-bytes'];
|
return (int)$response['{DAV:}quota-available-bytes'];
|
||||||
} else {
|
} else {
|
||||||
return \OCP\Files\FileInfo::SPACE_UNKNOWN;
|
return FileInfo::SPACE_UNKNOWN;
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return \OCP\Files\FileInfo::SPACE_UNKNOWN;
|
return FileInfo::SPACE_UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,6 +458,7 @@ class DAV extends \OC\Files\Storage\Common {
|
||||||
/**
|
/**
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param string $data
|
* @param string $data
|
||||||
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function file_put_contents($path, $data) {
|
public function file_put_contents($path, $data) {
|
||||||
$path = $this->cleanPath($path);
|
$path = $this->cleanPath($path);
|
||||||
|
@ -485,7 +498,7 @@ class DAV extends \OC\Files\Storage\Common {
|
||||||
curl_exec($curl);
|
curl_exec($curl);
|
||||||
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
if ($statusCode !== 200) {
|
if ($statusCode !== 200) {
|
||||||
\OCP\Util::writeLog("webdav client", 'curl GET ' . curl_getinfo($curl, CURLINFO_EFFECTIVE_URL) . ' returned status code ' . $statusCode, \OCP\Util::ERROR);
|
Util::writeLog("webdav client", 'curl GET ' . curl_getinfo($curl, CURLINFO_EFFECTIVE_URL) . ' returned status code ' . $statusCode, Util::ERROR);
|
||||||
}
|
}
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
fclose($source);
|
fclose($source);
|
||||||
|
@ -590,7 +603,7 @@ class DAV extends \OC\Files\Storage\Common {
|
||||||
if ($path === '') {
|
if ($path === '') {
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
$path = \OC\Files\Filesystem::normalizePath($path);
|
$path = Filesystem::normalizePath($path);
|
||||||
// remove leading slash
|
// remove leading slash
|
||||||
return substr($path, 1);
|
return substr($path, 1);
|
||||||
}
|
}
|
||||||
|
@ -643,22 +656,22 @@ class DAV extends \OC\Files\Storage\Common {
|
||||||
|
|
||||||
/** {@inheritdoc} */
|
/** {@inheritdoc} */
|
||||||
public function isUpdatable($path) {
|
public function isUpdatable($path) {
|
||||||
return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE);
|
return (bool)($this->getPermissions($path) & Constants::PERMISSION_UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritdoc} */
|
/** {@inheritdoc} */
|
||||||
public function isCreatable($path) {
|
public function isCreatable($path) {
|
||||||
return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE);
|
return (bool)($this->getPermissions($path) & Constants::PERMISSION_CREATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritdoc} */
|
/** {@inheritdoc} */
|
||||||
public function isSharable($path) {
|
public function isSharable($path) {
|
||||||
return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE);
|
return (bool)($this->getPermissions($path) & Constants::PERMISSION_SHARE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritdoc} */
|
/** {@inheritdoc} */
|
||||||
public function isDeletable($path) {
|
public function isDeletable($path) {
|
||||||
return (bool)($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE);
|
return (bool)($this->getPermissions($path) & Constants::PERMISSION_DELETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritdoc} */
|
/** {@inheritdoc} */
|
||||||
|
@ -669,9 +682,9 @@ class DAV extends \OC\Files\Storage\Common {
|
||||||
if (isset($response['{http://owncloud.org/ns}permissions'])) {
|
if (isset($response['{http://owncloud.org/ns}permissions'])) {
|
||||||
return $this->parsePermissions($response['{http://owncloud.org/ns}permissions']);
|
return $this->parsePermissions($response['{http://owncloud.org/ns}permissions']);
|
||||||
} else if ($this->is_dir($path)) {
|
} else if ($this->is_dir($path)) {
|
||||||
return \OCP\Constants::PERMISSION_ALL;
|
return Constants::PERMISSION_ALL;
|
||||||
} else if ($this->file_exists($path)) {
|
} else if ($this->file_exists($path)) {
|
||||||
return \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE;
|
return Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -682,19 +695,19 @@ class DAV extends \OC\Files\Storage\Common {
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
protected function parsePermissions($permissionsString) {
|
protected function parsePermissions($permissionsString) {
|
||||||
$permissions = \OCP\Constants::PERMISSION_READ;
|
$permissions = Constants::PERMISSION_READ;
|
||||||
if (strpos($permissionsString, 'R') !== false) {
|
if (strpos($permissionsString, 'R') !== false) {
|
||||||
$permissions |= \OCP\Constants::PERMISSION_SHARE;
|
$permissions |= Constants::PERMISSION_SHARE;
|
||||||
}
|
}
|
||||||
if (strpos($permissionsString, 'D') !== false) {
|
if (strpos($permissionsString, 'D') !== false) {
|
||||||
$permissions |= \OCP\Constants::PERMISSION_DELETE;
|
$permissions |= Constants::PERMISSION_DELETE;
|
||||||
}
|
}
|
||||||
if (strpos($permissionsString, 'W') !== false) {
|
if (strpos($permissionsString, 'W') !== false) {
|
||||||
$permissions |= \OCP\Constants::PERMISSION_UPDATE;
|
$permissions |= Constants::PERMISSION_UPDATE;
|
||||||
}
|
}
|
||||||
if (strpos($permissionsString, 'CK') !== false) {
|
if (strpos($permissionsString, 'CK') !== false) {
|
||||||
$permissions |= \OCP\Constants::PERMISSION_CREATE;
|
$permissions |= Constants::PERMISSION_CREATE;
|
||||||
$permissions |= \OCP\Constants::PERMISSION_UPDATE;
|
$permissions |= Constants::PERMISSION_UPDATE;
|
||||||
}
|
}
|
||||||
return $permissions;
|
return $permissions;
|
||||||
}
|
}
|
||||||
|
@ -755,7 +768,7 @@ class DAV extends \OC\Files\Storage\Common {
|
||||||
* which might be temporary
|
* which might be temporary
|
||||||
*/
|
*/
|
||||||
private function convertException(Exception $e) {
|
private function convertException(Exception $e) {
|
||||||
\OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
|
Util::writeLog('files_external', $e->getMessage(), Util::ERROR);
|
||||||
if ($e instanceof ClientHttpException) {
|
if ($e instanceof ClientHttpException) {
|
||||||
if ($e->getHttpStatus() === 401) {
|
if ($e->getHttpStatus() === 401) {
|
||||||
// either password was changed or was invalid all along
|
// either password was changed or was invalid all along
|
||||||
|
|
Loading…
Reference in New Issue