@@ -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 | } |
@@ -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, |
@@ -43,158 +43,158 @@ |
||
43 | 43 | use Sabre\DAV\Auth\Plugin; |
44 | 44 | |
45 | 45 | class ServerFactory { |
46 | - /** @var IConfig */ |
|
47 | - private $config; |
|
48 | - /** @var ILogger */ |
|
49 | - private $logger; |
|
50 | - /** @var IDBConnection */ |
|
51 | - private $databaseConnection; |
|
52 | - /** @var IUserSession */ |
|
53 | - private $userSession; |
|
54 | - /** @var IMountManager */ |
|
55 | - private $mountManager; |
|
56 | - /** @var ITagManager */ |
|
57 | - private $tagManager; |
|
58 | - /** @var IRequest */ |
|
59 | - private $request; |
|
60 | - /** @var IPreview */ |
|
61 | - private $previewManager; |
|
46 | + /** @var IConfig */ |
|
47 | + private $config; |
|
48 | + /** @var ILogger */ |
|
49 | + private $logger; |
|
50 | + /** @var IDBConnection */ |
|
51 | + private $databaseConnection; |
|
52 | + /** @var IUserSession */ |
|
53 | + private $userSession; |
|
54 | + /** @var IMountManager */ |
|
55 | + private $mountManager; |
|
56 | + /** @var ITagManager */ |
|
57 | + private $tagManager; |
|
58 | + /** @var IRequest */ |
|
59 | + private $request; |
|
60 | + /** @var IPreview */ |
|
61 | + private $previewManager; |
|
62 | 62 | |
63 | - /** |
|
64 | - * @param IConfig $config |
|
65 | - * @param ILogger $logger |
|
66 | - * @param IDBConnection $databaseConnection |
|
67 | - * @param IUserSession $userSession |
|
68 | - * @param IMountManager $mountManager |
|
69 | - * @param ITagManager $tagManager |
|
70 | - * @param IRequest $request |
|
71 | - * @param IPreview $previewManager |
|
72 | - */ |
|
73 | - public function __construct( |
|
74 | - IConfig $config, |
|
75 | - ILogger $logger, |
|
76 | - IDBConnection $databaseConnection, |
|
77 | - IUserSession $userSession, |
|
78 | - IMountManager $mountManager, |
|
79 | - ITagManager $tagManager, |
|
80 | - IRequest $request, |
|
81 | - IPreview $previewManager |
|
82 | - ) { |
|
83 | - $this->config = $config; |
|
84 | - $this->logger = $logger; |
|
85 | - $this->databaseConnection = $databaseConnection; |
|
86 | - $this->userSession = $userSession; |
|
87 | - $this->mountManager = $mountManager; |
|
88 | - $this->tagManager = $tagManager; |
|
89 | - $this->request = $request; |
|
90 | - $this->previewManager = $previewManager; |
|
91 | - } |
|
63 | + /** |
|
64 | + * @param IConfig $config |
|
65 | + * @param ILogger $logger |
|
66 | + * @param IDBConnection $databaseConnection |
|
67 | + * @param IUserSession $userSession |
|
68 | + * @param IMountManager $mountManager |
|
69 | + * @param ITagManager $tagManager |
|
70 | + * @param IRequest $request |
|
71 | + * @param IPreview $previewManager |
|
72 | + */ |
|
73 | + public function __construct( |
|
74 | + IConfig $config, |
|
75 | + ILogger $logger, |
|
76 | + IDBConnection $databaseConnection, |
|
77 | + IUserSession $userSession, |
|
78 | + IMountManager $mountManager, |
|
79 | + ITagManager $tagManager, |
|
80 | + IRequest $request, |
|
81 | + IPreview $previewManager |
|
82 | + ) { |
|
83 | + $this->config = $config; |
|
84 | + $this->logger = $logger; |
|
85 | + $this->databaseConnection = $databaseConnection; |
|
86 | + $this->userSession = $userSession; |
|
87 | + $this->mountManager = $mountManager; |
|
88 | + $this->tagManager = $tagManager; |
|
89 | + $this->request = $request; |
|
90 | + $this->previewManager = $previewManager; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @param string $baseUri |
|
95 | - * @param string $requestUri |
|
96 | - * @param Plugin $authPlugin |
|
97 | - * @param callable $viewCallBack callback that should return the view for the dav endpoint |
|
98 | - * @return Server |
|
99 | - */ |
|
100 | - public function createServer($baseUri, |
|
101 | - $requestUri, |
|
102 | - Plugin $authPlugin, |
|
103 | - callable $viewCallBack) { |
|
104 | - // Fire up server |
|
105 | - $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); |
|
106 | - $server = new \OCA\DAV\Connector\Sabre\Server($objectTree); |
|
107 | - // Set URL explicitly due to reverse-proxy situations |
|
108 | - $server->httpRequest->setUrl($requestUri); |
|
109 | - $server->setBaseUri($baseUri); |
|
93 | + /** |
|
94 | + * @param string $baseUri |
|
95 | + * @param string $requestUri |
|
96 | + * @param Plugin $authPlugin |
|
97 | + * @param callable $viewCallBack callback that should return the view for the dav endpoint |
|
98 | + * @return Server |
|
99 | + */ |
|
100 | + public function createServer($baseUri, |
|
101 | + $requestUri, |
|
102 | + Plugin $authPlugin, |
|
103 | + callable $viewCallBack) { |
|
104 | + // Fire up server |
|
105 | + $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); |
|
106 | + $server = new \OCA\DAV\Connector\Sabre\Server($objectTree); |
|
107 | + // Set URL explicitly due to reverse-proxy situations |
|
108 | + $server->httpRequest->setUrl($requestUri); |
|
109 | + $server->setBaseUri($baseUri); |
|
110 | 110 | |
111 | - // Load plugins |
|
112 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
|
113 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); |
|
114 | - $server->addPlugin($authPlugin); |
|
115 | - // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to / |
|
116 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); |
|
117 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); |
|
118 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
119 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
120 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
121 | - if($this->request->isUserAgent([ |
|
122 | - '/WebDAVFS/', |
|
123 | - '/Microsoft Office OneNote 2013/', |
|
124 | - '/Microsoft-WebDAV-MiniRedir/', |
|
125 | - ])) { |
|
126 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); |
|
127 | - } |
|
111 | + // Load plugins |
|
112 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
|
113 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); |
|
114 | + $server->addPlugin($authPlugin); |
|
115 | + // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to / |
|
116 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); |
|
117 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); |
|
118 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
119 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
120 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
121 | + if($this->request->isUserAgent([ |
|
122 | + '/WebDAVFS/', |
|
123 | + '/Microsoft Office OneNote 2013/', |
|
124 | + '/Microsoft-WebDAV-MiniRedir/', |
|
125 | + ])) { |
|
126 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); |
|
127 | + } |
|
128 | 128 | |
129 | - if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) { |
|
130 | - $server->addPlugin(new BrowserErrorPagePlugin()); |
|
131 | - } |
|
129 | + if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) { |
|
130 | + $server->addPlugin(new BrowserErrorPagePlugin()); |
|
131 | + } |
|
132 | 132 | |
133 | - // wait with registering these until auth is handled and the filesystem is setup |
|
134 | - $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { |
|
135 | - // ensure the skeleton is copied |
|
136 | - $userFolder = \OC::$server->getUserFolder(); |
|
133 | + // wait with registering these until auth is handled and the filesystem is setup |
|
134 | + $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { |
|
135 | + // ensure the skeleton is copied |
|
136 | + $userFolder = \OC::$server->getUserFolder(); |
|
137 | 137 | |
138 | - /** @var \OC\Files\View $view */ |
|
139 | - $view = $viewCallBack($server); |
|
140 | - if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { |
|
141 | - $rootInfo = $userFolder; |
|
142 | - } else { |
|
143 | - $rootInfo = $view->getFileInfo(''); |
|
144 | - } |
|
138 | + /** @var \OC\Files\View $view */ |
|
139 | + $view = $viewCallBack($server); |
|
140 | + if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { |
|
141 | + $rootInfo = $userFolder; |
|
142 | + } else { |
|
143 | + $rootInfo = $view->getFileInfo(''); |
|
144 | + } |
|
145 | 145 | |
146 | - // Create Nextcloud Dir |
|
147 | - if ($rootInfo->getType() === 'dir') { |
|
148 | - $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree); |
|
149 | - } else { |
|
150 | - $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo); |
|
151 | - } |
|
152 | - $objectTree->init($root, $view, $this->mountManager); |
|
146 | + // Create Nextcloud Dir |
|
147 | + if ($rootInfo->getType() === 'dir') { |
|
148 | + $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree); |
|
149 | + } else { |
|
150 | + $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo); |
|
151 | + } |
|
152 | + $objectTree->init($root, $view, $this->mountManager); |
|
153 | 153 | |
154 | - $server->addPlugin( |
|
155 | - new \OCA\DAV\Connector\Sabre\FilesPlugin( |
|
156 | - $objectTree, |
|
157 | - $this->config, |
|
158 | - $this->request, |
|
159 | - $this->previewManager, |
|
160 | - false, |
|
161 | - !$this->config->getSystemValue('debug', false) |
|
162 | - ) |
|
163 | - ); |
|
164 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view)); |
|
154 | + $server->addPlugin( |
|
155 | + new \OCA\DAV\Connector\Sabre\FilesPlugin( |
|
156 | + $objectTree, |
|
157 | + $this->config, |
|
158 | + $this->request, |
|
159 | + $this->previewManager, |
|
160 | + false, |
|
161 | + !$this->config->getSystemValue('debug', false) |
|
162 | + ) |
|
163 | + ); |
|
164 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view)); |
|
165 | 165 | |
166 | - if($this->userSession->isLoggedIn()) { |
|
167 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
|
168 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
|
169 | - $objectTree, |
|
170 | - $this->userSession, |
|
171 | - $userFolder, |
|
172 | - \OC::$server->getShareManager() |
|
173 | - )); |
|
174 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession)); |
|
175 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin( |
|
176 | - $objectTree, |
|
177 | - $view, |
|
178 | - \OC::$server->getSystemTagManager(), |
|
179 | - \OC::$server->getSystemTagObjectMapper(), |
|
180 | - \OC::$server->getTagManager(), |
|
181 | - $this->userSession, |
|
182 | - \OC::$server->getGroupManager(), |
|
183 | - $userFolder |
|
184 | - )); |
|
185 | - // custom properties plugin must be the last one |
|
186 | - $server->addPlugin( |
|
187 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
188 | - new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend( |
|
189 | - $objectTree, |
|
190 | - $this->databaseConnection, |
|
191 | - $this->userSession->getUser() |
|
192 | - ) |
|
193 | - ) |
|
194 | - ); |
|
195 | - } |
|
196 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin()); |
|
197 | - }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request |
|
198 | - return $server; |
|
199 | - } |
|
166 | + if($this->userSession->isLoggedIn()) { |
|
167 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
|
168 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
|
169 | + $objectTree, |
|
170 | + $this->userSession, |
|
171 | + $userFolder, |
|
172 | + \OC::$server->getShareManager() |
|
173 | + )); |
|
174 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession)); |
|
175 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin( |
|
176 | + $objectTree, |
|
177 | + $view, |
|
178 | + \OC::$server->getSystemTagManager(), |
|
179 | + \OC::$server->getSystemTagObjectMapper(), |
|
180 | + \OC::$server->getTagManager(), |
|
181 | + $this->userSession, |
|
182 | + \OC::$server->getGroupManager(), |
|
183 | + $userFolder |
|
184 | + )); |
|
185 | + // custom properties plugin must be the last one |
|
186 | + $server->addPlugin( |
|
187 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
188 | + new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend( |
|
189 | + $objectTree, |
|
190 | + $this->databaseConnection, |
|
191 | + $this->userSession->getUser() |
|
192 | + ) |
|
193 | + ) |
|
194 | + ); |
|
195 | + } |
|
196 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin()); |
|
197 | + }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request |
|
198 | + return $server; |
|
199 | + } |
|
200 | 200 | } |
@@ -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 | } |
@@ -43,315 +43,315 @@ |
||
43 | 43 | |
44 | 44 | abstract class Node implements \Sabre\DAV\INode { |
45 | 45 | |
46 | - /** |
|
47 | - * @var \OC\Files\View |
|
48 | - */ |
|
49 | - protected $fileView; |
|
50 | - |
|
51 | - /** |
|
52 | - * The path to the current node |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - protected $path; |
|
57 | - |
|
58 | - /** |
|
59 | - * node properties cache |
|
60 | - * |
|
61 | - * @var array |
|
62 | - */ |
|
63 | - protected $property_cache = null; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var \OCP\Files\FileInfo |
|
67 | - */ |
|
68 | - protected $info; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var IManager |
|
72 | - */ |
|
73 | - protected $shareManager; |
|
74 | - |
|
75 | - /** |
|
76 | - * Sets up the node, expects a full path name |
|
77 | - * |
|
78 | - * @param \OC\Files\View $view |
|
79 | - * @param \OCP\Files\FileInfo $info |
|
80 | - * @param IManager $shareManager |
|
81 | - */ |
|
82 | - public function __construct(View $view, FileInfo $info, IManager $shareManager = null) { |
|
83 | - $this->fileView = $view; |
|
84 | - $this->path = $this->fileView->getRelativePath($info->getPath()); |
|
85 | - $this->info = $info; |
|
86 | - if ($shareManager) { |
|
87 | - $this->shareManager = $shareManager; |
|
88 | - } else { |
|
89 | - $this->shareManager = \OC::$server->getShareManager(); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - protected function refreshInfo() { |
|
94 | - $this->info = $this->fileView->getFileInfo($this->path); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Returns the name of the node |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function getName() { |
|
103 | - return $this->info->getName(); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Returns the full path |
|
108 | - * |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - public function getPath() { |
|
112 | - return $this->path; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Renames the node |
|
117 | - * |
|
118 | - * @param string $name The new name |
|
119 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
120 | - * @throws \Sabre\DAV\Exception\Forbidden |
|
121 | - */ |
|
122 | - public function setName($name) { |
|
123 | - |
|
124 | - // rename is only allowed if the update privilege is granted |
|
125 | - if (!$this->info->isUpdateable()) { |
|
126 | - throw new \Sabre\DAV\Exception\Forbidden(); |
|
127 | - } |
|
128 | - |
|
129 | - list($parentPath,) = \Sabre\HTTP\URLUtil::splitPath($this->path); |
|
130 | - list(, $newName) = \Sabre\HTTP\URLUtil::splitPath($name); |
|
131 | - |
|
132 | - // verify path of the target |
|
133 | - $this->verifyPath(); |
|
134 | - |
|
135 | - $newPath = $parentPath . '/' . $newName; |
|
136 | - |
|
137 | - $this->fileView->rename($this->path, $newPath); |
|
138 | - |
|
139 | - $this->path = $newPath; |
|
140 | - |
|
141 | - $this->refreshInfo(); |
|
142 | - } |
|
143 | - |
|
144 | - public function setPropertyCache($property_cache) { |
|
145 | - $this->property_cache = $property_cache; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Returns the last modification time, as a unix timestamp |
|
150 | - * |
|
151 | - * @return int timestamp as integer |
|
152 | - */ |
|
153 | - public function getLastModified() { |
|
154 | - $timestamp = $this->info->getMtime(); |
|
155 | - if (!empty($timestamp)) { |
|
156 | - return (int)$timestamp; |
|
157 | - } |
|
158 | - return $timestamp; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * sets the last modification time of the file (mtime) to the value given |
|
163 | - * in the second parameter or to now if the second param is empty. |
|
164 | - * Even if the modification time is set to a custom value the access time is set to now. |
|
165 | - */ |
|
166 | - public function touch($mtime) { |
|
167 | - $this->fileView->touch($this->path, $mtime); |
|
168 | - $this->refreshInfo(); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Returns the ETag for a file |
|
173 | - * |
|
174 | - * An ETag is a unique identifier representing the current version of the |
|
175 | - * file. If the file changes, the ETag MUST change. The ETag is an |
|
176 | - * arbitrary string, but MUST be surrounded by double-quotes. |
|
177 | - * |
|
178 | - * Return null if the ETag can not effectively be determined |
|
179 | - * |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function getETag() { |
|
183 | - return '"' . $this->info->getEtag() . '"'; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Sets the ETag |
|
188 | - * |
|
189 | - * @param string $etag |
|
190 | - * |
|
191 | - * @return int file id of updated file or -1 on failure |
|
192 | - */ |
|
193 | - public function setETag($etag) { |
|
194 | - return $this->fileView->putFileInfo($this->path, array('etag' => $etag)); |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Returns the size of the node, in bytes |
|
199 | - * |
|
200 | - * @return integer |
|
201 | - */ |
|
202 | - public function getSize() { |
|
203 | - return $this->info->getSize(); |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Returns the cache's file id |
|
208 | - * |
|
209 | - * @return int |
|
210 | - */ |
|
211 | - public function getId() { |
|
212 | - return $this->info->getId(); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @return string|null |
|
217 | - */ |
|
218 | - public function getFileId() { |
|
219 | - if ($this->info->getId()) { |
|
220 | - $instanceId = \OC_Util::getInstanceId(); |
|
221 | - $id = sprintf('%08d', $this->info->getId()); |
|
222 | - return $id . $instanceId; |
|
223 | - } |
|
224 | - |
|
225 | - return null; |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * @return integer |
|
230 | - */ |
|
231 | - public function getInternalFileId() { |
|
232 | - return $this->info->getId(); |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * @param string $user |
|
237 | - * @return int |
|
238 | - */ |
|
239 | - public function getSharePermissions($user) { |
|
240 | - |
|
241 | - // check of we access a federated share |
|
242 | - if ($user !== null) { |
|
243 | - try { |
|
244 | - $share = $this->shareManager->getShareByToken($user); |
|
245 | - return $share->getPermissions(); |
|
246 | - } catch (ShareNotFound $e) { |
|
247 | - // ignore |
|
248 | - } |
|
249 | - } |
|
250 | - |
|
251 | - $storage = $this->info->getStorage(); |
|
252 | - |
|
253 | - $path = $this->info->getInternalPath(); |
|
254 | - |
|
255 | - if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
256 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
257 | - $permissions = (int)$storage->getShare()->getPermissions(); |
|
258 | - } else { |
|
259 | - $permissions = $storage->getPermissions($path); |
|
260 | - } |
|
261 | - |
|
262 | - /* |
|
46 | + /** |
|
47 | + * @var \OC\Files\View |
|
48 | + */ |
|
49 | + protected $fileView; |
|
50 | + |
|
51 | + /** |
|
52 | + * The path to the current node |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + protected $path; |
|
57 | + |
|
58 | + /** |
|
59 | + * node properties cache |
|
60 | + * |
|
61 | + * @var array |
|
62 | + */ |
|
63 | + protected $property_cache = null; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var \OCP\Files\FileInfo |
|
67 | + */ |
|
68 | + protected $info; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var IManager |
|
72 | + */ |
|
73 | + protected $shareManager; |
|
74 | + |
|
75 | + /** |
|
76 | + * Sets up the node, expects a full path name |
|
77 | + * |
|
78 | + * @param \OC\Files\View $view |
|
79 | + * @param \OCP\Files\FileInfo $info |
|
80 | + * @param IManager $shareManager |
|
81 | + */ |
|
82 | + public function __construct(View $view, FileInfo $info, IManager $shareManager = null) { |
|
83 | + $this->fileView = $view; |
|
84 | + $this->path = $this->fileView->getRelativePath($info->getPath()); |
|
85 | + $this->info = $info; |
|
86 | + if ($shareManager) { |
|
87 | + $this->shareManager = $shareManager; |
|
88 | + } else { |
|
89 | + $this->shareManager = \OC::$server->getShareManager(); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + protected function refreshInfo() { |
|
94 | + $this->info = $this->fileView->getFileInfo($this->path); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Returns the name of the node |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function getName() { |
|
103 | + return $this->info->getName(); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Returns the full path |
|
108 | + * |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + public function getPath() { |
|
112 | + return $this->path; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Renames the node |
|
117 | + * |
|
118 | + * @param string $name The new name |
|
119 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
120 | + * @throws \Sabre\DAV\Exception\Forbidden |
|
121 | + */ |
|
122 | + public function setName($name) { |
|
123 | + |
|
124 | + // rename is only allowed if the update privilege is granted |
|
125 | + if (!$this->info->isUpdateable()) { |
|
126 | + throw new \Sabre\DAV\Exception\Forbidden(); |
|
127 | + } |
|
128 | + |
|
129 | + list($parentPath,) = \Sabre\HTTP\URLUtil::splitPath($this->path); |
|
130 | + list(, $newName) = \Sabre\HTTP\URLUtil::splitPath($name); |
|
131 | + |
|
132 | + // verify path of the target |
|
133 | + $this->verifyPath(); |
|
134 | + |
|
135 | + $newPath = $parentPath . '/' . $newName; |
|
136 | + |
|
137 | + $this->fileView->rename($this->path, $newPath); |
|
138 | + |
|
139 | + $this->path = $newPath; |
|
140 | + |
|
141 | + $this->refreshInfo(); |
|
142 | + } |
|
143 | + |
|
144 | + public function setPropertyCache($property_cache) { |
|
145 | + $this->property_cache = $property_cache; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Returns the last modification time, as a unix timestamp |
|
150 | + * |
|
151 | + * @return int timestamp as integer |
|
152 | + */ |
|
153 | + public function getLastModified() { |
|
154 | + $timestamp = $this->info->getMtime(); |
|
155 | + if (!empty($timestamp)) { |
|
156 | + return (int)$timestamp; |
|
157 | + } |
|
158 | + return $timestamp; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * sets the last modification time of the file (mtime) to the value given |
|
163 | + * in the second parameter or to now if the second param is empty. |
|
164 | + * Even if the modification time is set to a custom value the access time is set to now. |
|
165 | + */ |
|
166 | + public function touch($mtime) { |
|
167 | + $this->fileView->touch($this->path, $mtime); |
|
168 | + $this->refreshInfo(); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Returns the ETag for a file |
|
173 | + * |
|
174 | + * An ETag is a unique identifier representing the current version of the |
|
175 | + * file. If the file changes, the ETag MUST change. The ETag is an |
|
176 | + * arbitrary string, but MUST be surrounded by double-quotes. |
|
177 | + * |
|
178 | + * Return null if the ETag can not effectively be determined |
|
179 | + * |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function getETag() { |
|
183 | + return '"' . $this->info->getEtag() . '"'; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Sets the ETag |
|
188 | + * |
|
189 | + * @param string $etag |
|
190 | + * |
|
191 | + * @return int file id of updated file or -1 on failure |
|
192 | + */ |
|
193 | + public function setETag($etag) { |
|
194 | + return $this->fileView->putFileInfo($this->path, array('etag' => $etag)); |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Returns the size of the node, in bytes |
|
199 | + * |
|
200 | + * @return integer |
|
201 | + */ |
|
202 | + public function getSize() { |
|
203 | + return $this->info->getSize(); |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Returns the cache's file id |
|
208 | + * |
|
209 | + * @return int |
|
210 | + */ |
|
211 | + public function getId() { |
|
212 | + return $this->info->getId(); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @return string|null |
|
217 | + */ |
|
218 | + public function getFileId() { |
|
219 | + if ($this->info->getId()) { |
|
220 | + $instanceId = \OC_Util::getInstanceId(); |
|
221 | + $id = sprintf('%08d', $this->info->getId()); |
|
222 | + return $id . $instanceId; |
|
223 | + } |
|
224 | + |
|
225 | + return null; |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * @return integer |
|
230 | + */ |
|
231 | + public function getInternalFileId() { |
|
232 | + return $this->info->getId(); |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * @param string $user |
|
237 | + * @return int |
|
238 | + */ |
|
239 | + public function getSharePermissions($user) { |
|
240 | + |
|
241 | + // check of we access a federated share |
|
242 | + if ($user !== null) { |
|
243 | + try { |
|
244 | + $share = $this->shareManager->getShareByToken($user); |
|
245 | + return $share->getPermissions(); |
|
246 | + } catch (ShareNotFound $e) { |
|
247 | + // ignore |
|
248 | + } |
|
249 | + } |
|
250 | + |
|
251 | + $storage = $this->info->getStorage(); |
|
252 | + |
|
253 | + $path = $this->info->getInternalPath(); |
|
254 | + |
|
255 | + if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
256 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
257 | + $permissions = (int)$storage->getShare()->getPermissions(); |
|
258 | + } else { |
|
259 | + $permissions = $storage->getPermissions($path); |
|
260 | + } |
|
261 | + |
|
262 | + /* |
|
263 | 263 | * We can always share non moveable mount points with DELETE and UPDATE |
264 | 264 | * Eventually we need to do this properly |
265 | 265 | */ |
266 | - $mountpoint = $this->info->getMountPoint(); |
|
267 | - if (!($mountpoint instanceof MoveableMount)) { |
|
268 | - $mountpointpath = $mountpoint->getMountPoint(); |
|
269 | - if (substr($mountpointpath, -1) === '/') { |
|
270 | - $mountpointpath = substr($mountpointpath, 0, -1); |
|
271 | - } |
|
272 | - |
|
273 | - if ($mountpointpath === $this->info->getPath()) { |
|
274 | - $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
275 | - } |
|
276 | - } |
|
277 | - |
|
278 | - /* |
|
266 | + $mountpoint = $this->info->getMountPoint(); |
|
267 | + if (!($mountpoint instanceof MoveableMount)) { |
|
268 | + $mountpointpath = $mountpoint->getMountPoint(); |
|
269 | + if (substr($mountpointpath, -1) === '/') { |
|
270 | + $mountpointpath = substr($mountpointpath, 0, -1); |
|
271 | + } |
|
272 | + |
|
273 | + if ($mountpointpath === $this->info->getPath()) { |
|
274 | + $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
275 | + } |
|
276 | + } |
|
277 | + |
|
278 | + /* |
|
279 | 279 | * Files can't have create or delete permissions |
280 | 280 | */ |
281 | - if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
282 | - $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE); |
|
283 | - } |
|
284 | - |
|
285 | - return $permissions; |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * @return string |
|
290 | - */ |
|
291 | - public function getDavPermissions() { |
|
292 | - $p = ''; |
|
293 | - if ($this->info->isShared()) { |
|
294 | - $p .= 'S'; |
|
295 | - } |
|
296 | - if ($this->info->isShareable()) { |
|
297 | - $p .= 'R'; |
|
298 | - } |
|
299 | - if ($this->info->isMounted()) { |
|
300 | - $p .= 'M'; |
|
301 | - } |
|
302 | - if ($this->info->isDeletable()) { |
|
303 | - $p .= 'D'; |
|
304 | - } |
|
305 | - if ($this->info->isUpdateable()) { |
|
306 | - $p .= 'NV'; // Renameable, Moveable |
|
307 | - } |
|
308 | - if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
309 | - if ($this->info->isUpdateable()) { |
|
310 | - $p .= 'W'; |
|
311 | - } |
|
312 | - } else { |
|
313 | - if ($this->info->isCreatable()) { |
|
314 | - $p .= 'CK'; |
|
315 | - } |
|
316 | - } |
|
317 | - return $p; |
|
318 | - } |
|
319 | - |
|
320 | - public function getOwner() { |
|
321 | - return $this->info->getOwner(); |
|
322 | - } |
|
323 | - |
|
324 | - protected function verifyPath() { |
|
325 | - try { |
|
326 | - $fileName = basename($this->info->getPath()); |
|
327 | - $this->fileView->verifyPath($this->path, $fileName); |
|
328 | - } catch (\OCP\Files\InvalidPathException $ex) { |
|
329 | - throw new InvalidPath($ex->getMessage()); |
|
330 | - } |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
335 | - */ |
|
336 | - public function acquireLock($type) { |
|
337 | - $this->fileView->lockFile($this->path, $type); |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
342 | - */ |
|
343 | - public function releaseLock($type) { |
|
344 | - $this->fileView->unlockFile($this->path, $type); |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
349 | - */ |
|
350 | - public function changeLock($type) { |
|
351 | - $this->fileView->changeLock($this->path, $type); |
|
352 | - } |
|
353 | - |
|
354 | - public function getFileInfo() { |
|
355 | - return $this->info; |
|
356 | - } |
|
281 | + if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
282 | + $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE); |
|
283 | + } |
|
284 | + |
|
285 | + return $permissions; |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * @return string |
|
290 | + */ |
|
291 | + public function getDavPermissions() { |
|
292 | + $p = ''; |
|
293 | + if ($this->info->isShared()) { |
|
294 | + $p .= 'S'; |
|
295 | + } |
|
296 | + if ($this->info->isShareable()) { |
|
297 | + $p .= 'R'; |
|
298 | + } |
|
299 | + if ($this->info->isMounted()) { |
|
300 | + $p .= 'M'; |
|
301 | + } |
|
302 | + if ($this->info->isDeletable()) { |
|
303 | + $p .= 'D'; |
|
304 | + } |
|
305 | + if ($this->info->isUpdateable()) { |
|
306 | + $p .= 'NV'; // Renameable, Moveable |
|
307 | + } |
|
308 | + if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
309 | + if ($this->info->isUpdateable()) { |
|
310 | + $p .= 'W'; |
|
311 | + } |
|
312 | + } else { |
|
313 | + if ($this->info->isCreatable()) { |
|
314 | + $p .= 'CK'; |
|
315 | + } |
|
316 | + } |
|
317 | + return $p; |
|
318 | + } |
|
319 | + |
|
320 | + public function getOwner() { |
|
321 | + return $this->info->getOwner(); |
|
322 | + } |
|
323 | + |
|
324 | + protected function verifyPath() { |
|
325 | + try { |
|
326 | + $fileName = basename($this->info->getPath()); |
|
327 | + $this->fileView->verifyPath($this->path, $fileName); |
|
328 | + } catch (\OCP\Files\InvalidPathException $ex) { |
|
329 | + throw new InvalidPath($ex->getMessage()); |
|
330 | + } |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
335 | + */ |
|
336 | + public function acquireLock($type) { |
|
337 | + $this->fileView->lockFile($this->path, $type); |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
342 | + */ |
|
343 | + public function releaseLock($type) { |
|
344 | + $this->fileView->unlockFile($this->path, $type); |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
349 | + */ |
|
350 | + public function changeLock($type) { |
|
351 | + $this->fileView->changeLock($this->path, $type); |
|
352 | + } |
|
353 | + |
|
354 | + public function getFileInfo() { |
|
355 | + return $this->info; |
|
356 | + } |
|
357 | 357 | } |
@@ -32,88 +32,88 @@ |
||
32 | 32 | use Sabre\HTTP\Response; |
33 | 33 | |
34 | 34 | class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { |
35 | - protected $nonFatalExceptions = [ |
|
36 | - 'Sabre\DAV\Exception\NotAuthenticated' => true, |
|
37 | - // If tokenauth can throw this exception (which is basically as |
|
38 | - // NotAuthenticated. So not fatal. |
|
39 | - 'OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden' => true, |
|
40 | - // the sync client uses this to find out whether files exist, |
|
41 | - // so it is not always an error, log it as debug |
|
42 | - 'Sabre\DAV\Exception\NotFound' => true, |
|
43 | - // this one mostly happens when the same file is uploaded at |
|
44 | - // exactly the same time from two clients, only one client |
|
45 | - // wins, the second one gets "Precondition failed" |
|
46 | - 'Sabre\DAV\Exception\PreconditionFailed' => true, |
|
47 | - // forbidden can be expected when trying to upload to |
|
48 | - // read-only folders for example |
|
49 | - 'Sabre\DAV\Exception\Forbidden' => true, |
|
50 | - // Happens when an external storage or federated share is temporarily |
|
51 | - // not available |
|
52 | - 'Sabre\DAV\Exception\StorageNotAvailableException' => true, |
|
53 | - ]; |
|
35 | + protected $nonFatalExceptions = [ |
|
36 | + 'Sabre\DAV\Exception\NotAuthenticated' => true, |
|
37 | + // If tokenauth can throw this exception (which is basically as |
|
38 | + // NotAuthenticated. So not fatal. |
|
39 | + 'OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden' => true, |
|
40 | + // the sync client uses this to find out whether files exist, |
|
41 | + // so it is not always an error, log it as debug |
|
42 | + 'Sabre\DAV\Exception\NotFound' => true, |
|
43 | + // this one mostly happens when the same file is uploaded at |
|
44 | + // exactly the same time from two clients, only one client |
|
45 | + // wins, the second one gets "Precondition failed" |
|
46 | + 'Sabre\DAV\Exception\PreconditionFailed' => true, |
|
47 | + // forbidden can be expected when trying to upload to |
|
48 | + // read-only folders for example |
|
49 | + 'Sabre\DAV\Exception\Forbidden' => true, |
|
50 | + // Happens when an external storage or federated share is temporarily |
|
51 | + // not available |
|
52 | + 'Sabre\DAV\Exception\StorageNotAvailableException' => true, |
|
53 | + ]; |
|
54 | 54 | |
55 | - /** @var string */ |
|
56 | - private $appName; |
|
55 | + /** @var string */ |
|
56 | + private $appName; |
|
57 | 57 | |
58 | - /** @var ILogger */ |
|
59 | - private $logger; |
|
58 | + /** @var ILogger */ |
|
59 | + private $logger; |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param string $loggerAppName app name to use when logging |
|
63 | - * @param ILogger $logger |
|
64 | - */ |
|
65 | - public function __construct($loggerAppName, $logger) { |
|
66 | - $this->appName = $loggerAppName; |
|
67 | - $this->logger = $logger; |
|
68 | - } |
|
61 | + /** |
|
62 | + * @param string $loggerAppName app name to use when logging |
|
63 | + * @param ILogger $logger |
|
64 | + */ |
|
65 | + public function __construct($loggerAppName, $logger) { |
|
66 | + $this->appName = $loggerAppName; |
|
67 | + $this->logger = $logger; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * This initializes the plugin. |
|
72 | - * |
|
73 | - * This function is called by \Sabre\DAV\Server, after |
|
74 | - * addPlugin is called. |
|
75 | - * |
|
76 | - * This method should set up the required event subscriptions. |
|
77 | - * |
|
78 | - * @param \Sabre\DAV\Server $server |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - public function initialize(\Sabre\DAV\Server $server) { |
|
70 | + /** |
|
71 | + * This initializes the plugin. |
|
72 | + * |
|
73 | + * This function is called by \Sabre\DAV\Server, after |
|
74 | + * addPlugin is called. |
|
75 | + * |
|
76 | + * This method should set up the required event subscriptions. |
|
77 | + * |
|
78 | + * @param \Sabre\DAV\Server $server |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + public function initialize(\Sabre\DAV\Server $server) { |
|
82 | 82 | |
83 | - $server->on('exception', array($this, 'logException'), 10); |
|
84 | - } |
|
83 | + $server->on('exception', array($this, 'logException'), 10); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Log exception |
|
88 | - * |
|
89 | - */ |
|
90 | - public function logException(\Exception $ex) { |
|
91 | - $exceptionClass = get_class($ex); |
|
92 | - $level = \OCP\Util::FATAL; |
|
93 | - if (isset($this->nonFatalExceptions[$exceptionClass])) { |
|
94 | - $level = \OCP\Util::DEBUG; |
|
95 | - } |
|
86 | + /** |
|
87 | + * Log exception |
|
88 | + * |
|
89 | + */ |
|
90 | + public function logException(\Exception $ex) { |
|
91 | + $exceptionClass = get_class($ex); |
|
92 | + $level = \OCP\Util::FATAL; |
|
93 | + if (isset($this->nonFatalExceptions[$exceptionClass])) { |
|
94 | + $level = \OCP\Util::DEBUG; |
|
95 | + } |
|
96 | 96 | |
97 | - $message = $ex->getMessage(); |
|
98 | - if ($ex instanceof Exception) { |
|
99 | - if (empty($message)) { |
|
100 | - $response = new Response($ex->getHTTPCode()); |
|
101 | - $message = $response->getStatusText(); |
|
102 | - } |
|
103 | - $message = "HTTP/1.1 {$ex->getHTTPCode()} $message"; |
|
104 | - } |
|
97 | + $message = $ex->getMessage(); |
|
98 | + if ($ex instanceof Exception) { |
|
99 | + if (empty($message)) { |
|
100 | + $response = new Response($ex->getHTTPCode()); |
|
101 | + $message = $response->getStatusText(); |
|
102 | + } |
|
103 | + $message = "HTTP/1.1 {$ex->getHTTPCode()} $message"; |
|
104 | + } |
|
105 | 105 | |
106 | - $user = \OC_User::getUser(); |
|
106 | + $user = \OC_User::getUser(); |
|
107 | 107 | |
108 | - $exception = [ |
|
109 | - 'Message' => $message, |
|
110 | - 'Exception' => $exceptionClass, |
|
111 | - 'Code' => $ex->getCode(), |
|
112 | - 'Trace' => $ex->getTraceAsString(), |
|
113 | - 'File' => $ex->getFile(), |
|
114 | - 'Line' => $ex->getLine(), |
|
115 | - 'User' => $user, |
|
116 | - ]; |
|
117 | - $this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]); |
|
118 | - } |
|
108 | + $exception = [ |
|
109 | + 'Message' => $message, |
|
110 | + 'Exception' => $exceptionClass, |
|
111 | + 'Code' => $ex->getCode(), |
|
112 | + 'Trace' => $ex->getTraceAsString(), |
|
113 | + 'File' => $ex->getFile(), |
|
114 | + 'Line' => $ex->getLine(), |
|
115 | + 'User' => $user, |
|
116 | + ]; |
|
117 | + $this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]); |
|
118 | + } |
|
119 | 119 | } |
@@ -114,6 +114,6 @@ |
||
114 | 114 | 'Line' => $ex->getLine(), |
115 | 115 | 'User' => $user, |
116 | 116 | ]; |
117 | - $this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]); |
|
117 | + $this->logger->log($level, 'Exception: '.json_encode($exception), ['app' => $this->appName]); |
|
118 | 118 | } |
119 | 119 | } |