@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | * @return mixed|string |
100 | 100 | */ |
101 | 101 | public function getCommentsLink(Node $node) { |
102 | - $href = $this->server->getBaseUri(); |
|
102 | + $href = $this->server->getBaseUri(); |
|
103 | 103 | $entryPoint = strpos($href, '/remote.php/'); |
104 | - if($entryPoint === false) { |
|
104 | + if ($entryPoint === false) { |
|
105 | 105 | // in case we end up somewhere else, unexpectedly. |
106 | 106 | return null; |
107 | 107 | } |
108 | - $commentsPart = 'dav/comments/files/' . rawurldecode($node->getId()); |
|
108 | + $commentsPart = 'dav/comments/files/'.rawurldecode($node->getId()); |
|
109 | 109 | $href = substr_replace($href, $commentsPart, $entryPoint + strlen('/remote.php/')); |
110 | 110 | return $href; |
111 | 111 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function getUnreadCount(Node $node) { |
121 | 121 | $user = $this->userSession->getUser(); |
122 | - if(is_null($user)) { |
|
122 | + if (is_null($user)) { |
|
123 | 123 | return null; |
124 | 124 | } |
125 | 125 |
@@ -29,132 +29,132 @@ |
||
29 | 29 | |
30 | 30 | class CommentPropertiesPlugin extends ServerPlugin { |
31 | 31 | |
32 | - const PROPERTY_NAME_HREF = '{http://owncloud.org/ns}comments-href'; |
|
33 | - const PROPERTY_NAME_COUNT = '{http://owncloud.org/ns}comments-count'; |
|
34 | - const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}comments-unread'; |
|
35 | - |
|
36 | - /** @var \Sabre\DAV\Server */ |
|
37 | - protected $server; |
|
38 | - |
|
39 | - /** @var ICommentsManager */ |
|
40 | - private $commentsManager; |
|
41 | - |
|
42 | - /** @var IUserSession */ |
|
43 | - private $userSession; |
|
44 | - |
|
45 | - private $cachedUnreadCount = []; |
|
46 | - |
|
47 | - private $cachedFolders = []; |
|
48 | - |
|
49 | - public function __construct(ICommentsManager $commentsManager, IUserSession $userSession) { |
|
50 | - $this->commentsManager = $commentsManager; |
|
51 | - $this->userSession = $userSession; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * This initializes the plugin. |
|
56 | - * |
|
57 | - * This function is called by Sabre\DAV\Server, after |
|
58 | - * addPlugin is called. |
|
59 | - * |
|
60 | - * This method should set up the required event subscriptions. |
|
61 | - * |
|
62 | - * @param \Sabre\DAV\Server $server |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - function initialize(\Sabre\DAV\Server $server) { |
|
66 | - $this->server = $server; |
|
67 | - $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Adds tags and favorites properties to the response, |
|
72 | - * if requested. |
|
73 | - * |
|
74 | - * @param PropFind $propFind |
|
75 | - * @param \Sabre\DAV\INode $node |
|
76 | - * @return void |
|
77 | - */ |
|
78 | - public function handleGetProperties( |
|
79 | - PropFind $propFind, |
|
80 | - \Sabre\DAV\INode $node |
|
81 | - ) { |
|
82 | - if (!($node instanceof File) && !($node instanceof Directory)) { |
|
83 | - return; |
|
84 | - } |
|
85 | - |
|
86 | - // need prefetch ? |
|
87 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Directory |
|
88 | - && $propFind->getDepth() !== 0 |
|
89 | - && !is_null($propFind->getStatus(self::PROPERTY_NAME_UNREAD)) |
|
90 | - ) { |
|
91 | - $unreadCounts = $this->commentsManager->getNumberOfUnreadCommentsForFolder($node->getId(), $this->userSession->getUser()); |
|
92 | - $this->cachedFolders[] = $node->getPath(); |
|
93 | - foreach ($unreadCounts as $id => $count) { |
|
94 | - $this->cachedUnreadCount[$id] = $count; |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - $propFind->handle(self::PROPERTY_NAME_COUNT, function() use ($node) { |
|
99 | - return $this->commentsManager->getNumberOfCommentsForObject('files', strval($node->getId())); |
|
100 | - }); |
|
101 | - |
|
102 | - $propFind->handle(self::PROPERTY_NAME_HREF, function() use ($node) { |
|
103 | - return $this->getCommentsLink($node); |
|
104 | - }); |
|
105 | - |
|
106 | - $propFind->handle(self::PROPERTY_NAME_UNREAD, function() use ($node) { |
|
107 | - if (isset($this->cachedUnreadCount[$node->getId()])) { |
|
108 | - return $this->cachedUnreadCount[$node->getId()]; |
|
109 | - } else { |
|
110 | - list($parentPath,) = \Sabre\Uri\split($node->getPath()); |
|
111 | - if ($parentPath === '') { |
|
112 | - $parentPath = '/'; |
|
113 | - } |
|
114 | - // if we already cached the folder this file is in we know there are no shares for this file |
|
115 | - if (array_search($parentPath, $this->cachedFolders) === false) { |
|
116 | - return $this->getUnreadCount($node); |
|
117 | - } else { |
|
118 | - return 0; |
|
119 | - } |
|
120 | - } |
|
121 | - }); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * returns a reference to the comments node |
|
126 | - * |
|
127 | - * @param Node $node |
|
128 | - * @return mixed|string |
|
129 | - */ |
|
130 | - public function getCommentsLink(Node $node) { |
|
131 | - $href = $this->server->getBaseUri(); |
|
132 | - $entryPoint = strpos($href, '/remote.php/'); |
|
133 | - if($entryPoint === false) { |
|
134 | - // in case we end up somewhere else, unexpectedly. |
|
135 | - return null; |
|
136 | - } |
|
137 | - $commentsPart = 'dav/comments/files/' . rawurldecode($node->getId()); |
|
138 | - $href = substr_replace($href, $commentsPart, $entryPoint + strlen('/remote.php/')); |
|
139 | - return $href; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * returns the number of unread comments for the currently logged in user |
|
144 | - * on the given file or directory node |
|
145 | - * |
|
146 | - * @param Node $node |
|
147 | - * @return Int|null |
|
148 | - */ |
|
149 | - public function getUnreadCount(Node $node) { |
|
150 | - $user = $this->userSession->getUser(); |
|
151 | - if(is_null($user)) { |
|
152 | - return null; |
|
153 | - } |
|
154 | - |
|
155 | - $lastRead = $this->commentsManager->getReadMark('files', strval($node->getId()), $user); |
|
156 | - |
|
157 | - return $this->commentsManager->getNumberOfCommentsForObject('files', strval($node->getId()), $lastRead); |
|
158 | - } |
|
32 | + const PROPERTY_NAME_HREF = '{http://owncloud.org/ns}comments-href'; |
|
33 | + const PROPERTY_NAME_COUNT = '{http://owncloud.org/ns}comments-count'; |
|
34 | + const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}comments-unread'; |
|
35 | + |
|
36 | + /** @var \Sabre\DAV\Server */ |
|
37 | + protected $server; |
|
38 | + |
|
39 | + /** @var ICommentsManager */ |
|
40 | + private $commentsManager; |
|
41 | + |
|
42 | + /** @var IUserSession */ |
|
43 | + private $userSession; |
|
44 | + |
|
45 | + private $cachedUnreadCount = []; |
|
46 | + |
|
47 | + private $cachedFolders = []; |
|
48 | + |
|
49 | + public function __construct(ICommentsManager $commentsManager, IUserSession $userSession) { |
|
50 | + $this->commentsManager = $commentsManager; |
|
51 | + $this->userSession = $userSession; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * This initializes the plugin. |
|
56 | + * |
|
57 | + * This function is called by Sabre\DAV\Server, after |
|
58 | + * addPlugin is called. |
|
59 | + * |
|
60 | + * This method should set up the required event subscriptions. |
|
61 | + * |
|
62 | + * @param \Sabre\DAV\Server $server |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + function initialize(\Sabre\DAV\Server $server) { |
|
66 | + $this->server = $server; |
|
67 | + $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Adds tags and favorites properties to the response, |
|
72 | + * if requested. |
|
73 | + * |
|
74 | + * @param PropFind $propFind |
|
75 | + * @param \Sabre\DAV\INode $node |
|
76 | + * @return void |
|
77 | + */ |
|
78 | + public function handleGetProperties( |
|
79 | + PropFind $propFind, |
|
80 | + \Sabre\DAV\INode $node |
|
81 | + ) { |
|
82 | + if (!($node instanceof File) && !($node instanceof Directory)) { |
|
83 | + return; |
|
84 | + } |
|
85 | + |
|
86 | + // need prefetch ? |
|
87 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Directory |
|
88 | + && $propFind->getDepth() !== 0 |
|
89 | + && !is_null($propFind->getStatus(self::PROPERTY_NAME_UNREAD)) |
|
90 | + ) { |
|
91 | + $unreadCounts = $this->commentsManager->getNumberOfUnreadCommentsForFolder($node->getId(), $this->userSession->getUser()); |
|
92 | + $this->cachedFolders[] = $node->getPath(); |
|
93 | + foreach ($unreadCounts as $id => $count) { |
|
94 | + $this->cachedUnreadCount[$id] = $count; |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + $propFind->handle(self::PROPERTY_NAME_COUNT, function() use ($node) { |
|
99 | + return $this->commentsManager->getNumberOfCommentsForObject('files', strval($node->getId())); |
|
100 | + }); |
|
101 | + |
|
102 | + $propFind->handle(self::PROPERTY_NAME_HREF, function() use ($node) { |
|
103 | + return $this->getCommentsLink($node); |
|
104 | + }); |
|
105 | + |
|
106 | + $propFind->handle(self::PROPERTY_NAME_UNREAD, function() use ($node) { |
|
107 | + if (isset($this->cachedUnreadCount[$node->getId()])) { |
|
108 | + return $this->cachedUnreadCount[$node->getId()]; |
|
109 | + } else { |
|
110 | + list($parentPath,) = \Sabre\Uri\split($node->getPath()); |
|
111 | + if ($parentPath === '') { |
|
112 | + $parentPath = '/'; |
|
113 | + } |
|
114 | + // if we already cached the folder this file is in we know there are no shares for this file |
|
115 | + if (array_search($parentPath, $this->cachedFolders) === false) { |
|
116 | + return $this->getUnreadCount($node); |
|
117 | + } else { |
|
118 | + return 0; |
|
119 | + } |
|
120 | + } |
|
121 | + }); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * returns a reference to the comments node |
|
126 | + * |
|
127 | + * @param Node $node |
|
128 | + * @return mixed|string |
|
129 | + */ |
|
130 | + public function getCommentsLink(Node $node) { |
|
131 | + $href = $this->server->getBaseUri(); |
|
132 | + $entryPoint = strpos($href, '/remote.php/'); |
|
133 | + if($entryPoint === false) { |
|
134 | + // in case we end up somewhere else, unexpectedly. |
|
135 | + return null; |
|
136 | + } |
|
137 | + $commentsPart = 'dav/comments/files/' . rawurldecode($node->getId()); |
|
138 | + $href = substr_replace($href, $commentsPart, $entryPoint + strlen('/remote.php/')); |
|
139 | + return $href; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * returns the number of unread comments for the currently logged in user |
|
144 | + * on the given file or directory node |
|
145 | + * |
|
146 | + * @param Node $node |
|
147 | + * @return Int|null |
|
148 | + */ |
|
149 | + public function getUnreadCount(Node $node) { |
|
150 | + $user = $this->userSession->getUser(); |
|
151 | + if(is_null($user)) { |
|
152 | + return null; |
|
153 | + } |
|
154 | + |
|
155 | + $lastRead = $this->commentsManager->getReadMark('files', strval($node->getId()), $user); |
|
156 | + |
|
157 | + return $this->commentsManager->getNumberOfCommentsForObject('files', strval($node->getId()), $lastRead); |
|
158 | + } |
|
159 | 159 | |
160 | 160 | } |
@@ -34,53 +34,53 @@ |
||
34 | 34 | use Sabre\HTTP\RequestInterface; |
35 | 35 | |
36 | 36 | class LockPlugin extends ServerPlugin { |
37 | - /** |
|
38 | - * Reference to main server object |
|
39 | - * |
|
40 | - * @var \Sabre\DAV\Server |
|
41 | - */ |
|
42 | - private $server; |
|
37 | + /** |
|
38 | + * Reference to main server object |
|
39 | + * |
|
40 | + * @var \Sabre\DAV\Server |
|
41 | + */ |
|
42 | + private $server; |
|
43 | 43 | |
44 | - /** |
|
45 | - * {@inheritdoc} |
|
46 | - */ |
|
47 | - public function initialize(\Sabre\DAV\Server $server) { |
|
48 | - $this->server = $server; |
|
49 | - $this->server->on('beforeMethod', [$this, 'getLock'], 50); |
|
50 | - $this->server->on('afterMethod', [$this, 'releaseLock'], 50); |
|
51 | - } |
|
44 | + /** |
|
45 | + * {@inheritdoc} |
|
46 | + */ |
|
47 | + public function initialize(\Sabre\DAV\Server $server) { |
|
48 | + $this->server = $server; |
|
49 | + $this->server->on('beforeMethod', [$this, 'getLock'], 50); |
|
50 | + $this->server->on('afterMethod', [$this, 'releaseLock'], 50); |
|
51 | + } |
|
52 | 52 | |
53 | - public function getLock(RequestInterface $request) { |
|
54 | - // we can't listen on 'beforeMethod:PUT' due to order of operations with setting up the tree |
|
55 | - // so instead we limit ourselves to the PUT method manually |
|
56 | - if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
57 | - return; |
|
58 | - } |
|
59 | - try { |
|
60 | - $node = $this->server->tree->getNodeForPath($request->getPath()); |
|
61 | - } catch (NotFound $e) { |
|
62 | - return; |
|
63 | - } |
|
64 | - if ($node instanceof Node) { |
|
65 | - try { |
|
66 | - $node->acquireLock(ILockingProvider::LOCK_SHARED); |
|
67 | - } catch (LockedException $e) { |
|
68 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
69 | - } |
|
70 | - } |
|
71 | - } |
|
53 | + public function getLock(RequestInterface $request) { |
|
54 | + // we can't listen on 'beforeMethod:PUT' due to order of operations with setting up the tree |
|
55 | + // so instead we limit ourselves to the PUT method manually |
|
56 | + if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
57 | + return; |
|
58 | + } |
|
59 | + try { |
|
60 | + $node = $this->server->tree->getNodeForPath($request->getPath()); |
|
61 | + } catch (NotFound $e) { |
|
62 | + return; |
|
63 | + } |
|
64 | + if ($node instanceof Node) { |
|
65 | + try { |
|
66 | + $node->acquireLock(ILockingProvider::LOCK_SHARED); |
|
67 | + } catch (LockedException $e) { |
|
68 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
69 | + } |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - public function releaseLock(RequestInterface $request) { |
|
74 | - if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
75 | - return; |
|
76 | - } |
|
77 | - try { |
|
78 | - $node = $this->server->tree->getNodeForPath($request->getPath()); |
|
79 | - } catch (NotFound $e) { |
|
80 | - return; |
|
81 | - } |
|
82 | - if ($node instanceof Node) { |
|
83 | - $node->releaseLock(ILockingProvider::LOCK_SHARED); |
|
84 | - } |
|
85 | - } |
|
73 | + public function releaseLock(RequestInterface $request) { |
|
74 | + if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
75 | + return; |
|
76 | + } |
|
77 | + try { |
|
78 | + $node = $this->server->tree->getNodeForPath($request->getPath()); |
|
79 | + } catch (NotFound $e) { |
|
80 | + return; |
|
81 | + } |
|
82 | + if ($node instanceof Node) { |
|
83 | + $node->releaseLock(ILockingProvider::LOCK_SHARED); |
|
84 | + } |
|
85 | + } |
|
86 | 86 | } |
@@ -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 | } |
@@ -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 |
@@ -26,54 +26,54 @@ |
||
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 | - * @param \Exception|null $previous |
|
40 | - */ |
|
41 | - public function __construct($message, $retry = false, \Exception $previous = null) { |
|
42 | - parent::__construct($message, 0, $previous); |
|
43 | - $this->retry = $retry; |
|
44 | - } |
|
36 | + /** |
|
37 | + * @param string $message |
|
38 | + * @param bool $retry |
|
39 | + * @param \Exception|null $previous |
|
40 | + */ |
|
41 | + public function __construct($message, $retry = false, \Exception $previous = null) { |
|
42 | + parent::__construct($message, 0, $previous); |
|
43 | + $this->retry = $retry; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Returns the HTTP status code for this exception |
|
48 | - * |
|
49 | - * @return int |
|
50 | - */ |
|
51 | - public function getHTTPCode() { |
|
46 | + /** |
|
47 | + * Returns the HTTP status code for this exception |
|
48 | + * |
|
49 | + * @return int |
|
50 | + */ |
|
51 | + public function getHTTPCode() { |
|
52 | 52 | |
53 | - return 400; |
|
53 | + return 400; |
|
54 | 54 | |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * This method allows the exception to include additional information |
|
59 | - * into the WebDAV error response |
|
60 | - * |
|
61 | - * @param \Sabre\DAV\Server $server |
|
62 | - * @param \DOMElement $errorNode |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
57 | + /** |
|
58 | + * This method allows the exception to include additional information |
|
59 | + * into the WebDAV error response |
|
60 | + * |
|
61 | + * @param \Sabre\DAV\Server $server |
|
62 | + * @param \DOMElement $errorNode |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
|
66 | 66 | |
67 | - // set ownCloud namespace |
|
68 | - $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
67 | + // set ownCloud namespace |
|
68 | + $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
|
69 | 69 | |
70 | - // adding the retry node |
|
71 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
72 | - $errorNode->appendChild($error); |
|
70 | + // adding the retry node |
|
71 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
|
72 | + $errorNode->appendChild($error); |
|
73 | 73 | |
74 | - // adding the message node |
|
75 | - $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
76 | - $errorNode->appendChild($error); |
|
77 | - } |
|
74 | + // adding the message node |
|
75 | + $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
|
76 | + $errorNode->appendChild($error); |
|
77 | + } |
|
78 | 78 | |
79 | 79 | } |
@@ -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 | } |
@@ -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 | } |
@@ -44,332 +44,332 @@ |
||
44 | 44 | |
45 | 45 | abstract class Node implements \Sabre\DAV\INode { |
46 | 46 | |
47 | - /** |
|
48 | - * @var \OC\Files\View |
|
49 | - */ |
|
50 | - protected $fileView; |
|
51 | - |
|
52 | - /** |
|
53 | - * The path to the current node |
|
54 | - * |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - protected $path; |
|
58 | - |
|
59 | - /** |
|
60 | - * node properties cache |
|
61 | - * |
|
62 | - * @var array |
|
63 | - */ |
|
64 | - protected $property_cache = null; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var \OCP\Files\FileInfo |
|
68 | - */ |
|
69 | - protected $info; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var IManager |
|
73 | - */ |
|
74 | - protected $shareManager; |
|
75 | - |
|
76 | - /** |
|
77 | - * Sets up the node, expects a full path name |
|
78 | - * |
|
79 | - * @param \OC\Files\View $view |
|
80 | - * @param \OCP\Files\FileInfo $info |
|
81 | - * @param IManager $shareManager |
|
82 | - */ |
|
83 | - public function __construct(View $view, FileInfo $info, IManager $shareManager = null) { |
|
84 | - $this->fileView = $view; |
|
85 | - $this->path = $this->fileView->getRelativePath($info->getPath()); |
|
86 | - $this->info = $info; |
|
87 | - if ($shareManager) { |
|
88 | - $this->shareManager = $shareManager; |
|
89 | - } else { |
|
90 | - $this->shareManager = \OC::$server->getShareManager(); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - protected function refreshInfo() { |
|
95 | - $this->info = $this->fileView->getFileInfo($this->path); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Returns the name of the node |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function getName() { |
|
104 | - return $this->info->getName(); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Returns the full path |
|
109 | - * |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function getPath() { |
|
113 | - return $this->path; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Renames the node |
|
118 | - * |
|
119 | - * @param string $name The new name |
|
120 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
121 | - * @throws \Sabre\DAV\Exception\Forbidden |
|
122 | - */ |
|
123 | - public function setName($name) { |
|
124 | - |
|
125 | - // rename is only allowed if the update privilege is granted |
|
126 | - if (!$this->info->isUpdateable()) { |
|
127 | - throw new \Sabre\DAV\Exception\Forbidden(); |
|
128 | - } |
|
129 | - |
|
130 | - list($parentPath,) = \Sabre\Uri\split($this->path); |
|
131 | - list(, $newName) = \Sabre\Uri\split($name); |
|
132 | - |
|
133 | - // verify path of the target |
|
134 | - $this->verifyPath(); |
|
135 | - |
|
136 | - $newPath = $parentPath . '/' . $newName; |
|
137 | - |
|
138 | - $this->fileView->rename($this->path, $newPath); |
|
139 | - |
|
140 | - $this->path = $newPath; |
|
141 | - |
|
142 | - $this->refreshInfo(); |
|
143 | - } |
|
144 | - |
|
145 | - public function setPropertyCache($property_cache) { |
|
146 | - $this->property_cache = $property_cache; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Returns the last modification time, as a unix timestamp |
|
151 | - * |
|
152 | - * @return int timestamp as integer |
|
153 | - */ |
|
154 | - public function getLastModified() { |
|
155 | - $timestamp = $this->info->getMtime(); |
|
156 | - if (!empty($timestamp)) { |
|
157 | - return (int)$timestamp; |
|
158 | - } |
|
159 | - return $timestamp; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * sets the last modification time of the file (mtime) to the value given |
|
164 | - * in the second parameter or to now if the second param is empty. |
|
165 | - * Even if the modification time is set to a custom value the access time is set to now. |
|
166 | - */ |
|
167 | - public function touch($mtime) { |
|
168 | - $mtime = $this->sanitizeMtime($mtime); |
|
169 | - $this->fileView->touch($this->path, $mtime); |
|
170 | - $this->refreshInfo(); |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Returns the ETag for a file |
|
175 | - * |
|
176 | - * An ETag is a unique identifier representing the current version of the |
|
177 | - * file. If the file changes, the ETag MUST change. The ETag is an |
|
178 | - * arbitrary string, but MUST be surrounded by double-quotes. |
|
179 | - * |
|
180 | - * Return null if the ETag can not effectively be determined |
|
181 | - * |
|
182 | - * @return string |
|
183 | - */ |
|
184 | - public function getETag() { |
|
185 | - return '"' . $this->info->getEtag() . '"'; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Sets the ETag |
|
190 | - * |
|
191 | - * @param string $etag |
|
192 | - * |
|
193 | - * @return int file id of updated file or -1 on failure |
|
194 | - */ |
|
195 | - public function setETag($etag) { |
|
196 | - return $this->fileView->putFileInfo($this->path, array('etag' => $etag)); |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Returns the size of the node, in bytes |
|
201 | - * |
|
202 | - * @return integer |
|
203 | - */ |
|
204 | - public function getSize() { |
|
205 | - return $this->info->getSize(); |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Returns the cache's file id |
|
210 | - * |
|
211 | - * @return int |
|
212 | - */ |
|
213 | - public function getId() { |
|
214 | - return $this->info->getId(); |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * @return string|null |
|
219 | - */ |
|
220 | - public function getFileId() { |
|
221 | - if ($this->info->getId()) { |
|
222 | - $instanceId = \OC_Util::getInstanceId(); |
|
223 | - $id = sprintf('%08d', $this->info->getId()); |
|
224 | - return $id . $instanceId; |
|
225 | - } |
|
226 | - |
|
227 | - return null; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * @return integer |
|
232 | - */ |
|
233 | - public function getInternalFileId() { |
|
234 | - return $this->info->getId(); |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * @param string $user |
|
239 | - * @return int |
|
240 | - */ |
|
241 | - public function getSharePermissions($user) { |
|
242 | - |
|
243 | - // check of we access a federated share |
|
244 | - if ($user !== null) { |
|
245 | - try { |
|
246 | - $share = $this->shareManager->getShareByToken($user); |
|
247 | - return $share->getPermissions(); |
|
248 | - } catch (ShareNotFound $e) { |
|
249 | - // ignore |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - $storage = $this->info->getStorage(); |
|
254 | - |
|
255 | - $path = $this->info->getInternalPath(); |
|
256 | - |
|
257 | - if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
258 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
259 | - $permissions = (int)$storage->getShare()->getPermissions(); |
|
260 | - } else { |
|
261 | - $permissions = $storage->getPermissions($path); |
|
262 | - } |
|
263 | - |
|
264 | - /* |
|
47 | + /** |
|
48 | + * @var \OC\Files\View |
|
49 | + */ |
|
50 | + protected $fileView; |
|
51 | + |
|
52 | + /** |
|
53 | + * The path to the current node |
|
54 | + * |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + protected $path; |
|
58 | + |
|
59 | + /** |
|
60 | + * node properties cache |
|
61 | + * |
|
62 | + * @var array |
|
63 | + */ |
|
64 | + protected $property_cache = null; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var \OCP\Files\FileInfo |
|
68 | + */ |
|
69 | + protected $info; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var IManager |
|
73 | + */ |
|
74 | + protected $shareManager; |
|
75 | + |
|
76 | + /** |
|
77 | + * Sets up the node, expects a full path name |
|
78 | + * |
|
79 | + * @param \OC\Files\View $view |
|
80 | + * @param \OCP\Files\FileInfo $info |
|
81 | + * @param IManager $shareManager |
|
82 | + */ |
|
83 | + public function __construct(View $view, FileInfo $info, IManager $shareManager = null) { |
|
84 | + $this->fileView = $view; |
|
85 | + $this->path = $this->fileView->getRelativePath($info->getPath()); |
|
86 | + $this->info = $info; |
|
87 | + if ($shareManager) { |
|
88 | + $this->shareManager = $shareManager; |
|
89 | + } else { |
|
90 | + $this->shareManager = \OC::$server->getShareManager(); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + protected function refreshInfo() { |
|
95 | + $this->info = $this->fileView->getFileInfo($this->path); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Returns the name of the node |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function getName() { |
|
104 | + return $this->info->getName(); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Returns the full path |
|
109 | + * |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function getPath() { |
|
113 | + return $this->path; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Renames the node |
|
118 | + * |
|
119 | + * @param string $name The new name |
|
120 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
121 | + * @throws \Sabre\DAV\Exception\Forbidden |
|
122 | + */ |
|
123 | + public function setName($name) { |
|
124 | + |
|
125 | + // rename is only allowed if the update privilege is granted |
|
126 | + if (!$this->info->isUpdateable()) { |
|
127 | + throw new \Sabre\DAV\Exception\Forbidden(); |
|
128 | + } |
|
129 | + |
|
130 | + list($parentPath,) = \Sabre\Uri\split($this->path); |
|
131 | + list(, $newName) = \Sabre\Uri\split($name); |
|
132 | + |
|
133 | + // verify path of the target |
|
134 | + $this->verifyPath(); |
|
135 | + |
|
136 | + $newPath = $parentPath . '/' . $newName; |
|
137 | + |
|
138 | + $this->fileView->rename($this->path, $newPath); |
|
139 | + |
|
140 | + $this->path = $newPath; |
|
141 | + |
|
142 | + $this->refreshInfo(); |
|
143 | + } |
|
144 | + |
|
145 | + public function setPropertyCache($property_cache) { |
|
146 | + $this->property_cache = $property_cache; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Returns the last modification time, as a unix timestamp |
|
151 | + * |
|
152 | + * @return int timestamp as integer |
|
153 | + */ |
|
154 | + public function getLastModified() { |
|
155 | + $timestamp = $this->info->getMtime(); |
|
156 | + if (!empty($timestamp)) { |
|
157 | + return (int)$timestamp; |
|
158 | + } |
|
159 | + return $timestamp; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * sets the last modification time of the file (mtime) to the value given |
|
164 | + * in the second parameter or to now if the second param is empty. |
|
165 | + * Even if the modification time is set to a custom value the access time is set to now. |
|
166 | + */ |
|
167 | + public function touch($mtime) { |
|
168 | + $mtime = $this->sanitizeMtime($mtime); |
|
169 | + $this->fileView->touch($this->path, $mtime); |
|
170 | + $this->refreshInfo(); |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Returns the ETag for a file |
|
175 | + * |
|
176 | + * An ETag is a unique identifier representing the current version of the |
|
177 | + * file. If the file changes, the ETag MUST change. The ETag is an |
|
178 | + * arbitrary string, but MUST be surrounded by double-quotes. |
|
179 | + * |
|
180 | + * Return null if the ETag can not effectively be determined |
|
181 | + * |
|
182 | + * @return string |
|
183 | + */ |
|
184 | + public function getETag() { |
|
185 | + return '"' . $this->info->getEtag() . '"'; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Sets the ETag |
|
190 | + * |
|
191 | + * @param string $etag |
|
192 | + * |
|
193 | + * @return int file id of updated file or -1 on failure |
|
194 | + */ |
|
195 | + public function setETag($etag) { |
|
196 | + return $this->fileView->putFileInfo($this->path, array('etag' => $etag)); |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Returns the size of the node, in bytes |
|
201 | + * |
|
202 | + * @return integer |
|
203 | + */ |
|
204 | + public function getSize() { |
|
205 | + return $this->info->getSize(); |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Returns the cache's file id |
|
210 | + * |
|
211 | + * @return int |
|
212 | + */ |
|
213 | + public function getId() { |
|
214 | + return $this->info->getId(); |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * @return string|null |
|
219 | + */ |
|
220 | + public function getFileId() { |
|
221 | + if ($this->info->getId()) { |
|
222 | + $instanceId = \OC_Util::getInstanceId(); |
|
223 | + $id = sprintf('%08d', $this->info->getId()); |
|
224 | + return $id . $instanceId; |
|
225 | + } |
|
226 | + |
|
227 | + return null; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * @return integer |
|
232 | + */ |
|
233 | + public function getInternalFileId() { |
|
234 | + return $this->info->getId(); |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * @param string $user |
|
239 | + * @return int |
|
240 | + */ |
|
241 | + public function getSharePermissions($user) { |
|
242 | + |
|
243 | + // check of we access a federated share |
|
244 | + if ($user !== null) { |
|
245 | + try { |
|
246 | + $share = $this->shareManager->getShareByToken($user); |
|
247 | + return $share->getPermissions(); |
|
248 | + } catch (ShareNotFound $e) { |
|
249 | + // ignore |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + $storage = $this->info->getStorage(); |
|
254 | + |
|
255 | + $path = $this->info->getInternalPath(); |
|
256 | + |
|
257 | + if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
258 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
259 | + $permissions = (int)$storage->getShare()->getPermissions(); |
|
260 | + } else { |
|
261 | + $permissions = $storage->getPermissions($path); |
|
262 | + } |
|
263 | + |
|
264 | + /* |
|
265 | 265 | * We can always share non moveable mount points with DELETE and UPDATE |
266 | 266 | * Eventually we need to do this properly |
267 | 267 | */ |
268 | - $mountpoint = $this->info->getMountPoint(); |
|
269 | - if (!($mountpoint instanceof MoveableMount)) { |
|
270 | - $mountpointpath = $mountpoint->getMountPoint(); |
|
271 | - if (substr($mountpointpath, -1) === '/') { |
|
272 | - $mountpointpath = substr($mountpointpath, 0, -1); |
|
273 | - } |
|
274 | - |
|
275 | - if ($mountpointpath === $this->info->getPath()) { |
|
276 | - $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
277 | - } |
|
278 | - } |
|
279 | - |
|
280 | - /* |
|
268 | + $mountpoint = $this->info->getMountPoint(); |
|
269 | + if (!($mountpoint instanceof MoveableMount)) { |
|
270 | + $mountpointpath = $mountpoint->getMountPoint(); |
|
271 | + if (substr($mountpointpath, -1) === '/') { |
|
272 | + $mountpointpath = substr($mountpointpath, 0, -1); |
|
273 | + } |
|
274 | + |
|
275 | + if ($mountpointpath === $this->info->getPath()) { |
|
276 | + $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
277 | + } |
|
278 | + } |
|
279 | + |
|
280 | + /* |
|
281 | 281 | * Files can't have create or delete permissions |
282 | 282 | */ |
283 | - if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
284 | - $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE); |
|
285 | - } |
|
286 | - |
|
287 | - return $permissions; |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * @return string |
|
292 | - */ |
|
293 | - public function getDavPermissions() { |
|
294 | - $p = ''; |
|
295 | - if ($this->info->isShared()) { |
|
296 | - $p .= 'S'; |
|
297 | - } |
|
298 | - if ($this->info->isShareable()) { |
|
299 | - $p .= 'R'; |
|
300 | - } |
|
301 | - if ($this->info->isMounted()) { |
|
302 | - $p .= 'M'; |
|
303 | - } |
|
304 | - if ($this->info->isReadable()) { |
|
305 | - $p .= 'G'; |
|
306 | - } |
|
307 | - if ($this->info->isDeletable()) { |
|
308 | - $p .= 'D'; |
|
309 | - } |
|
310 | - if ($this->info->isUpdateable()) { |
|
311 | - $p .= 'NV'; // Renameable, Moveable |
|
312 | - } |
|
313 | - if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
314 | - if ($this->info->isUpdateable()) { |
|
315 | - $p .= 'W'; |
|
316 | - } |
|
317 | - } else { |
|
318 | - if ($this->info->isCreatable()) { |
|
319 | - $p .= 'CK'; |
|
320 | - } |
|
321 | - } |
|
322 | - return $p; |
|
323 | - } |
|
324 | - |
|
325 | - public function getOwner() { |
|
326 | - return $this->info->getOwner(); |
|
327 | - } |
|
328 | - |
|
329 | - protected function verifyPath() { |
|
330 | - try { |
|
331 | - $fileName = basename($this->info->getPath()); |
|
332 | - $this->fileView->verifyPath($this->path, $fileName); |
|
333 | - } catch (\OCP\Files\InvalidPathException $ex) { |
|
334 | - throw new InvalidPath($ex->getMessage()); |
|
335 | - } |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
340 | - */ |
|
341 | - public function acquireLock($type) { |
|
342 | - $this->fileView->lockFile($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 releaseLock($type) { |
|
349 | - $this->fileView->unlockFile($this->path, $type); |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
354 | - */ |
|
355 | - public function changeLock($type) { |
|
356 | - $this->fileView->changeLock($this->path, $type); |
|
357 | - } |
|
358 | - |
|
359 | - public function getFileInfo() { |
|
360 | - return $this->info; |
|
361 | - } |
|
362 | - |
|
363 | - protected function sanitizeMtime($mtimeFromRequest) { |
|
364 | - // In PHP 5.X "is_numeric" returns true for strings in hexadecimal |
|
365 | - // notation. This is no longer the case in PHP 7.X, so this check |
|
366 | - // ensures that strings with hexadecimal notations fail too in PHP 5.X. |
|
367 | - $isHexadecimal = is_string($mtimeFromRequest) && preg_match('/^\s*0[xX]/', $mtimeFromRequest); |
|
368 | - if ($isHexadecimal || !is_numeric($mtimeFromRequest)) { |
|
369 | - throw new \InvalidArgumentException('X-OC-MTime header must be an integer (unix timestamp).'); |
|
370 | - } |
|
371 | - |
|
372 | - return intval($mtimeFromRequest); |
|
373 | - } |
|
283 | + if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
284 | + $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE); |
|
285 | + } |
|
286 | + |
|
287 | + return $permissions; |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * @return string |
|
292 | + */ |
|
293 | + public function getDavPermissions() { |
|
294 | + $p = ''; |
|
295 | + if ($this->info->isShared()) { |
|
296 | + $p .= 'S'; |
|
297 | + } |
|
298 | + if ($this->info->isShareable()) { |
|
299 | + $p .= 'R'; |
|
300 | + } |
|
301 | + if ($this->info->isMounted()) { |
|
302 | + $p .= 'M'; |
|
303 | + } |
|
304 | + if ($this->info->isReadable()) { |
|
305 | + $p .= 'G'; |
|
306 | + } |
|
307 | + if ($this->info->isDeletable()) { |
|
308 | + $p .= 'D'; |
|
309 | + } |
|
310 | + if ($this->info->isUpdateable()) { |
|
311 | + $p .= 'NV'; // Renameable, Moveable |
|
312 | + } |
|
313 | + if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
314 | + if ($this->info->isUpdateable()) { |
|
315 | + $p .= 'W'; |
|
316 | + } |
|
317 | + } else { |
|
318 | + if ($this->info->isCreatable()) { |
|
319 | + $p .= 'CK'; |
|
320 | + } |
|
321 | + } |
|
322 | + return $p; |
|
323 | + } |
|
324 | + |
|
325 | + public function getOwner() { |
|
326 | + return $this->info->getOwner(); |
|
327 | + } |
|
328 | + |
|
329 | + protected function verifyPath() { |
|
330 | + try { |
|
331 | + $fileName = basename($this->info->getPath()); |
|
332 | + $this->fileView->verifyPath($this->path, $fileName); |
|
333 | + } catch (\OCP\Files\InvalidPathException $ex) { |
|
334 | + throw new InvalidPath($ex->getMessage()); |
|
335 | + } |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
340 | + */ |
|
341 | + public function acquireLock($type) { |
|
342 | + $this->fileView->lockFile($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 releaseLock($type) { |
|
349 | + $this->fileView->unlockFile($this->path, $type); |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
354 | + */ |
|
355 | + public function changeLock($type) { |
|
356 | + $this->fileView->changeLock($this->path, $type); |
|
357 | + } |
|
358 | + |
|
359 | + public function getFileInfo() { |
|
360 | + return $this->info; |
|
361 | + } |
|
362 | + |
|
363 | + protected function sanitizeMtime($mtimeFromRequest) { |
|
364 | + // In PHP 5.X "is_numeric" returns true for strings in hexadecimal |
|
365 | + // notation. This is no longer the case in PHP 7.X, so this check |
|
366 | + // ensures that strings with hexadecimal notations fail too in PHP 5.X. |
|
367 | + $isHexadecimal = is_string($mtimeFromRequest) && preg_match('/^\s*0[xX]/', $mtimeFromRequest); |
|
368 | + if ($isHexadecimal || !is_numeric($mtimeFromRequest)) { |
|
369 | + throw new \InvalidArgumentException('X-OC-MTime header must be an integer (unix timestamp).'); |
|
370 | + } |
|
371 | + |
|
372 | + return intval($mtimeFromRequest); |
|
373 | + } |
|
374 | 374 | |
375 | 375 | } |