@@ -47,365 +47,365 @@  | 
                                                    ||
| 47 | 47 | |
| 48 | 48 |  abstract class Node implements \Sabre\DAV\INode { | 
                                                        
| 49 | 49 | |
| 50 | - /**  | 
                                                        |
| 51 | - * @var \OC\Files\View  | 
                                                        |
| 52 | - */  | 
                                                        |
| 53 | - protected $fileView;  | 
                                                        |
| 54 | -  | 
                                                        |
| 55 | - /**  | 
                                                        |
| 56 | - * The path to the current node  | 
                                                        |
| 57 | - *  | 
                                                        |
| 58 | - * @var string  | 
                                                        |
| 59 | - */  | 
                                                        |
| 60 | - protected $path;  | 
                                                        |
| 61 | -  | 
                                                        |
| 62 | - /**  | 
                                                        |
| 63 | - * node properties cache  | 
                                                        |
| 64 | - *  | 
                                                        |
| 65 | - * @var array  | 
                                                        |
| 66 | - */  | 
                                                        |
| 67 | - protected $property_cache = null;  | 
                                                        |
| 68 | -  | 
                                                        |
| 69 | - /**  | 
                                                        |
| 70 | - * @var \OCP\Files\FileInfo  | 
                                                        |
| 71 | - */  | 
                                                        |
| 72 | - protected $info;  | 
                                                        |
| 73 | -  | 
                                                        |
| 74 | - /**  | 
                                                        |
| 75 | - * @var IManager  | 
                                                        |
| 76 | - */  | 
                                                        |
| 77 | - protected $shareManager;  | 
                                                        |
| 78 | -  | 
                                                        |
| 79 | - /**  | 
                                                        |
| 80 | - * Sets up the node, expects a full path name  | 
                                                        |
| 81 | - *  | 
                                                        |
| 82 | - * @param \OC\Files\View $view  | 
                                                        |
| 83 | - * @param \OCP\Files\FileInfo $info  | 
                                                        |
| 84 | - * @param IManager $shareManager  | 
                                                        |
| 85 | - */  | 
                                                        |
| 86 | -	public function __construct(View $view, FileInfo $info, IManager $shareManager = null) { | 
                                                        |
| 87 | - $this->fileView = $view;  | 
                                                        |
| 88 | - $this->path = $this->fileView->getRelativePath($info->getPath());  | 
                                                        |
| 89 | - $this->info = $info;  | 
                                                        |
| 90 | -		if ($shareManager) { | 
                                                        |
| 91 | - $this->shareManager = $shareManager;  | 
                                                        |
| 92 | -		} else { | 
                                                        |
| 93 | - $this->shareManager = \OC::$server->getShareManager();  | 
                                                        |
| 94 | - }  | 
                                                        |
| 95 | - }  | 
                                                        |
| 96 | -  | 
                                                        |
| 97 | -	protected function refreshInfo() { | 
                                                        |
| 98 | - $this->info = $this->fileView->getFileInfo($this->path);  | 
                                                        |
| 99 | - }  | 
                                                        |
| 100 | -  | 
                                                        |
| 101 | - /**  | 
                                                        |
| 102 | - * Returns the name of the node  | 
                                                        |
| 103 | - *  | 
                                                        |
| 104 | - * @return string  | 
                                                        |
| 105 | - */  | 
                                                        |
| 106 | -	public function getName() { | 
                                                        |
| 107 | - return $this->info->getName();  | 
                                                        |
| 108 | - }  | 
                                                        |
| 109 | -  | 
                                                        |
| 110 | - /**  | 
                                                        |
| 111 | - * Returns the full path  | 
                                                        |
| 112 | - *  | 
                                                        |
| 113 | - * @return string  | 
                                                        |
| 114 | - */  | 
                                                        |
| 115 | -	public function getPath() { | 
                                                        |
| 116 | - return $this->path;  | 
                                                        |
| 117 | - }  | 
                                                        |
| 118 | -  | 
                                                        |
| 119 | - /**  | 
                                                        |
| 120 | - * Renames the node  | 
                                                        |
| 121 | - *  | 
                                                        |
| 122 | - * @param string $name The new name  | 
                                                        |
| 123 | - * @throws \Sabre\DAV\Exception\BadRequest  | 
                                                        |
| 124 | - * @throws \Sabre\DAV\Exception\Forbidden  | 
                                                        |
| 125 | - */  | 
                                                        |
| 126 | -	public function setName($name) { | 
                                                        |
| 127 | -  | 
                                                        |
| 128 | - // rename is only allowed if the update privilege is granted  | 
                                                        |
| 129 | -		if (!$this->info->isUpdateable()) { | 
                                                        |
| 130 | - throw new \Sabre\DAV\Exception\Forbidden();  | 
                                                        |
| 131 | - }  | 
                                                        |
| 132 | -  | 
                                                        |
| 133 | - list($parentPath,) = \Sabre\Uri\split($this->path);  | 
                                                        |
| 134 | - list(, $newName) = \Sabre\Uri\split($name);  | 
                                                        |
| 135 | -  | 
                                                        |
| 136 | - // verify path of the target  | 
                                                        |
| 137 | - $this->verifyPath();  | 
                                                        |
| 138 | -  | 
                                                        |
| 139 | - $newPath = $parentPath . '/' . $newName;  | 
                                                        |
| 140 | -  | 
                                                        |
| 141 | -		if (!$this->fileView->rename($this->path, $newPath)) { | 
                                                        |
| 142 | -			throw new \Sabre\DAV\Exception('Failed to rename '. $this->path . ' to ' . $newPath); | 
                                                        |
| 143 | - }  | 
                                                        |
| 144 | -  | 
                                                        |
| 145 | - $this->path = $newPath;  | 
                                                        |
| 146 | -  | 
                                                        |
| 147 | - $this->refreshInfo();  | 
                                                        |
| 148 | - }  | 
                                                        |
| 149 | -  | 
                                                        |
| 150 | -	public function setPropertyCache($property_cache) { | 
                                                        |
| 151 | - $this->property_cache = $property_cache;  | 
                                                        |
| 152 | - }  | 
                                                        |
| 153 | -  | 
                                                        |
| 154 | - /**  | 
                                                        |
| 155 | - * Returns the last modification time, as a unix timestamp  | 
                                                        |
| 156 | - *  | 
                                                        |
| 157 | - * @return int timestamp as integer  | 
                                                        |
| 158 | - */  | 
                                                        |
| 159 | -	public function getLastModified() { | 
                                                        |
| 160 | - $timestamp = $this->info->getMtime();  | 
                                                        |
| 161 | -		if (!empty($timestamp)) { | 
                                                        |
| 162 | - return (int)$timestamp;  | 
                                                        |
| 163 | - }  | 
                                                        |
| 164 | - return $timestamp;  | 
                                                        |
| 165 | - }  | 
                                                        |
| 166 | -  | 
                                                        |
| 167 | - /**  | 
                                                        |
| 168 | - * sets the last modification time of the file (mtime) to the value given  | 
                                                        |
| 169 | - * in the second parameter or to now if the second param is empty.  | 
                                                        |
| 170 | - * Even if the modification time is set to a custom value the access time is set to now.  | 
                                                        |
| 171 | - */  | 
                                                        |
| 172 | -	public function touch($mtime) { | 
                                                        |
| 173 | - $mtime = $this->sanitizeMtime($mtime);  | 
                                                        |
| 174 | - $this->fileView->touch($this->path, $mtime);  | 
                                                        |
| 175 | - $this->refreshInfo();  | 
                                                        |
| 176 | - }  | 
                                                        |
| 177 | -  | 
                                                        |
| 178 | - /**  | 
                                                        |
| 179 | - * Returns the ETag for a file  | 
                                                        |
| 180 | - *  | 
                                                        |
| 181 | - * An ETag is a unique identifier representing the current version of the  | 
                                                        |
| 182 | - * file. If the file changes, the ETag MUST change. The ETag is an  | 
                                                        |
| 183 | - * arbitrary string, but MUST be surrounded by double-quotes.  | 
                                                        |
| 184 | - *  | 
                                                        |
| 185 | - * Return null if the ETag can not effectively be determined  | 
                                                        |
| 186 | - *  | 
                                                        |
| 187 | - * @return string  | 
                                                        |
| 188 | - */  | 
                                                        |
| 189 | -	public function getETag() { | 
                                                        |
| 190 | - return '"' . $this->info->getEtag() . '"';  | 
                                                        |
| 191 | - }  | 
                                                        |
| 192 | -  | 
                                                        |
| 193 | - /**  | 
                                                        |
| 194 | - * Sets the ETag  | 
                                                        |
| 195 | - *  | 
                                                        |
| 196 | - * @param string $etag  | 
                                                        |
| 197 | - *  | 
                                                        |
| 198 | - * @return int file id of updated file or -1 on failure  | 
                                                        |
| 199 | - */  | 
                                                        |
| 200 | -	public function setETag($etag) { | 
                                                        |
| 201 | -		return $this->fileView->putFileInfo($this->path, array('etag' => $etag)); | 
                                                        |
| 202 | - }  | 
                                                        |
| 203 | -  | 
                                                        |
| 204 | - /**  | 
                                                        |
| 205 | - * Returns the size of the node, in bytes  | 
                                                        |
| 206 | - *  | 
                                                        |
| 207 | - * @return integer  | 
                                                        |
| 208 | - */  | 
                                                        |
| 209 | -	public function getSize() { | 
                                                        |
| 210 | - return $this->info->getSize();  | 
                                                        |
| 211 | - }  | 
                                                        |
| 212 | -  | 
                                                        |
| 213 | - /**  | 
                                                        |
| 214 | - * Returns the cache's file id  | 
                                                        |
| 215 | - *  | 
                                                        |
| 216 | - * @return int  | 
                                                        |
| 217 | - */  | 
                                                        |
| 218 | -	public function getId() { | 
                                                        |
| 219 | - return $this->info->getId();  | 
                                                        |
| 220 | - }  | 
                                                        |
| 221 | -  | 
                                                        |
| 222 | - /**  | 
                                                        |
| 223 | - * @return string|null  | 
                                                        |
| 224 | - */  | 
                                                        |
| 225 | -	public function getFileId() { | 
                                                        |
| 226 | -		if ($this->info->getId()) { | 
                                                        |
| 227 | - $instanceId = \OC_Util::getInstanceId();  | 
                                                        |
| 228 | -			$id = sprintf('%08d', $this->info->getId()); | 
                                                        |
| 229 | - return $id . $instanceId;  | 
                                                        |
| 230 | - }  | 
                                                        |
| 231 | -  | 
                                                        |
| 232 | - return null;  | 
                                                        |
| 233 | - }  | 
                                                        |
| 234 | -  | 
                                                        |
| 235 | - /**  | 
                                                        |
| 236 | - * @return integer  | 
                                                        |
| 237 | - */  | 
                                                        |
| 238 | -	public function getInternalFileId() { | 
                                                        |
| 239 | - return $this->info->getId();  | 
                                                        |
| 240 | - }  | 
                                                        |
| 241 | -  | 
                                                        |
| 242 | - /**  | 
                                                        |
| 243 | - * @param string $user  | 
                                                        |
| 244 | - * @return int  | 
                                                        |
| 245 | - */  | 
                                                        |
| 246 | -	public function getSharePermissions($user) { | 
                                                        |
| 247 | -  | 
                                                        |
| 248 | - // check of we access a federated share  | 
                                                        |
| 249 | -		if ($user !== null) { | 
                                                        |
| 250 | -			try { | 
                                                        |
| 251 | - $share = $this->shareManager->getShareByToken($user);  | 
                                                        |
| 252 | - return $share->getPermissions();  | 
                                                        |
| 253 | -			} catch (ShareNotFound $e) { | 
                                                        |
| 254 | - // ignore  | 
                                                        |
| 255 | - }  | 
                                                        |
| 256 | - }  | 
                                                        |
| 257 | -  | 
                                                        |
| 258 | -		try { | 
                                                        |
| 259 | - $storage = $this->info->getStorage();  | 
                                                        |
| 260 | -		} catch (StorageNotAvailableException $e) { | 
                                                        |
| 261 | - $storage = null;  | 
                                                        |
| 262 | - }  | 
                                                        |
| 263 | -  | 
                                                        |
| 264 | -		if ($storage && $storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { | 
                                                        |
| 265 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */  | 
                                                        |
| 266 | - $permissions = (int)$storage->getShare()->getPermissions();  | 
                                                        |
| 267 | -		} else { | 
                                                        |
| 268 | - $permissions = $this->info->getPermissions();  | 
                                                        |
| 269 | - }  | 
                                                        |
| 270 | -  | 
                                                        |
| 271 | - /*  | 
                                                        |
| 50 | + /**  | 
                                                        |
| 51 | + * @var \OC\Files\View  | 
                                                        |
| 52 | + */  | 
                                                        |
| 53 | + protected $fileView;  | 
                                                        |
| 54 | +  | 
                                                        |
| 55 | + /**  | 
                                                        |
| 56 | + * The path to the current node  | 
                                                        |
| 57 | + *  | 
                                                        |
| 58 | + * @var string  | 
                                                        |
| 59 | + */  | 
                                                        |
| 60 | + protected $path;  | 
                                                        |
| 61 | +  | 
                                                        |
| 62 | + /**  | 
                                                        |
| 63 | + * node properties cache  | 
                                                        |
| 64 | + *  | 
                                                        |
| 65 | + * @var array  | 
                                                        |
| 66 | + */  | 
                                                        |
| 67 | + protected $property_cache = null;  | 
                                                        |
| 68 | +  | 
                                                        |
| 69 | + /**  | 
                                                        |
| 70 | + * @var \OCP\Files\FileInfo  | 
                                                        |
| 71 | + */  | 
                                                        |
| 72 | + protected $info;  | 
                                                        |
| 73 | +  | 
                                                        |
| 74 | + /**  | 
                                                        |
| 75 | + * @var IManager  | 
                                                        |
| 76 | + */  | 
                                                        |
| 77 | + protected $shareManager;  | 
                                                        |
| 78 | +  | 
                                                        |
| 79 | + /**  | 
                                                        |
| 80 | + * Sets up the node, expects a full path name  | 
                                                        |
| 81 | + *  | 
                                                        |
| 82 | + * @param \OC\Files\View $view  | 
                                                        |
| 83 | + * @param \OCP\Files\FileInfo $info  | 
                                                        |
| 84 | + * @param IManager $shareManager  | 
                                                        |
| 85 | + */  | 
                                                        |
| 86 | +    public function __construct(View $view, FileInfo $info, IManager $shareManager = null) { | 
                                                        |
| 87 | + $this->fileView = $view;  | 
                                                        |
| 88 | + $this->path = $this->fileView->getRelativePath($info->getPath());  | 
                                                        |
| 89 | + $this->info = $info;  | 
                                                        |
| 90 | +        if ($shareManager) { | 
                                                        |
| 91 | + $this->shareManager = $shareManager;  | 
                                                        |
| 92 | +        } else { | 
                                                        |
| 93 | + $this->shareManager = \OC::$server->getShareManager();  | 
                                                        |
| 94 | + }  | 
                                                        |
| 95 | + }  | 
                                                        |
| 96 | +  | 
                                                        |
| 97 | +    protected function refreshInfo() { | 
                                                        |
| 98 | + $this->info = $this->fileView->getFileInfo($this->path);  | 
                                                        |
| 99 | + }  | 
                                                        |
| 100 | +  | 
                                                        |
| 101 | + /**  | 
                                                        |
| 102 | + * Returns the name of the node  | 
                                                        |
| 103 | + *  | 
                                                        |
| 104 | + * @return string  | 
                                                        |
| 105 | + */  | 
                                                        |
| 106 | +    public function getName() { | 
                                                        |
| 107 | + return $this->info->getName();  | 
                                                        |
| 108 | + }  | 
                                                        |
| 109 | +  | 
                                                        |
| 110 | + /**  | 
                                                        |
| 111 | + * Returns the full path  | 
                                                        |
| 112 | + *  | 
                                                        |
| 113 | + * @return string  | 
                                                        |
| 114 | + */  | 
                                                        |
| 115 | +    public function getPath() { | 
                                                        |
| 116 | + return $this->path;  | 
                                                        |
| 117 | + }  | 
                                                        |
| 118 | +  | 
                                                        |
| 119 | + /**  | 
                                                        |
| 120 | + * Renames the node  | 
                                                        |
| 121 | + *  | 
                                                        |
| 122 | + * @param string $name The new name  | 
                                                        |
| 123 | + * @throws \Sabre\DAV\Exception\BadRequest  | 
                                                        |
| 124 | + * @throws \Sabre\DAV\Exception\Forbidden  | 
                                                        |
| 125 | + */  | 
                                                        |
| 126 | +    public function setName($name) { | 
                                                        |
| 127 | +  | 
                                                        |
| 128 | + // rename is only allowed if the update privilege is granted  | 
                                                        |
| 129 | +        if (!$this->info->isUpdateable()) { | 
                                                        |
| 130 | + throw new \Sabre\DAV\Exception\Forbidden();  | 
                                                        |
| 131 | + }  | 
                                                        |
| 132 | +  | 
                                                        |
| 133 | + list($parentPath,) = \Sabre\Uri\split($this->path);  | 
                                                        |
| 134 | + list(, $newName) = \Sabre\Uri\split($name);  | 
                                                        |
| 135 | +  | 
                                                        |
| 136 | + // verify path of the target  | 
                                                        |
| 137 | + $this->verifyPath();  | 
                                                        |
| 138 | +  | 
                                                        |
| 139 | + $newPath = $parentPath . '/' . $newName;  | 
                                                        |
| 140 | +  | 
                                                        |
| 141 | +        if (!$this->fileView->rename($this->path, $newPath)) { | 
                                                        |
| 142 | +            throw new \Sabre\DAV\Exception('Failed to rename '. $this->path . ' to ' . $newPath); | 
                                                        |
| 143 | + }  | 
                                                        |
| 144 | +  | 
                                                        |
| 145 | + $this->path = $newPath;  | 
                                                        |
| 146 | +  | 
                                                        |
| 147 | + $this->refreshInfo();  | 
                                                        |
| 148 | + }  | 
                                                        |
| 149 | +  | 
                                                        |
| 150 | +    public function setPropertyCache($property_cache) { | 
                                                        |
| 151 | + $this->property_cache = $property_cache;  | 
                                                        |
| 152 | + }  | 
                                                        |
| 153 | +  | 
                                                        |
| 154 | + /**  | 
                                                        |
| 155 | + * Returns the last modification time, as a unix timestamp  | 
                                                        |
| 156 | + *  | 
                                                        |
| 157 | + * @return int timestamp as integer  | 
                                                        |
| 158 | + */  | 
                                                        |
| 159 | +    public function getLastModified() { | 
                                                        |
| 160 | + $timestamp = $this->info->getMtime();  | 
                                                        |
| 161 | +        if (!empty($timestamp)) { | 
                                                        |
| 162 | + return (int)$timestamp;  | 
                                                        |
| 163 | + }  | 
                                                        |
| 164 | + return $timestamp;  | 
                                                        |
| 165 | + }  | 
                                                        |
| 166 | +  | 
                                                        |
| 167 | + /**  | 
                                                        |
| 168 | + * sets the last modification time of the file (mtime) to the value given  | 
                                                        |
| 169 | + * in the second parameter or to now if the second param is empty.  | 
                                                        |
| 170 | + * Even if the modification time is set to a custom value the access time is set to now.  | 
                                                        |
| 171 | + */  | 
                                                        |
| 172 | +    public function touch($mtime) { | 
                                                        |
| 173 | + $mtime = $this->sanitizeMtime($mtime);  | 
                                                        |
| 174 | + $this->fileView->touch($this->path, $mtime);  | 
                                                        |
| 175 | + $this->refreshInfo();  | 
                                                        |
| 176 | + }  | 
                                                        |
| 177 | +  | 
                                                        |
| 178 | + /**  | 
                                                        |
| 179 | + * Returns the ETag for a file  | 
                                                        |
| 180 | + *  | 
                                                        |
| 181 | + * An ETag is a unique identifier representing the current version of the  | 
                                                        |
| 182 | + * file. If the file changes, the ETag MUST change. The ETag is an  | 
                                                        |
| 183 | + * arbitrary string, but MUST be surrounded by double-quotes.  | 
                                                        |
| 184 | + *  | 
                                                        |
| 185 | + * Return null if the ETag can not effectively be determined  | 
                                                        |
| 186 | + *  | 
                                                        |
| 187 | + * @return string  | 
                                                        |
| 188 | + */  | 
                                                        |
| 189 | +    public function getETag() { | 
                                                        |
| 190 | + return '"' . $this->info->getEtag() . '"';  | 
                                                        |
| 191 | + }  | 
                                                        |
| 192 | +  | 
                                                        |
| 193 | + /**  | 
                                                        |
| 194 | + * Sets the ETag  | 
                                                        |
| 195 | + *  | 
                                                        |
| 196 | + * @param string $etag  | 
                                                        |
| 197 | + *  | 
                                                        |
| 198 | + * @return int file id of updated file or -1 on failure  | 
                                                        |
| 199 | + */  | 
                                                        |
| 200 | +    public function setETag($etag) { | 
                                                        |
| 201 | +        return $this->fileView->putFileInfo($this->path, array('etag' => $etag)); | 
                                                        |
| 202 | + }  | 
                                                        |
| 203 | +  | 
                                                        |
| 204 | + /**  | 
                                                        |
| 205 | + * Returns the size of the node, in bytes  | 
                                                        |
| 206 | + *  | 
                                                        |
| 207 | + * @return integer  | 
                                                        |
| 208 | + */  | 
                                                        |
| 209 | +    public function getSize() { | 
                                                        |
| 210 | + return $this->info->getSize();  | 
                                                        |
| 211 | + }  | 
                                                        |
| 212 | +  | 
                                                        |
| 213 | + /**  | 
                                                        |
| 214 | + * Returns the cache's file id  | 
                                                        |
| 215 | + *  | 
                                                        |
| 216 | + * @return int  | 
                                                        |
| 217 | + */  | 
                                                        |
| 218 | +    public function getId() { | 
                                                        |
| 219 | + return $this->info->getId();  | 
                                                        |
| 220 | + }  | 
                                                        |
| 221 | +  | 
                                                        |
| 222 | + /**  | 
                                                        |
| 223 | + * @return string|null  | 
                                                        |
| 224 | + */  | 
                                                        |
| 225 | +    public function getFileId() { | 
                                                        |
| 226 | +        if ($this->info->getId()) { | 
                                                        |
| 227 | + $instanceId = \OC_Util::getInstanceId();  | 
                                                        |
| 228 | +            $id = sprintf('%08d', $this->info->getId()); | 
                                                        |
| 229 | + return $id . $instanceId;  | 
                                                        |
| 230 | + }  | 
                                                        |
| 231 | +  | 
                                                        |
| 232 | + return null;  | 
                                                        |
| 233 | + }  | 
                                                        |
| 234 | +  | 
                                                        |
| 235 | + /**  | 
                                                        |
| 236 | + * @return integer  | 
                                                        |
| 237 | + */  | 
                                                        |
| 238 | +    public function getInternalFileId() { | 
                                                        |
| 239 | + return $this->info->getId();  | 
                                                        |
| 240 | + }  | 
                                                        |
| 241 | +  | 
                                                        |
| 242 | + /**  | 
                                                        |
| 243 | + * @param string $user  | 
                                                        |
| 244 | + * @return int  | 
                                                        |
| 245 | + */  | 
                                                        |
| 246 | +    public function getSharePermissions($user) { | 
                                                        |
| 247 | +  | 
                                                        |
| 248 | + // check of we access a federated share  | 
                                                        |
| 249 | +        if ($user !== null) { | 
                                                        |
| 250 | +            try { | 
                                                        |
| 251 | + $share = $this->shareManager->getShareByToken($user);  | 
                                                        |
| 252 | + return $share->getPermissions();  | 
                                                        |
| 253 | +            } catch (ShareNotFound $e) { | 
                                                        |
| 254 | + // ignore  | 
                                                        |
| 255 | + }  | 
                                                        |
| 256 | + }  | 
                                                        |
| 257 | +  | 
                                                        |
| 258 | +        try { | 
                                                        |
| 259 | + $storage = $this->info->getStorage();  | 
                                                        |
| 260 | +        } catch (StorageNotAvailableException $e) { | 
                                                        |
| 261 | + $storage = null;  | 
                                                        |
| 262 | + }  | 
                                                        |
| 263 | +  | 
                                                        |
| 264 | +        if ($storage && $storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { | 
                                                        |
| 265 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */  | 
                                                        |
| 266 | + $permissions = (int)$storage->getShare()->getPermissions();  | 
                                                        |
| 267 | +        } else { | 
                                                        |
| 268 | + $permissions = $this->info->getPermissions();  | 
                                                        |
| 269 | + }  | 
                                                        |
| 270 | +  | 
                                                        |
| 271 | + /*  | 
                                                        |
| 272 | 272 | * We can always share non moveable mount points with DELETE and UPDATE  | 
                                                        
| 273 | 273 | * Eventually we need to do this properly  | 
                                                        
| 274 | 274 | */  | 
                                                        
| 275 | - $mountpoint = $this->info->getMountPoint();  | 
                                                        |
| 276 | -		if (!($mountpoint instanceof MoveableMount)) { | 
                                                        |
| 277 | - $mountpointpath = $mountpoint->getMountPoint();  | 
                                                        |
| 278 | -			if (substr($mountpointpath, -1) === '/') { | 
                                                        |
| 279 | - $mountpointpath = substr($mountpointpath, 0, -1);  | 
                                                        |
| 280 | - }  | 
                                                        |
| 281 | -  | 
                                                        |
| 282 | -			if (!$mountpoint->getOption('readonly', false) && $mountpointpath === $this->info->getPath()) { | 
                                                        |
| 283 | - $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE;  | 
                                                        |
| 284 | - }  | 
                                                        |
| 285 | - }  | 
                                                        |
| 286 | -  | 
                                                        |
| 287 | - /*  | 
                                                        |
| 275 | + $mountpoint = $this->info->getMountPoint();  | 
                                                        |
| 276 | +        if (!($mountpoint instanceof MoveableMount)) { | 
                                                        |
| 277 | + $mountpointpath = $mountpoint->getMountPoint();  | 
                                                        |
| 278 | +            if (substr($mountpointpath, -1) === '/') { | 
                                                        |
| 279 | + $mountpointpath = substr($mountpointpath, 0, -1);  | 
                                                        |
| 280 | + }  | 
                                                        |
| 281 | +  | 
                                                        |
| 282 | +            if (!$mountpoint->getOption('readonly', false) && $mountpointpath === $this->info->getPath()) { | 
                                                        |
| 283 | + $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE;  | 
                                                        |
| 284 | + }  | 
                                                        |
| 285 | + }  | 
                                                        |
| 286 | +  | 
                                                        |
| 287 | + /*  | 
                                                        |
| 288 | 288 | * Files can't have create or delete permissions  | 
                                                        
| 289 | 289 | */  | 
                                                        
| 290 | -		if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { | 
                                                        |
| 291 | - $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE);  | 
                                                        |
| 292 | - }  | 
                                                        |
| 293 | -  | 
                                                        |
| 294 | - return $permissions;  | 
                                                        |
| 295 | - }  | 
                                                        |
| 296 | -  | 
                                                        |
| 297 | - /**  | 
                                                        |
| 298 | - * @param string $user  | 
                                                        |
| 299 | - * @return string  | 
                                                        |
| 300 | - */  | 
                                                        |
| 301 | -	public function getNoteFromShare($user) { | 
                                                        |
| 302 | -		if ($user === null) { | 
                                                        |
| 303 | - return '';  | 
                                                        |
| 304 | - }  | 
                                                        |
| 305 | -  | 
                                                        |
| 306 | - $types = [  | 
                                                        |
| 307 | - Share::SHARE_TYPE_USER,  | 
                                                        |
| 308 | - Share::SHARE_TYPE_GROUP,  | 
                                                        |
| 309 | - Share::SHARE_TYPE_CIRCLE,  | 
                                                        |
| 310 | - Share::SHARE_TYPE_ROOM  | 
                                                        |
| 311 | - ];  | 
                                                        |
| 312 | -  | 
                                                        |
| 313 | -		foreach ($types as $shareType) { | 
                                                        |
| 314 | - $shares = $this->shareManager->getSharedWith($user, $shareType, $this, -1);  | 
                                                        |
| 315 | -			foreach ($shares as $share) { | 
                                                        |
| 316 | - $note = $share->getNote();  | 
                                                        |
| 317 | -				if($share->getShareOwner() !== $user && !empty($note)) { | 
                                                        |
| 318 | - return $note;  | 
                                                        |
| 319 | - }  | 
                                                        |
| 320 | - }  | 
                                                        |
| 321 | - }  | 
                                                        |
| 322 | -  | 
                                                        |
| 323 | - return '';  | 
                                                        |
| 324 | - }  | 
                                                        |
| 325 | -  | 
                                                        |
| 326 | - /**  | 
                                                        |
| 327 | - * @return string  | 
                                                        |
| 328 | - */  | 
                                                        |
| 329 | -	public function getDavPermissions() { | 
                                                        |
| 330 | - $p = '';  | 
                                                        |
| 331 | -		if ($this->info->isShared()) { | 
                                                        |
| 332 | - $p .= 'S';  | 
                                                        |
| 333 | - }  | 
                                                        |
| 334 | -		if ($this->info->isShareable()) { | 
                                                        |
| 335 | - $p .= 'R';  | 
                                                        |
| 336 | - }  | 
                                                        |
| 337 | -		if ($this->info->isMounted()) { | 
                                                        |
| 338 | - $p .= 'M';  | 
                                                        |
| 339 | - }  | 
                                                        |
| 340 | -		if ($this->info->isReadable()) { | 
                                                        |
| 341 | - $p .= 'G';  | 
                                                        |
| 342 | - }  | 
                                                        |
| 343 | -		if ($this->info->isDeletable()) { | 
                                                        |
| 344 | - $p .= 'D';  | 
                                                        |
| 345 | - }  | 
                                                        |
| 346 | -		if ($this->info->isUpdateable()) { | 
                                                        |
| 347 | - $p .= 'NV'; // Renameable, Moveable  | 
                                                        |
| 348 | - }  | 
                                                        |
| 349 | -		if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { | 
                                                        |
| 350 | -			if ($this->info->isUpdateable()) { | 
                                                        |
| 351 | - $p .= 'W';  | 
                                                        |
| 352 | - }  | 
                                                        |
| 353 | -		} else { | 
                                                        |
| 354 | -			if ($this->info->isCreatable()) { | 
                                                        |
| 355 | - $p .= 'CK';  | 
                                                        |
| 356 | - }  | 
                                                        |
| 357 | - }  | 
                                                        |
| 358 | - return $p;  | 
                                                        |
| 359 | - }  | 
                                                        |
| 360 | -  | 
                                                        |
| 361 | -	public function getOwner() { | 
                                                        |
| 362 | - return $this->info->getOwner();  | 
                                                        |
| 363 | - }  | 
                                                        |
| 364 | -  | 
                                                        |
| 365 | -	protected function verifyPath() { | 
                                                        |
| 366 | -		try { | 
                                                        |
| 367 | - $fileName = basename($this->info->getPath());  | 
                                                        |
| 368 | - $this->fileView->verifyPath($this->path, $fileName);  | 
                                                        |
| 369 | -		} catch (\OCP\Files\InvalidPathException $ex) { | 
                                                        |
| 370 | - throw new InvalidPath($ex->getMessage());  | 
                                                        |
| 371 | - }  | 
                                                        |
| 372 | - }  | 
                                                        |
| 373 | -  | 
                                                        |
| 374 | - /**  | 
                                                        |
| 375 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE  | 
                                                        |
| 376 | - */  | 
                                                        |
| 377 | -	public function acquireLock($type) { | 
                                                        |
| 378 | - $this->fileView->lockFile($this->path, $type);  | 
                                                        |
| 379 | - }  | 
                                                        |
| 380 | -  | 
                                                        |
| 381 | - /**  | 
                                                        |
| 382 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE  | 
                                                        |
| 383 | - */  | 
                                                        |
| 384 | -	public function releaseLock($type) { | 
                                                        |
| 385 | - $this->fileView->unlockFile($this->path, $type);  | 
                                                        |
| 386 | - }  | 
                                                        |
| 387 | -  | 
                                                        |
| 388 | - /**  | 
                                                        |
| 389 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE  | 
                                                        |
| 390 | - */  | 
                                                        |
| 391 | -	public function changeLock($type) { | 
                                                        |
| 392 | - $this->fileView->changeLock($this->path, $type);  | 
                                                        |
| 393 | - }  | 
                                                        |
| 394 | -  | 
                                                        |
| 395 | -	public function getFileInfo() { | 
                                                        |
| 396 | - return $this->info;  | 
                                                        |
| 397 | - }  | 
                                                        |
| 398 | -  | 
                                                        |
| 399 | -	protected function sanitizeMtime($mtimeFromRequest) { | 
                                                        |
| 400 | - // In PHP 5.X "is_numeric" returns true for strings in hexadecimal  | 
                                                        |
| 401 | - // notation. This is no longer the case in PHP 7.X, so this check  | 
                                                        |
| 402 | - // ensures that strings with hexadecimal notations fail too in PHP 5.X.  | 
                                                        |
| 403 | -		$isHexadecimal = is_string($mtimeFromRequest) && preg_match('/^\s*0[xX]/', $mtimeFromRequest); | 
                                                        |
| 404 | -		if ($isHexadecimal || !is_numeric($mtimeFromRequest)) { | 
                                                        |
| 405 | -			throw new \InvalidArgumentException('X-OC-MTime header must be an integer (unix timestamp).'); | 
                                                        |
| 406 | - }  | 
                                                        |
| 407 | -  | 
                                                        |
| 408 | - return (int)$mtimeFromRequest;  | 
                                                        |
| 409 | - }  | 
                                                        |
| 290 | +        if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { | 
                                                        |
| 291 | + $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE);  | 
                                                        |
| 292 | + }  | 
                                                        |
| 293 | +  | 
                                                        |
| 294 | + return $permissions;  | 
                                                        |
| 295 | + }  | 
                                                        |
| 296 | +  | 
                                                        |
| 297 | + /**  | 
                                                        |
| 298 | + * @param string $user  | 
                                                        |
| 299 | + * @return string  | 
                                                        |
| 300 | + */  | 
                                                        |
| 301 | +    public function getNoteFromShare($user) { | 
                                                        |
| 302 | +        if ($user === null) { | 
                                                        |
| 303 | + return '';  | 
                                                        |
| 304 | + }  | 
                                                        |
| 305 | +  | 
                                                        |
| 306 | + $types = [  | 
                                                        |
| 307 | + Share::SHARE_TYPE_USER,  | 
                                                        |
| 308 | + Share::SHARE_TYPE_GROUP,  | 
                                                        |
| 309 | + Share::SHARE_TYPE_CIRCLE,  | 
                                                        |
| 310 | + Share::SHARE_TYPE_ROOM  | 
                                                        |
| 311 | + ];  | 
                                                        |
| 312 | +  | 
                                                        |
| 313 | +        foreach ($types as $shareType) { | 
                                                        |
| 314 | + $shares = $this->shareManager->getSharedWith($user, $shareType, $this, -1);  | 
                                                        |
| 315 | +            foreach ($shares as $share) { | 
                                                        |
| 316 | + $note = $share->getNote();  | 
                                                        |
| 317 | +                if($share->getShareOwner() !== $user && !empty($note)) { | 
                                                        |
| 318 | + return $note;  | 
                                                        |
| 319 | + }  | 
                                                        |
| 320 | + }  | 
                                                        |
| 321 | + }  | 
                                                        |
| 322 | +  | 
                                                        |
| 323 | + return '';  | 
                                                        |
| 324 | + }  | 
                                                        |
| 325 | +  | 
                                                        |
| 326 | + /**  | 
                                                        |
| 327 | + * @return string  | 
                                                        |
| 328 | + */  | 
                                                        |
| 329 | +    public function getDavPermissions() { | 
                                                        |
| 330 | + $p = '';  | 
                                                        |
| 331 | +        if ($this->info->isShared()) { | 
                                                        |
| 332 | + $p .= 'S';  | 
                                                        |
| 333 | + }  | 
                                                        |
| 334 | +        if ($this->info->isShareable()) { | 
                                                        |
| 335 | + $p .= 'R';  | 
                                                        |
| 336 | + }  | 
                                                        |
| 337 | +        if ($this->info->isMounted()) { | 
                                                        |
| 338 | + $p .= 'M';  | 
                                                        |
| 339 | + }  | 
                                                        |
| 340 | +        if ($this->info->isReadable()) { | 
                                                        |
| 341 | + $p .= 'G';  | 
                                                        |
| 342 | + }  | 
                                                        |
| 343 | +        if ($this->info->isDeletable()) { | 
                                                        |
| 344 | + $p .= 'D';  | 
                                                        |
| 345 | + }  | 
                                                        |
| 346 | +        if ($this->info->isUpdateable()) { | 
                                                        |
| 347 | + $p .= 'NV'; // Renameable, Moveable  | 
                                                        |
| 348 | + }  | 
                                                        |
| 349 | +        if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { | 
                                                        |
| 350 | +            if ($this->info->isUpdateable()) { | 
                                                        |
| 351 | + $p .= 'W';  | 
                                                        |
| 352 | + }  | 
                                                        |
| 353 | +        } else { | 
                                                        |
| 354 | +            if ($this->info->isCreatable()) { | 
                                                        |
| 355 | + $p .= 'CK';  | 
                                                        |
| 356 | + }  | 
                                                        |
| 357 | + }  | 
                                                        |
| 358 | + return $p;  | 
                                                        |
| 359 | + }  | 
                                                        |
| 360 | +  | 
                                                        |
| 361 | +    public function getOwner() { | 
                                                        |
| 362 | + return $this->info->getOwner();  | 
                                                        |
| 363 | + }  | 
                                                        |
| 364 | +  | 
                                                        |
| 365 | +    protected function verifyPath() { | 
                                                        |
| 366 | +        try { | 
                                                        |
| 367 | + $fileName = basename($this->info->getPath());  | 
                                                        |
| 368 | + $this->fileView->verifyPath($this->path, $fileName);  | 
                                                        |
| 369 | +        } catch (\OCP\Files\InvalidPathException $ex) { | 
                                                        |
| 370 | + throw new InvalidPath($ex->getMessage());  | 
                                                        |
| 371 | + }  | 
                                                        |
| 372 | + }  | 
                                                        |
| 373 | +  | 
                                                        |
| 374 | + /**  | 
                                                        |
| 375 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE  | 
                                                        |
| 376 | + */  | 
                                                        |
| 377 | +    public function acquireLock($type) { | 
                                                        |
| 378 | + $this->fileView->lockFile($this->path, $type);  | 
                                                        |
| 379 | + }  | 
                                                        |
| 380 | +  | 
                                                        |
| 381 | + /**  | 
                                                        |
| 382 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE  | 
                                                        |
| 383 | + */  | 
                                                        |
| 384 | +    public function releaseLock($type) { | 
                                                        |
| 385 | + $this->fileView->unlockFile($this->path, $type);  | 
                                                        |
| 386 | + }  | 
                                                        |
| 387 | +  | 
                                                        |
| 388 | + /**  | 
                                                        |
| 389 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE  | 
                                                        |
| 390 | + */  | 
                                                        |
| 391 | +    public function changeLock($type) { | 
                                                        |
| 392 | + $this->fileView->changeLock($this->path, $type);  | 
                                                        |
| 393 | + }  | 
                                                        |
| 394 | +  | 
                                                        |
| 395 | +    public function getFileInfo() { | 
                                                        |
| 396 | + return $this->info;  | 
                                                        |
| 397 | + }  | 
                                                        |
| 398 | +  | 
                                                        |
| 399 | +    protected function sanitizeMtime($mtimeFromRequest) { | 
                                                        |
| 400 | + // In PHP 5.X "is_numeric" returns true for strings in hexadecimal  | 
                                                        |
| 401 | + // notation. This is no longer the case in PHP 7.X, so this check  | 
                                                        |
| 402 | + // ensures that strings with hexadecimal notations fail too in PHP 5.X.  | 
                                                        |
| 403 | +        $isHexadecimal = is_string($mtimeFromRequest) && preg_match('/^\s*0[xX]/', $mtimeFromRequest); | 
                                                        |
| 404 | +        if ($isHexadecimal || !is_numeric($mtimeFromRequest)) { | 
                                                        |
| 405 | +            throw new \InvalidArgumentException('X-OC-MTime header must be an integer (unix timestamp).'); | 
                                                        |
| 406 | + }  | 
                                                        |
| 407 | +  | 
                                                        |
| 408 | + return (int)$mtimeFromRequest;  | 
                                                        |
| 409 | + }  | 
                                                        |
| 410 | 410 | |
| 411 | 411 | }  | 
                                                        
