@@ -24,42 +24,42 @@ |
||
24 | 24 | |
25 | 25 | class Forbidden extends \Sabre\DAV\Exception\Forbidden { |
26 | 26 | |
27 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
27 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var bool |
|
31 | - */ |
|
32 | - private $retry; |
|
29 | + /** |
|
30 | + * @var bool |
|
31 | + */ |
|
32 | + private $retry; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param string $message |
|
36 | - * @param bool $retry |
|
37 | - * @param \Exception $previous |
|
38 | - */ |
|
39 | - public function __construct($message, $retry = false, \Exception $previous = null) { |
|
40 | - parent::__construct($message, 0, $previous); |
|
41 | - $this->retry = $retry; |
|
42 | - } |
|
34 | + /** |
|
35 | + * @param string $message |
|
36 | + * @param bool $retry |
|
37 | + * @param \Exception $previous |
|
38 | + */ |
|
39 | + public function __construct($message, $retry = false, \Exception $previous = null) { |
|
40 | + parent::__construct($message, 0, $previous); |
|
41 | + $this->retry = $retry; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * This method allows the exception to include additional information |
|
46 | - * into the WebDAV error response |
|
47 | - * |
|
48 | - * @param \Sabre\DAV\Server $server |
|
49 | - * @param \DOMElement $errorNode |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
44 | + /** |
|
45 | + * This method allows the exception to include additional information |
|
46 | + * into the WebDAV error response |
|
47 | + * |
|
48 | + * @param \Sabre\DAV\Server $server |
|
49 | + * @param \DOMElement $errorNode |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
53 | 53 | |
54 | - // set ownCloud namespace |
|
55 | - $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
54 | + // set ownCloud namespace |
|
55 | + $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
56 | 56 | |
57 | - // adding the retry node |
|
58 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
59 | - $errorNode->appendChild($error); |
|
57 | + // adding the retry node |
|
58 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
59 | + $errorNode->appendChild($error); |
|
60 | 60 | |
61 | - // adding the message node |
|
62 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
63 | - $errorNode->appendChild($error); |
|
64 | - } |
|
61 | + // adding the message node |
|
62 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
63 | + $errorNode->appendChild($error); |
|
64 | + } |
|
65 | 65 | } |
@@ -49,17 +49,17 @@ |
||
49 | 49 | * @param \DOMElement $errorNode |
50 | 50 | * @return void |
51 | 51 | */ |
52 | - public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
52 | + public function serialize(\Sabre\DAV\Server $server, \DOMElement $errorNode) { |
|
53 | 53 | |
54 | 54 | // set ownCloud namespace |
55 | 55 | $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
56 | 56 | |
57 | 57 | // adding the retry node |
58 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
58 | + $error = $errorNode->ownerDocument->createElementNS('o:', 'o:retry', var_export($this->retry, true)); |
|
59 | 59 | $errorNode->appendChild($error); |
60 | 60 | |
61 | 61 | // adding the message node |
62 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
62 | + $error = $errorNode->ownerDocument->createElementNS('o:', 'o:reason', $this->getMessage()); |
|
63 | 63 | $errorNode->appendChild($error); |
64 | 64 | } |
65 | 65 | } |
@@ -26,53 +26,53 @@ |
||
26 | 26 | |
27 | 27 | class InvalidPath extends Exception { |
28 | 28 | |
29 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
29 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var bool |
|
33 | - */ |
|
34 | - private $retry; |
|
31 | + /** |
|
32 | + * @var bool |
|
33 | + */ |
|
34 | + private $retry; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $message |
|
38 | - * @param bool $retry |
|
39 | - */ |
|
40 | - public function __construct($message, $retry = false) { |
|
41 | - parent::__construct($message); |
|
42 | - $this->retry = $retry; |
|
43 | - } |
|
36 | + /** |
|
37 | + * @param string $message |
|
38 | + * @param bool $retry |
|
39 | + */ |
|
40 | + public function __construct($message, $retry = false) { |
|
41 | + parent::__construct($message); |
|
42 | + $this->retry = $retry; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Returns the HTTP status code for this exception |
|
47 | - * |
|
48 | - * @return int |
|
49 | - */ |
|
50 | - public function getHTTPCode() { |
|
45 | + /** |
|
46 | + * Returns the HTTP status code for this exception |
|
47 | + * |
|
48 | + * @return int |
|
49 | + */ |
|
50 | + public function getHTTPCode() { |
|
51 | 51 | |
52 | - return 400; |
|
52 | + return 400; |
|
53 | 53 | |
54 | - } |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * This method allows the exception to include additional information |
|
58 | - * into the WebDAV error response |
|
59 | - * |
|
60 | - * @param \Sabre\DAV\Server $server |
|
61 | - * @param \DOMElement $errorNode |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
56 | + /** |
|
57 | + * This method allows the exception to include additional information |
|
58 | + * into the WebDAV error response |
|
59 | + * |
|
60 | + * @param \Sabre\DAV\Server $server |
|
61 | + * @param \DOMElement $errorNode |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
65 | 65 | |
66 | - // set ownCloud namespace |
|
67 | - $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
66 | + // set ownCloud namespace |
|
67 | + $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
68 | 68 | |
69 | - // adding the retry node |
|
70 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
71 | - $errorNode->appendChild($error); |
|
69 | + // adding the retry node |
|
70 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
71 | + $errorNode->appendChild($error); |
|
72 | 72 | |
73 | - // adding the message node |
|
74 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
75 | - $errorNode->appendChild($error); |
|
76 | - } |
|
73 | + // adding the message node |
|
74 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
75 | + $errorNode->appendChild($error); |
|
76 | + } |
|
77 | 77 | |
78 | 78 | } |
@@ -61,17 +61,17 @@ |
||
61 | 61 | * @param \DOMElement $errorNode |
62 | 62 | * @return void |
63 | 63 | */ |
64 | - public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
64 | + public function serialize(\Sabre\DAV\Server $server, \DOMElement $errorNode) { |
|
65 | 65 | |
66 | 66 | // set ownCloud namespace |
67 | 67 | $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
68 | 68 | |
69 | 69 | // adding the retry node |
70 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
70 | + $error = $errorNode->ownerDocument->createElementNS('o:', 'o:retry', var_export($this->retry, true)); |
|
71 | 71 | $errorNode->appendChild($error); |
72 | 72 | |
73 | 73 | // adding the message node |
74 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
74 | + $error = $errorNode->ownerDocument->createElementNS('o:', 'o:reason', $this->getMessage()); |
|
75 | 75 | $errorNode->appendChild($error); |
76 | 76 | } |
77 | 77 |
@@ -29,27 +29,27 @@ |
||
29 | 29 | |
30 | 30 | class PasswordLoginForbidden extends NotAuthenticated { |
31 | 31 | |
32 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
33 | - |
|
34 | - public function getHTTPCode() { |
|
35 | - return 401; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * This method allows the exception to include additional information |
|
40 | - * into the WebDAV error response |
|
41 | - * |
|
42 | - * @param Server $server |
|
43 | - * @param DOMElement $errorNode |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - public function serialize(Server $server, DOMElement $errorNode) { |
|
47 | - |
|
48 | - // set ownCloud namespace |
|
49 | - $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
50 | - |
|
51 | - $error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'password login forbidden'); |
|
52 | - $errorNode->appendChild($error); |
|
53 | - } |
|
32 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
33 | + |
|
34 | + public function getHTTPCode() { |
|
35 | + return 401; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * This method allows the exception to include additional information |
|
40 | + * into the WebDAV error response |
|
41 | + * |
|
42 | + * @param Server $server |
|
43 | + * @param DOMElement $errorNode |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + public function serialize(Server $server, DOMElement $errorNode) { |
|
47 | + |
|
48 | + // set ownCloud namespace |
|
49 | + $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
50 | + |
|
51 | + $error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'password login forbidden'); |
|
52 | + $errorNode->appendChild($error); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | } |
@@ -30,20 +30,20 @@ |
||
30 | 30 | |
31 | 31 | class FileLocked extends \Sabre\DAV\Exception { |
32 | 32 | |
33 | - public function __construct($message = "", $code = 0, Exception $previous = null) { |
|
34 | - if($previous instanceof \OCP\Files\LockNotAcquiredException) { |
|
35 | - $message = sprintf('Target file %s is locked by another process.', $previous->path); |
|
36 | - } |
|
37 | - parent::__construct($message, $code, $previous); |
|
38 | - } |
|
33 | + public function __construct($message = "", $code = 0, Exception $previous = null) { |
|
34 | + if($previous instanceof \OCP\Files\LockNotAcquiredException) { |
|
35 | + $message = sprintf('Target file %s is locked by another process.', $previous->path); |
|
36 | + } |
|
37 | + parent::__construct($message, $code, $previous); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Returns the HTTP status code for this exception |
|
42 | - * |
|
43 | - * @return int |
|
44 | - */ |
|
45 | - public function getHTTPCode() { |
|
40 | + /** |
|
41 | + * Returns the HTTP status code for this exception |
|
42 | + * |
|
43 | + * @return int |
|
44 | + */ |
|
45 | + public function getHTTPCode() { |
|
46 | 46 | |
47 | - return 423; |
|
48 | - } |
|
47 | + return 423; |
|
48 | + } |
|
49 | 49 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | class FileLocked extends \Sabre\DAV\Exception { |
32 | 32 | |
33 | 33 | public function __construct($message = "", $code = 0, Exception $previous = null) { |
34 | - if($previous instanceof \OCP\Files\LockNotAcquiredException) { |
|
34 | + if ($previous instanceof \OCP\Files\LockNotAcquiredException) { |
|
35 | 35 | $message = sprintf('Target file %s is locked by another process.', $previous->path); |
36 | 36 | } |
37 | 37 | parent::__construct($message, $code, $previous); |
@@ -31,15 +31,15 @@ |
||
31 | 31 | */ |
32 | 32 | class UnsupportedMediaType extends \Sabre\DAV\Exception { |
33 | 33 | |
34 | - /** |
|
35 | - * Returns the HTTP status code for this exception |
|
36 | - * |
|
37 | - * @return int |
|
38 | - */ |
|
39 | - public function getHTTPCode() { |
|
34 | + /** |
|
35 | + * Returns the HTTP status code for this exception |
|
36 | + * |
|
37 | + * @return int |
|
38 | + */ |
|
39 | + public function getHTTPCode() { |
|
40 | 40 | |
41 | - return 415; |
|
41 | + return 415; |
|
42 | 42 | |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | 45 | } |
@@ -31,15 +31,15 @@ |
||
31 | 31 | */ |
32 | 32 | class EntityTooLarge extends \Sabre\DAV\Exception { |
33 | 33 | |
34 | - /** |
|
35 | - * Returns the HTTP status code for this exception |
|
36 | - * |
|
37 | - * @return int |
|
38 | - */ |
|
39 | - public function getHTTPCode() { |
|
34 | + /** |
|
35 | + * Returns the HTTP status code for this exception |
|
36 | + * |
|
37 | + * @return int |
|
38 | + */ |
|
39 | + public function getHTTPCode() { |
|
40 | 40 | |
41 | - return 413; |
|
41 | + return 413; |
|
42 | 42 | |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | 45 | } |
@@ -42,158 +42,158 @@ |
||
42 | 42 | use Sabre\DAV\Auth\Backend\BackendInterface; |
43 | 43 | |
44 | 44 | class ServerFactory { |
45 | - /** @var IConfig */ |
|
46 | - private $config; |
|
47 | - /** @var ILogger */ |
|
48 | - private $logger; |
|
49 | - /** @var IDBConnection */ |
|
50 | - private $databaseConnection; |
|
51 | - /** @var IUserSession */ |
|
52 | - private $userSession; |
|
53 | - /** @var IMountManager */ |
|
54 | - private $mountManager; |
|
55 | - /** @var ITagManager */ |
|
56 | - private $tagManager; |
|
57 | - /** @var IRequest */ |
|
58 | - private $request; |
|
59 | - /** @var IPreview */ |
|
60 | - private $previewManager; |
|
45 | + /** @var IConfig */ |
|
46 | + private $config; |
|
47 | + /** @var ILogger */ |
|
48 | + private $logger; |
|
49 | + /** @var IDBConnection */ |
|
50 | + private $databaseConnection; |
|
51 | + /** @var IUserSession */ |
|
52 | + private $userSession; |
|
53 | + /** @var IMountManager */ |
|
54 | + private $mountManager; |
|
55 | + /** @var ITagManager */ |
|
56 | + private $tagManager; |
|
57 | + /** @var IRequest */ |
|
58 | + private $request; |
|
59 | + /** @var IPreview */ |
|
60 | + private $previewManager; |
|
61 | 61 | |
62 | - /** |
|
63 | - * @param IConfig $config |
|
64 | - * @param ILogger $logger |
|
65 | - * @param IDBConnection $databaseConnection |
|
66 | - * @param IUserSession $userSession |
|
67 | - * @param IMountManager $mountManager |
|
68 | - * @param ITagManager $tagManager |
|
69 | - * @param IRequest $request |
|
70 | - * @param IPreview $previewManager |
|
71 | - */ |
|
72 | - public function __construct( |
|
73 | - IConfig $config, |
|
74 | - ILogger $logger, |
|
75 | - IDBConnection $databaseConnection, |
|
76 | - IUserSession $userSession, |
|
77 | - IMountManager $mountManager, |
|
78 | - ITagManager $tagManager, |
|
79 | - IRequest $request, |
|
80 | - IPreview $previewManager |
|
81 | - ) { |
|
82 | - $this->config = $config; |
|
83 | - $this->logger = $logger; |
|
84 | - $this->databaseConnection = $databaseConnection; |
|
85 | - $this->userSession = $userSession; |
|
86 | - $this->mountManager = $mountManager; |
|
87 | - $this->tagManager = $tagManager; |
|
88 | - $this->request = $request; |
|
89 | - $this->previewManager = $previewManager; |
|
90 | - } |
|
62 | + /** |
|
63 | + * @param IConfig $config |
|
64 | + * @param ILogger $logger |
|
65 | + * @param IDBConnection $databaseConnection |
|
66 | + * @param IUserSession $userSession |
|
67 | + * @param IMountManager $mountManager |
|
68 | + * @param ITagManager $tagManager |
|
69 | + * @param IRequest $request |
|
70 | + * @param IPreview $previewManager |
|
71 | + */ |
|
72 | + public function __construct( |
|
73 | + IConfig $config, |
|
74 | + ILogger $logger, |
|
75 | + IDBConnection $databaseConnection, |
|
76 | + IUserSession $userSession, |
|
77 | + IMountManager $mountManager, |
|
78 | + ITagManager $tagManager, |
|
79 | + IRequest $request, |
|
80 | + IPreview $previewManager |
|
81 | + ) { |
|
82 | + $this->config = $config; |
|
83 | + $this->logger = $logger; |
|
84 | + $this->databaseConnection = $databaseConnection; |
|
85 | + $this->userSession = $userSession; |
|
86 | + $this->mountManager = $mountManager; |
|
87 | + $this->tagManager = $tagManager; |
|
88 | + $this->request = $request; |
|
89 | + $this->previewManager = $previewManager; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @param string $baseUri |
|
94 | - * @param string $requestUri |
|
95 | - * @param BackendInterface $authBackend |
|
96 | - * @param callable $viewCallBack callback that should return the view for the dav endpoint |
|
97 | - * @return Server |
|
98 | - */ |
|
99 | - public function createServer($baseUri, |
|
100 | - $requestUri, |
|
101 | - BackendInterface $authBackend, |
|
102 | - callable $viewCallBack) { |
|
103 | - // Fire up server |
|
104 | - $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); |
|
105 | - $server = new \OCA\DAV\Connector\Sabre\Server($objectTree); |
|
106 | - // Set URL explicitly due to reverse-proxy situations |
|
107 | - $server->httpRequest->setUrl($requestUri); |
|
108 | - $server->setBaseUri($baseUri); |
|
92 | + /** |
|
93 | + * @param string $baseUri |
|
94 | + * @param string $requestUri |
|
95 | + * @param BackendInterface $authBackend |
|
96 | + * @param callable $viewCallBack callback that should return the view for the dav endpoint |
|
97 | + * @return Server |
|
98 | + */ |
|
99 | + public function createServer($baseUri, |
|
100 | + $requestUri, |
|
101 | + BackendInterface $authBackend, |
|
102 | + callable $viewCallBack) { |
|
103 | + // Fire up server |
|
104 | + $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); |
|
105 | + $server = new \OCA\DAV\Connector\Sabre\Server($objectTree); |
|
106 | + // Set URL explicitly due to reverse-proxy situations |
|
107 | + $server->httpRequest->setUrl($requestUri); |
|
108 | + $server->setBaseUri($baseUri); |
|
109 | 109 | |
110 | - // Load plugins |
|
111 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
|
112 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); |
|
113 | - $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend)); |
|
114 | - // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to / |
|
115 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); |
|
116 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); |
|
117 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
118 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
119 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
120 | - if($this->request->isUserAgent([ |
|
121 | - '/WebDAVFS/', |
|
122 | - '/Microsoft Office OneNote 2013/', |
|
123 | - '/Microsoft-WebDAV-MiniRedir/', |
|
124 | - ])) { |
|
125 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); |
|
126 | - } |
|
110 | + // Load plugins |
|
111 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
|
112 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); |
|
113 | + $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend)); |
|
114 | + // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to / |
|
115 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); |
|
116 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); |
|
117 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
118 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
119 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
120 | + if($this->request->isUserAgent([ |
|
121 | + '/WebDAVFS/', |
|
122 | + '/Microsoft Office OneNote 2013/', |
|
123 | + '/Microsoft-WebDAV-MiniRedir/', |
|
124 | + ])) { |
|
125 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); |
|
126 | + } |
|
127 | 127 | |
128 | - if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) { |
|
129 | - $server->addPlugin(new BrowserErrorPagePlugin()); |
|
130 | - } |
|
128 | + if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) { |
|
129 | + $server->addPlugin(new BrowserErrorPagePlugin()); |
|
130 | + } |
|
131 | 131 | |
132 | - // wait with registering these until auth is handled and the filesystem is setup |
|
133 | - $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { |
|
134 | - // ensure the skeleton is copied |
|
135 | - $userFolder = \OC::$server->getUserFolder(); |
|
132 | + // wait with registering these until auth is handled and the filesystem is setup |
|
133 | + $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { |
|
134 | + // ensure the skeleton is copied |
|
135 | + $userFolder = \OC::$server->getUserFolder(); |
|
136 | 136 | |
137 | - /** @var \OC\Files\View $view */ |
|
138 | - $view = $viewCallBack($server); |
|
139 | - if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { |
|
140 | - $rootInfo = $userFolder; |
|
141 | - } else { |
|
142 | - $rootInfo = $view->getFileInfo(''); |
|
143 | - } |
|
137 | + /** @var \OC\Files\View $view */ |
|
138 | + $view = $viewCallBack($server); |
|
139 | + if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { |
|
140 | + $rootInfo = $userFolder; |
|
141 | + } else { |
|
142 | + $rootInfo = $view->getFileInfo(''); |
|
143 | + } |
|
144 | 144 | |
145 | - // Create ownCloud Dir |
|
146 | - if ($rootInfo->getType() === 'dir') { |
|
147 | - $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree); |
|
148 | - } else { |
|
149 | - $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo); |
|
150 | - } |
|
151 | - $objectTree->init($root, $view, $this->mountManager); |
|
145 | + // Create ownCloud Dir |
|
146 | + if ($rootInfo->getType() === 'dir') { |
|
147 | + $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree); |
|
148 | + } else { |
|
149 | + $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo); |
|
150 | + } |
|
151 | + $objectTree->init($root, $view, $this->mountManager); |
|
152 | 152 | |
153 | - $server->addPlugin( |
|
154 | - new \OCA\DAV\Connector\Sabre\FilesPlugin( |
|
155 | - $objectTree, |
|
156 | - $this->config, |
|
157 | - $this->request, |
|
158 | - $this->previewManager, |
|
159 | - false, |
|
160 | - !$this->config->getSystemValue('debug', false) |
|
161 | - ) |
|
162 | - ); |
|
163 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view)); |
|
153 | + $server->addPlugin( |
|
154 | + new \OCA\DAV\Connector\Sabre\FilesPlugin( |
|
155 | + $objectTree, |
|
156 | + $this->config, |
|
157 | + $this->request, |
|
158 | + $this->previewManager, |
|
159 | + false, |
|
160 | + !$this->config->getSystemValue('debug', false) |
|
161 | + ) |
|
162 | + ); |
|
163 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view)); |
|
164 | 164 | |
165 | - if($this->userSession->isLoggedIn()) { |
|
166 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
|
167 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
|
168 | - $objectTree, |
|
169 | - $this->userSession, |
|
170 | - $userFolder, |
|
171 | - \OC::$server->getShareManager() |
|
172 | - )); |
|
173 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession)); |
|
174 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin( |
|
175 | - $objectTree, |
|
176 | - $view, |
|
177 | - \OC::$server->getSystemTagManager(), |
|
178 | - \OC::$server->getSystemTagObjectMapper(), |
|
179 | - \OC::$server->getTagManager(), |
|
180 | - $this->userSession, |
|
181 | - \OC::$server->getGroupManager(), |
|
182 | - $userFolder |
|
183 | - )); |
|
184 | - // custom properties plugin must be the last one |
|
185 | - $server->addPlugin( |
|
186 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
187 | - new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend( |
|
188 | - $objectTree, |
|
189 | - $this->databaseConnection, |
|
190 | - $this->userSession->getUser() |
|
191 | - ) |
|
192 | - ) |
|
193 | - ); |
|
194 | - } |
|
195 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin()); |
|
196 | - }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request |
|
197 | - return $server; |
|
198 | - } |
|
165 | + if($this->userSession->isLoggedIn()) { |
|
166 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
|
167 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
|
168 | + $objectTree, |
|
169 | + $this->userSession, |
|
170 | + $userFolder, |
|
171 | + \OC::$server->getShareManager() |
|
172 | + )); |
|
173 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession)); |
|
174 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin( |
|
175 | + $objectTree, |
|
176 | + $view, |
|
177 | + \OC::$server->getSystemTagManager(), |
|
178 | + \OC::$server->getSystemTagObjectMapper(), |
|
179 | + \OC::$server->getTagManager(), |
|
180 | + $this->userSession, |
|
181 | + \OC::$server->getGroupManager(), |
|
182 | + $userFolder |
|
183 | + )); |
|
184 | + // custom properties plugin must be the last one |
|
185 | + $server->addPlugin( |
|
186 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
187 | + new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend( |
|
188 | + $objectTree, |
|
189 | + $this->databaseConnection, |
|
190 | + $this->userSession->getUser() |
|
191 | + ) |
|
192 | + ) |
|
193 | + ); |
|
194 | + } |
|
195 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin()); |
|
196 | + }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request |
|
197 | + return $server; |
|
198 | + } |
|
199 | 199 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
118 | 118 | // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
119 | 119 | // we do not provide locking we emulate it using a fake locking plugin. |
120 | - if($this->request->isUserAgent([ |
|
120 | + if ($this->request->isUserAgent([ |
|
121 | 121 | '/WebDAVFS/', |
122 | 122 | '/Microsoft Office OneNote 2013/', |
123 | 123 | '/Microsoft-WebDAV-MiniRedir/', |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | } |
131 | 131 | |
132 | 132 | // wait with registering these until auth is handled and the filesystem is setup |
133 | - $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { |
|
133 | + $server->on('beforeMethod', function() use ($server, $objectTree, $viewCallBack) { |
|
134 | 134 | // ensure the skeleton is copied |
135 | 135 | $userFolder = \OC::$server->getUserFolder(); |
136 | 136 | |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | ); |
163 | 163 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view)); |
164 | 164 | |
165 | - if($this->userSession->isLoggedIn()) { |
|
165 | + if ($this->userSession->isLoggedIn()) { |
|
166 | 166 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
167 | 167 | $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
168 | 168 | $objectTree, |
@@ -41,315 +41,315 @@ |
||
41 | 41 | |
42 | 42 | abstract class Node implements \Sabre\DAV\INode { |
43 | 43 | |
44 | - /** |
|
45 | - * @var \OC\Files\View |
|
46 | - */ |
|
47 | - protected $fileView; |
|
48 | - |
|
49 | - /** |
|
50 | - * The path to the current node |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $path; |
|
55 | - |
|
56 | - /** |
|
57 | - * node properties cache |
|
58 | - * |
|
59 | - * @var array |
|
60 | - */ |
|
61 | - protected $property_cache = null; |
|
62 | - |
|
63 | - /** |
|
64 | - * @var \OCP\Files\FileInfo |
|
65 | - */ |
|
66 | - protected $info; |
|
67 | - |
|
68 | - /** |
|
69 | - * @var IManager |
|
70 | - */ |
|
71 | - protected $shareManager; |
|
72 | - |
|
73 | - /** |
|
74 | - * Sets up the node, expects a full path name |
|
75 | - * |
|
76 | - * @param \OC\Files\View $view |
|
77 | - * @param \OCP\Files\FileInfo $info |
|
78 | - * @param IManager $shareManager |
|
79 | - */ |
|
80 | - public function __construct($view, $info, IManager $shareManager = null) { |
|
81 | - $this->fileView = $view; |
|
82 | - $this->path = $this->fileView->getRelativePath($info->getPath()); |
|
83 | - $this->info = $info; |
|
84 | - if ($shareManager) { |
|
85 | - $this->shareManager = $shareManager; |
|
86 | - } else { |
|
87 | - $this->shareManager = \OC::$server->getShareManager(); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - protected function refreshInfo() { |
|
92 | - $this->info = $this->fileView->getFileInfo($this->path); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Returns the name of the node |
|
97 | - * |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function getName() { |
|
101 | - return $this->info->getName(); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Returns the full path |
|
106 | - * |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function getPath() { |
|
110 | - return $this->path; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Renames the node |
|
115 | - * |
|
116 | - * @param string $name The new name |
|
117 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
118 | - * @throws \Sabre\DAV\Exception\Forbidden |
|
119 | - */ |
|
120 | - public function setName($name) { |
|
121 | - |
|
122 | - // rename is only allowed if the update privilege is granted |
|
123 | - if (!$this->info->isUpdateable()) { |
|
124 | - throw new \Sabre\DAV\Exception\Forbidden(); |
|
125 | - } |
|
126 | - |
|
127 | - list($parentPath,) = \Sabre\HTTP\URLUtil::splitPath($this->path); |
|
128 | - list(, $newName) = \Sabre\HTTP\URLUtil::splitPath($name); |
|
129 | - |
|
130 | - // verify path of the target |
|
131 | - $this->verifyPath(); |
|
132 | - |
|
133 | - $newPath = $parentPath . '/' . $newName; |
|
134 | - |
|
135 | - $this->fileView->rename($this->path, $newPath); |
|
136 | - |
|
137 | - $this->path = $newPath; |
|
138 | - |
|
139 | - $this->refreshInfo(); |
|
140 | - } |
|
141 | - |
|
142 | - public function setPropertyCache($property_cache) { |
|
143 | - $this->property_cache = $property_cache; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Returns the last modification time, as a unix timestamp |
|
148 | - * |
|
149 | - * @return int timestamp as integer |
|
150 | - */ |
|
151 | - public function getLastModified() { |
|
152 | - $timestamp = $this->info->getMtime(); |
|
153 | - if (!empty($timestamp)) { |
|
154 | - return (int)$timestamp; |
|
155 | - } |
|
156 | - return $timestamp; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * sets the last modification time of the file (mtime) to the value given |
|
161 | - * in the second parameter or to now if the second param is empty. |
|
162 | - * Even if the modification time is set to a custom value the access time is set to now. |
|
163 | - */ |
|
164 | - public function touch($mtime) { |
|
165 | - $this->fileView->touch($this->path, $mtime); |
|
166 | - $this->refreshInfo(); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Returns the ETag for a file |
|
171 | - * |
|
172 | - * An ETag is a unique identifier representing the current version of the |
|
173 | - * file. If the file changes, the ETag MUST change. The ETag is an |
|
174 | - * arbitrary string, but MUST be surrounded by double-quotes. |
|
175 | - * |
|
176 | - * Return null if the ETag can not effectively be determined |
|
177 | - * |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public function getETag() { |
|
181 | - return '"' . $this->info->getEtag() . '"'; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Sets the ETag |
|
186 | - * |
|
187 | - * @param string $etag |
|
188 | - * |
|
189 | - * @return int file id of updated file or -1 on failure |
|
190 | - */ |
|
191 | - public function setETag($etag) { |
|
192 | - return $this->fileView->putFileInfo($this->path, array('etag' => $etag)); |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Returns the size of the node, in bytes |
|
197 | - * |
|
198 | - * @return integer |
|
199 | - */ |
|
200 | - public function getSize() { |
|
201 | - return $this->info->getSize(); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Returns the cache's file id |
|
206 | - * |
|
207 | - * @return int |
|
208 | - */ |
|
209 | - public function getId() { |
|
210 | - return $this->info->getId(); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * @return string|null |
|
215 | - */ |
|
216 | - public function getFileId() { |
|
217 | - if ($this->info->getId()) { |
|
218 | - $instanceId = \OC_Util::getInstanceId(); |
|
219 | - $id = sprintf('%08d', $this->info->getId()); |
|
220 | - return $id . $instanceId; |
|
221 | - } |
|
222 | - |
|
223 | - return null; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * @return integer |
|
228 | - */ |
|
229 | - public function getInternalFileId() { |
|
230 | - return $this->info->getId(); |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * @param string $user |
|
235 | - * @return int |
|
236 | - */ |
|
237 | - public function getSharePermissions($user) { |
|
238 | - |
|
239 | - // check of we access a federated share |
|
240 | - if ($user !== null) { |
|
241 | - try { |
|
242 | - $share = $this->shareManager->getShareByToken($user); |
|
243 | - return $share->getPermissions(); |
|
244 | - } catch (ShareNotFound $e) { |
|
245 | - // ignore |
|
246 | - } |
|
247 | - } |
|
248 | - |
|
249 | - $storage = $this->info->getStorage(); |
|
250 | - |
|
251 | - $path = $this->info->getInternalPath(); |
|
252 | - |
|
253 | - if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
254 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
255 | - $permissions = (int)$storage->getShare()->getPermissions(); |
|
256 | - } else { |
|
257 | - $permissions = $storage->getPermissions($path); |
|
258 | - } |
|
259 | - |
|
260 | - /* |
|
44 | + /** |
|
45 | + * @var \OC\Files\View |
|
46 | + */ |
|
47 | + protected $fileView; |
|
48 | + |
|
49 | + /** |
|
50 | + * The path to the current node |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $path; |
|
55 | + |
|
56 | + /** |
|
57 | + * node properties cache |
|
58 | + * |
|
59 | + * @var array |
|
60 | + */ |
|
61 | + protected $property_cache = null; |
|
62 | + |
|
63 | + /** |
|
64 | + * @var \OCP\Files\FileInfo |
|
65 | + */ |
|
66 | + protected $info; |
|
67 | + |
|
68 | + /** |
|
69 | + * @var IManager |
|
70 | + */ |
|
71 | + protected $shareManager; |
|
72 | + |
|
73 | + /** |
|
74 | + * Sets up the node, expects a full path name |
|
75 | + * |
|
76 | + * @param \OC\Files\View $view |
|
77 | + * @param \OCP\Files\FileInfo $info |
|
78 | + * @param IManager $shareManager |
|
79 | + */ |
|
80 | + public function __construct($view, $info, IManager $shareManager = null) { |
|
81 | + $this->fileView = $view; |
|
82 | + $this->path = $this->fileView->getRelativePath($info->getPath()); |
|
83 | + $this->info = $info; |
|
84 | + if ($shareManager) { |
|
85 | + $this->shareManager = $shareManager; |
|
86 | + } else { |
|
87 | + $this->shareManager = \OC::$server->getShareManager(); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + protected function refreshInfo() { |
|
92 | + $this->info = $this->fileView->getFileInfo($this->path); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Returns the name of the node |
|
97 | + * |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function getName() { |
|
101 | + return $this->info->getName(); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Returns the full path |
|
106 | + * |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function getPath() { |
|
110 | + return $this->path; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Renames the node |
|
115 | + * |
|
116 | + * @param string $name The new name |
|
117 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
118 | + * @throws \Sabre\DAV\Exception\Forbidden |
|
119 | + */ |
|
120 | + public function setName($name) { |
|
121 | + |
|
122 | + // rename is only allowed if the update privilege is granted |
|
123 | + if (!$this->info->isUpdateable()) { |
|
124 | + throw new \Sabre\DAV\Exception\Forbidden(); |
|
125 | + } |
|
126 | + |
|
127 | + list($parentPath,) = \Sabre\HTTP\URLUtil::splitPath($this->path); |
|
128 | + list(, $newName) = \Sabre\HTTP\URLUtil::splitPath($name); |
|
129 | + |
|
130 | + // verify path of the target |
|
131 | + $this->verifyPath(); |
|
132 | + |
|
133 | + $newPath = $parentPath . '/' . $newName; |
|
134 | + |
|
135 | + $this->fileView->rename($this->path, $newPath); |
|
136 | + |
|
137 | + $this->path = $newPath; |
|
138 | + |
|
139 | + $this->refreshInfo(); |
|
140 | + } |
|
141 | + |
|
142 | + public function setPropertyCache($property_cache) { |
|
143 | + $this->property_cache = $property_cache; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Returns the last modification time, as a unix timestamp |
|
148 | + * |
|
149 | + * @return int timestamp as integer |
|
150 | + */ |
|
151 | + public function getLastModified() { |
|
152 | + $timestamp = $this->info->getMtime(); |
|
153 | + if (!empty($timestamp)) { |
|
154 | + return (int)$timestamp; |
|
155 | + } |
|
156 | + return $timestamp; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * sets the last modification time of the file (mtime) to the value given |
|
161 | + * in the second parameter or to now if the second param is empty. |
|
162 | + * Even if the modification time is set to a custom value the access time is set to now. |
|
163 | + */ |
|
164 | + public function touch($mtime) { |
|
165 | + $this->fileView->touch($this->path, $mtime); |
|
166 | + $this->refreshInfo(); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Returns the ETag for a file |
|
171 | + * |
|
172 | + * An ETag is a unique identifier representing the current version of the |
|
173 | + * file. If the file changes, the ETag MUST change. The ETag is an |
|
174 | + * arbitrary string, but MUST be surrounded by double-quotes. |
|
175 | + * |
|
176 | + * Return null if the ETag can not effectively be determined |
|
177 | + * |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public function getETag() { |
|
181 | + return '"' . $this->info->getEtag() . '"'; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Sets the ETag |
|
186 | + * |
|
187 | + * @param string $etag |
|
188 | + * |
|
189 | + * @return int file id of updated file or -1 on failure |
|
190 | + */ |
|
191 | + public function setETag($etag) { |
|
192 | + return $this->fileView->putFileInfo($this->path, array('etag' => $etag)); |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Returns the size of the node, in bytes |
|
197 | + * |
|
198 | + * @return integer |
|
199 | + */ |
|
200 | + public function getSize() { |
|
201 | + return $this->info->getSize(); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Returns the cache's file id |
|
206 | + * |
|
207 | + * @return int |
|
208 | + */ |
|
209 | + public function getId() { |
|
210 | + return $this->info->getId(); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * @return string|null |
|
215 | + */ |
|
216 | + public function getFileId() { |
|
217 | + if ($this->info->getId()) { |
|
218 | + $instanceId = \OC_Util::getInstanceId(); |
|
219 | + $id = sprintf('%08d', $this->info->getId()); |
|
220 | + return $id . $instanceId; |
|
221 | + } |
|
222 | + |
|
223 | + return null; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * @return integer |
|
228 | + */ |
|
229 | + public function getInternalFileId() { |
|
230 | + return $this->info->getId(); |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * @param string $user |
|
235 | + * @return int |
|
236 | + */ |
|
237 | + public function getSharePermissions($user) { |
|
238 | + |
|
239 | + // check of we access a federated share |
|
240 | + if ($user !== null) { |
|
241 | + try { |
|
242 | + $share = $this->shareManager->getShareByToken($user); |
|
243 | + return $share->getPermissions(); |
|
244 | + } catch (ShareNotFound $e) { |
|
245 | + // ignore |
|
246 | + } |
|
247 | + } |
|
248 | + |
|
249 | + $storage = $this->info->getStorage(); |
|
250 | + |
|
251 | + $path = $this->info->getInternalPath(); |
|
252 | + |
|
253 | + if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
254 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
255 | + $permissions = (int)$storage->getShare()->getPermissions(); |
|
256 | + } else { |
|
257 | + $permissions = $storage->getPermissions($path); |
|
258 | + } |
|
259 | + |
|
260 | + /* |
|
261 | 261 | * We can always share non moveable mount points with DELETE and UPDATE |
262 | 262 | * Eventually we need to do this properly |
263 | 263 | */ |
264 | - $mountpoint = $this->info->getMountPoint(); |
|
265 | - if (!($mountpoint instanceof MoveableMount)) { |
|
266 | - $mountpointpath = $mountpoint->getMountPoint(); |
|
267 | - if (substr($mountpointpath, -1) === '/') { |
|
268 | - $mountpointpath = substr($mountpointpath, 0, -1); |
|
269 | - } |
|
270 | - |
|
271 | - if ($mountpointpath === $this->info->getPath()) { |
|
272 | - $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - /* |
|
264 | + $mountpoint = $this->info->getMountPoint(); |
|
265 | + if (!($mountpoint instanceof MoveableMount)) { |
|
266 | + $mountpointpath = $mountpoint->getMountPoint(); |
|
267 | + if (substr($mountpointpath, -1) === '/') { |
|
268 | + $mountpointpath = substr($mountpointpath, 0, -1); |
|
269 | + } |
|
270 | + |
|
271 | + if ($mountpointpath === $this->info->getPath()) { |
|
272 | + $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + /* |
|
277 | 277 | * Files can't have create or delete permissions |
278 | 278 | */ |
279 | - if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
280 | - $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE); |
|
281 | - } |
|
282 | - |
|
283 | - return $permissions; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * @return string |
|
288 | - */ |
|
289 | - public function getDavPermissions() { |
|
290 | - $p = ''; |
|
291 | - if ($this->info->isShared()) { |
|
292 | - $p .= 'S'; |
|
293 | - } |
|
294 | - if ($this->info->isShareable()) { |
|
295 | - $p .= 'R'; |
|
296 | - } |
|
297 | - if ($this->info->isMounted()) { |
|
298 | - $p .= 'M'; |
|
299 | - } |
|
300 | - if ($this->info->isDeletable()) { |
|
301 | - $p .= 'D'; |
|
302 | - } |
|
303 | - if ($this->info->isUpdateable()) { |
|
304 | - $p .= 'NV'; // Renameable, Moveable |
|
305 | - } |
|
306 | - if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
307 | - if ($this->info->isUpdateable()) { |
|
308 | - $p .= 'W'; |
|
309 | - } |
|
310 | - } else { |
|
311 | - if ($this->info->isCreatable()) { |
|
312 | - $p .= 'CK'; |
|
313 | - } |
|
314 | - } |
|
315 | - return $p; |
|
316 | - } |
|
317 | - |
|
318 | - public function getOwner() { |
|
319 | - return $this->info->getOwner(); |
|
320 | - } |
|
321 | - |
|
322 | - protected function verifyPath() { |
|
323 | - try { |
|
324 | - $fileName = basename($this->info->getPath()); |
|
325 | - $this->fileView->verifyPath($this->path, $fileName); |
|
326 | - } catch (\OCP\Files\InvalidPathException $ex) { |
|
327 | - throw new InvalidPath($ex->getMessage()); |
|
328 | - } |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
333 | - */ |
|
334 | - public function acquireLock($type) { |
|
335 | - $this->fileView->lockFile($this->path, $type); |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
340 | - */ |
|
341 | - public function releaseLock($type) { |
|
342 | - $this->fileView->unlockFile($this->path, $type); |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
347 | - */ |
|
348 | - public function changeLock($type) { |
|
349 | - $this->fileView->changeLock($this->path, $type); |
|
350 | - } |
|
351 | - |
|
352 | - public function getFileInfo() { |
|
353 | - return $this->info; |
|
354 | - } |
|
279 | + if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
280 | + $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE); |
|
281 | + } |
|
282 | + |
|
283 | + return $permissions; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * @return string |
|
288 | + */ |
|
289 | + public function getDavPermissions() { |
|
290 | + $p = ''; |
|
291 | + if ($this->info->isShared()) { |
|
292 | + $p .= 'S'; |
|
293 | + } |
|
294 | + if ($this->info->isShareable()) { |
|
295 | + $p .= 'R'; |
|
296 | + } |
|
297 | + if ($this->info->isMounted()) { |
|
298 | + $p .= 'M'; |
|
299 | + } |
|
300 | + if ($this->info->isDeletable()) { |
|
301 | + $p .= 'D'; |
|
302 | + } |
|
303 | + if ($this->info->isUpdateable()) { |
|
304 | + $p .= 'NV'; // Renameable, Moveable |
|
305 | + } |
|
306 | + if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
307 | + if ($this->info->isUpdateable()) { |
|
308 | + $p .= 'W'; |
|
309 | + } |
|
310 | + } else { |
|
311 | + if ($this->info->isCreatable()) { |
|
312 | + $p .= 'CK'; |
|
313 | + } |
|
314 | + } |
|
315 | + return $p; |
|
316 | + } |
|
317 | + |
|
318 | + public function getOwner() { |
|
319 | + return $this->info->getOwner(); |
|
320 | + } |
|
321 | + |
|
322 | + protected function verifyPath() { |
|
323 | + try { |
|
324 | + $fileName = basename($this->info->getPath()); |
|
325 | + $this->fileView->verifyPath($this->path, $fileName); |
|
326 | + } catch (\OCP\Files\InvalidPathException $ex) { |
|
327 | + throw new InvalidPath($ex->getMessage()); |
|
328 | + } |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
333 | + */ |
|
334 | + public function acquireLock($type) { |
|
335 | + $this->fileView->lockFile($this->path, $type); |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
340 | + */ |
|
341 | + public function releaseLock($type) { |
|
342 | + $this->fileView->unlockFile($this->path, $type); |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
347 | + */ |
|
348 | + public function changeLock($type) { |
|
349 | + $this->fileView->changeLock($this->path, $type); |
|
350 | + } |
|
351 | + |
|
352 | + public function getFileInfo() { |
|
353 | + return $this->info; |
|
354 | + } |
|
355 | 355 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | // verify path of the target |
131 | 131 | $this->verifyPath(); |
132 | 132 | |
133 | - $newPath = $parentPath . '/' . $newName; |
|
133 | + $newPath = $parentPath.'/'.$newName; |
|
134 | 134 | |
135 | 135 | $this->fileView->rename($this->path, $newPath); |
136 | 136 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | public function getLastModified() { |
152 | 152 | $timestamp = $this->info->getMtime(); |
153 | 153 | if (!empty($timestamp)) { |
154 | - return (int)$timestamp; |
|
154 | + return (int) $timestamp; |
|
155 | 155 | } |
156 | 156 | return $timestamp; |
157 | 157 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @return string |
179 | 179 | */ |
180 | 180 | public function getETag() { |
181 | - return '"' . $this->info->getEtag() . '"'; |
|
181 | + return '"'.$this->info->getEtag().'"'; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | if ($this->info->getId()) { |
218 | 218 | $instanceId = \OC_Util::getInstanceId(); |
219 | 219 | $id = sprintf('%08d', $this->info->getId()); |
220 | - return $id . $instanceId; |
|
220 | + return $id.$instanceId; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | return null; |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | |
253 | 253 | if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
254 | 254 | /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
255 | - $permissions = (int)$storage->getShare()->getPermissions(); |
|
255 | + $permissions = (int) $storage->getShare()->getPermissions(); |
|
256 | 256 | } else { |
257 | 257 | $permissions = $storage->getPermissions($path); |
258 | 258 | } |
@@ -40,114 +40,114 @@ |
||
40 | 40 | */ |
41 | 41 | class QuotaPlugin extends \Sabre\DAV\ServerPlugin { |
42 | 42 | |
43 | - /** |
|
44 | - * @var \OC\Files\View |
|
45 | - */ |
|
46 | - private $view; |
|
43 | + /** |
|
44 | + * @var \OC\Files\View |
|
45 | + */ |
|
46 | + private $view; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Reference to main server object |
|
50 | - * |
|
51 | - * @var \Sabre\DAV\Server |
|
52 | - */ |
|
53 | - private $server; |
|
48 | + /** |
|
49 | + * Reference to main server object |
|
50 | + * |
|
51 | + * @var \Sabre\DAV\Server |
|
52 | + */ |
|
53 | + private $server; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param \OC\Files\View $view |
|
57 | - */ |
|
58 | - public function __construct($view) { |
|
59 | - $this->view = $view; |
|
60 | - } |
|
55 | + /** |
|
56 | + * @param \OC\Files\View $view |
|
57 | + */ |
|
58 | + public function __construct($view) { |
|
59 | + $this->view = $view; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * This initializes the plugin. |
|
64 | - * |
|
65 | - * This function is called by \Sabre\DAV\Server, after |
|
66 | - * addPlugin is called. |
|
67 | - * |
|
68 | - * This method should set up the requires event subscriptions. |
|
69 | - * |
|
70 | - * @param \Sabre\DAV\Server $server |
|
71 | - * @return void |
|
72 | - */ |
|
73 | - public function initialize(\Sabre\DAV\Server $server) { |
|
62 | + /** |
|
63 | + * This initializes the plugin. |
|
64 | + * |
|
65 | + * This function is called by \Sabre\DAV\Server, after |
|
66 | + * addPlugin is called. |
|
67 | + * |
|
68 | + * This method should set up the requires event subscriptions. |
|
69 | + * |
|
70 | + * @param \Sabre\DAV\Server $server |
|
71 | + * @return void |
|
72 | + */ |
|
73 | + public function initialize(\Sabre\DAV\Server $server) { |
|
74 | 74 | |
75 | - $this->server = $server; |
|
75 | + $this->server = $server; |
|
76 | 76 | |
77 | - $server->on('beforeWriteContent', array($this, 'checkQuota'), 10); |
|
78 | - $server->on('beforeCreateFile', array($this, 'checkQuota'), 10); |
|
79 | - } |
|
77 | + $server->on('beforeWriteContent', array($this, 'checkQuota'), 10); |
|
78 | + $server->on('beforeCreateFile', array($this, 'checkQuota'), 10); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * This method is called before any HTTP method and validates there is enough free space to store the file |
|
83 | - * |
|
84 | - * @param string $uri |
|
85 | - * @throws InsufficientStorage |
|
86 | - * @return bool |
|
87 | - */ |
|
88 | - public function checkQuota($uri) { |
|
89 | - $length = $this->getLength(); |
|
90 | - if ($length) { |
|
91 | - if (substr($uri, 0, 1) !== '/') { |
|
92 | - $uri = '/' . $uri; |
|
93 | - } |
|
94 | - list($parentUri, $newName) = URLUtil::splitPath($uri); |
|
95 | - if(is_null($parentUri)) { |
|
96 | - $parentUri = ''; |
|
97 | - } |
|
98 | - $req = $this->server->httpRequest; |
|
99 | - if ($req->getHeader('OC-Chunked')) { |
|
100 | - $info = \OC_FileChunking::decodeName($newName); |
|
101 | - $chunkHandler = $this->getFileChunking($info); |
|
102 | - // subtract the already uploaded size to see whether |
|
103 | - // there is still enough space for the remaining chunks |
|
104 | - $length -= $chunkHandler->getCurrentSize(); |
|
105 | - // use target file name for free space check in case of shared files |
|
106 | - $uri = rtrim($parentUri, '/') . '/' . $info['name']; |
|
107 | - } |
|
108 | - $freeSpace = $this->getFreeSpace($uri); |
|
109 | - if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $length > $freeSpace) { |
|
110 | - if (isset($chunkHandler)) { |
|
111 | - $chunkHandler->cleanup(); |
|
112 | - } |
|
113 | - throw new InsufficientStorage(); |
|
114 | - } |
|
115 | - } |
|
116 | - return true; |
|
117 | - } |
|
81 | + /** |
|
82 | + * This method is called before any HTTP method and validates there is enough free space to store the file |
|
83 | + * |
|
84 | + * @param string $uri |
|
85 | + * @throws InsufficientStorage |
|
86 | + * @return bool |
|
87 | + */ |
|
88 | + public function checkQuota($uri) { |
|
89 | + $length = $this->getLength(); |
|
90 | + if ($length) { |
|
91 | + if (substr($uri, 0, 1) !== '/') { |
|
92 | + $uri = '/' . $uri; |
|
93 | + } |
|
94 | + list($parentUri, $newName) = URLUtil::splitPath($uri); |
|
95 | + if(is_null($parentUri)) { |
|
96 | + $parentUri = ''; |
|
97 | + } |
|
98 | + $req = $this->server->httpRequest; |
|
99 | + if ($req->getHeader('OC-Chunked')) { |
|
100 | + $info = \OC_FileChunking::decodeName($newName); |
|
101 | + $chunkHandler = $this->getFileChunking($info); |
|
102 | + // subtract the already uploaded size to see whether |
|
103 | + // there is still enough space for the remaining chunks |
|
104 | + $length -= $chunkHandler->getCurrentSize(); |
|
105 | + // use target file name for free space check in case of shared files |
|
106 | + $uri = rtrim($parentUri, '/') . '/' . $info['name']; |
|
107 | + } |
|
108 | + $freeSpace = $this->getFreeSpace($uri); |
|
109 | + if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $length > $freeSpace) { |
|
110 | + if (isset($chunkHandler)) { |
|
111 | + $chunkHandler->cleanup(); |
|
112 | + } |
|
113 | + throw new InsufficientStorage(); |
|
114 | + } |
|
115 | + } |
|
116 | + return true; |
|
117 | + } |
|
118 | 118 | |
119 | - public function getFileChunking($info) { |
|
120 | - // FIXME: need a factory for better mocking support |
|
121 | - return new \OC_FileChunking($info); |
|
122 | - } |
|
119 | + public function getFileChunking($info) { |
|
120 | + // FIXME: need a factory for better mocking support |
|
121 | + return new \OC_FileChunking($info); |
|
122 | + } |
|
123 | 123 | |
124 | - public function getLength() { |
|
125 | - $req = $this->server->httpRequest; |
|
126 | - $length = $req->getHeader('X-Expected-Entity-Length'); |
|
127 | - if (!is_numeric($length)) { |
|
128 | - $length = $req->getHeader('Content-Length'); |
|
129 | - $length = is_numeric($length) ? $length : null; |
|
130 | - } |
|
124 | + public function getLength() { |
|
125 | + $req = $this->server->httpRequest; |
|
126 | + $length = $req->getHeader('X-Expected-Entity-Length'); |
|
127 | + if (!is_numeric($length)) { |
|
128 | + $length = $req->getHeader('Content-Length'); |
|
129 | + $length = is_numeric($length) ? $length : null; |
|
130 | + } |
|
131 | 131 | |
132 | - $ocLength = $req->getHeader('OC-Total-Length'); |
|
133 | - if (is_numeric($length) && is_numeric($ocLength)) { |
|
134 | - return max($length, $ocLength); |
|
135 | - } |
|
132 | + $ocLength = $req->getHeader('OC-Total-Length'); |
|
133 | + if (is_numeric($length) && is_numeric($ocLength)) { |
|
134 | + return max($length, $ocLength); |
|
135 | + } |
|
136 | 136 | |
137 | - return $length; |
|
138 | - } |
|
137 | + return $length; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @param string $uri |
|
142 | - * @return mixed |
|
143 | - * @throws ServiceUnavailable |
|
144 | - */ |
|
145 | - public function getFreeSpace($uri) { |
|
146 | - try { |
|
147 | - $freeSpace = $this->view->free_space(ltrim($uri, '/')); |
|
148 | - return $freeSpace; |
|
149 | - } catch (StorageNotAvailableException $e) { |
|
150 | - throw new ServiceUnavailable($e->getMessage()); |
|
151 | - } |
|
152 | - } |
|
140 | + /** |
|
141 | + * @param string $uri |
|
142 | + * @return mixed |
|
143 | + * @throws ServiceUnavailable |
|
144 | + */ |
|
145 | + public function getFreeSpace($uri) { |
|
146 | + try { |
|
147 | + $freeSpace = $this->view->free_space(ltrim($uri, '/')); |
|
148 | + return $freeSpace; |
|
149 | + } catch (StorageNotAvailableException $e) { |
|
150 | + throw new ServiceUnavailable($e->getMessage()); |
|
151 | + } |
|
152 | + } |
|
153 | 153 | } |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | $length = $this->getLength(); |
90 | 90 | if ($length) { |
91 | 91 | if (substr($uri, 0, 1) !== '/') { |
92 | - $uri = '/' . $uri; |
|
92 | + $uri = '/'.$uri; |
|
93 | 93 | } |
94 | 94 | list($parentUri, $newName) = URLUtil::splitPath($uri); |
95 | - if(is_null($parentUri)) { |
|
95 | + if (is_null($parentUri)) { |
|
96 | 96 | $parentUri = ''; |
97 | 97 | } |
98 | 98 | $req = $this->server->httpRequest; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | // there is still enough space for the remaining chunks |
104 | 104 | $length -= $chunkHandler->getCurrentSize(); |
105 | 105 | // use target file name for free space check in case of shared files |
106 | - $uri = rtrim($parentUri, '/') . '/' . $info['name']; |
|
106 | + $uri = rtrim($parentUri, '/').'/'.$info['name']; |
|
107 | 107 | } |
108 | 108 | $freeSpace = $this->getFreeSpace($uri); |
109 | 109 | if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $length > $freeSpace) { |