@@ -136,10 +136,10 @@ discard block  | 
                                                    ||
| 136 | 136 | // verify path of the target  | 
                                                        
| 137 | 137 | $this->verifyPath();  | 
                                                        
| 138 | 138 | |
| 139 | - $newPath = $parentPath . '/' . $newName;  | 
                                                        |
| 139 | + $newPath = $parentPath.'/'.$newName;  | 
                                                        |
| 140 | 140 | |
| 141 | 141 |  		if (!$this->fileView->rename($this->path, $newPath)) { | 
                                                        
| 142 | -			throw new \Sabre\DAV\Exception('Failed to rename '. $this->path . ' to ' . $newPath); | 
                                                        |
| 142 | +			throw new \Sabre\DAV\Exception('Failed to rename '.$this->path.' to '.$newPath); | 
                                                        |
| 143 | 143 | }  | 
                                                        
| 144 | 144 | |
| 145 | 145 | $this->path = $newPath;  | 
                                                        
@@ -159,7 +159,7 @@ discard block  | 
                                                    ||
| 159 | 159 |  	public function getLastModified() { | 
                                                        
| 160 | 160 | $timestamp = $this->info->getMtime();  | 
                                                        
| 161 | 161 |  		if (!empty($timestamp)) { | 
                                                        
| 162 | - return (int)$timestamp;  | 
                                                        |
| 162 | + return (int) $timestamp;  | 
                                                        |
| 163 | 163 | }  | 
                                                        
| 164 | 164 | return $timestamp;  | 
                                                        
| 165 | 165 | }  | 
                                                        
@@ -187,7 +187,7 @@ discard block  | 
                                                    ||
| 187 | 187 | * @return string  | 
                                                        
| 188 | 188 | */  | 
                                                        
| 189 | 189 |  	public function getETag() { | 
                                                        
| 190 | - return '"' . $this->info->getEtag() . '"';  | 
                                                        |
| 190 | + return '"'.$this->info->getEtag().'"';  | 
                                                        |
| 191 | 191 | }  | 
                                                        
| 192 | 192 | |
| 193 | 193 | /**  | 
                                                        
@@ -226,7 +226,7 @@ discard block  | 
                                                    ||
| 226 | 226 |  		if ($this->info->getId()) { | 
                                                        
| 227 | 227 | $instanceId = \OC_Util::getInstanceId();  | 
                                                        
| 228 | 228 |  			$id = sprintf('%08d', $this->info->getId()); | 
                                                        
| 229 | - return $id . $instanceId;  | 
                                                        |
| 229 | + return $id.$instanceId;  | 
                                                        |
| 230 | 230 | }  | 
                                                        
| 231 | 231 | |
| 232 | 232 | return null;  | 
                                                        
@@ -263,7 +263,7 @@ discard block  | 
                                                    ||
| 263 | 263 | |
| 264 | 264 |  		if ($storage && $storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { | 
                                                        
| 265 | 265 | /** @var \OCA\Files_Sharing\SharedStorage $storage */  | 
                                                        
| 266 | - $permissions = (int)$storage->getShare()->getPermissions();  | 
                                                        |
| 266 | + $permissions = (int) $storage->getShare()->getPermissions();  | 
                                                        |
| 267 | 267 |  		} else { | 
                                                        
| 268 | 268 | $permissions = $this->info->getPermissions();  | 
                                                        
| 269 | 269 | }  | 
                                                        
@@ -314,7 +314,7 @@ discard block  | 
                                                    ||
| 314 | 314 | $shares = $this->shareManager->getSharedWith($user, $shareType, $this, -1);  | 
                                                        
| 315 | 315 |  			foreach ($shares as $share) { | 
                                                        
| 316 | 316 | $note = $share->getNote();  | 
                                                        
| 317 | -				if($share->getShareOwner() !== $user && !empty($note)) { | 
                                                        |
| 317 | +				if ($share->getShareOwner() !== $user && !empty($note)) { | 
                                                        |
| 318 | 318 | return $note;  | 
                                                        
| 319 | 319 | }  | 
                                                        
| 320 | 320 | }  | 
                                                        
@@ -405,7 +405,7 @@ discard block  | 
                                                    ||
| 405 | 405 |  			throw new \InvalidArgumentException('X-OC-MTime header must be an integer (unix timestamp).'); | 
                                                        
| 406 | 406 | }  | 
                                                        
| 407 | 407 | |
| 408 | - return (int)$mtimeFromRequest;  | 
                                                        |
| 408 | + return (int) $mtimeFromRequest;  | 
                                                        |
| 409 | 409 | }  | 
                                                        
| 410 | 410 | |
| 411 | 411 | }  |