4848use OCP \Lock \ILockingProvider ;
4949use OCP \Lock \LockedException ;
5050use Psr \Log \LoggerInterface ;
51- use Sabre \DAV \Exception ;
5251use Sabre \DAV \Exception \BadRequest ;
5352use Sabre \DAV \Exception \Locked ;
5453use Sabre \DAV \Exception \NotFound ;
@@ -103,19 +102,33 @@ public function __construct(View $view, FileInfo $info, ?CachingTree $tree = nul
103102 * @param string $name Name of the file
104103 * @param resource|string $data Initial payload
105104 * @return null|string
105+ * @throws Exception\EntityTooLarge
106106 * @throws Exception\UnsupportedMediaType
107107 * @throws FileLocked
108108 * @throws InvalidPath
109- * @throws Exception
110- * @throws BadRequest
111- * @throws Exception\Forbidden
112- * @throws ServiceUnavailable
109+ * @throws \Sabre\DAV\ Exception
110+ * @throws \Sabre\DAV\Exception\ BadRequest
111+ * @throws \Sabre\DAV\ Exception\Forbidden
112+ * @throws \Sabre\DAV\Exception\ ServiceUnavailable
113113 */
114114 public function createFile ($ name , $ data = null ) {
115115 try {
116- // For non-chunked upload it is enough to check if we can create a new file
117- if (!$ this ->fileView ->isCreatable ($ this ->path )) {
118- throw new Exception \Forbidden ();
116+ // for chunked upload also updating a existing file is a "createFile"
117+ // because we create all the chunks before re-assemble them to the existing file.
118+ if (isset ($ _SERVER ['HTTP_OC_CHUNKED ' ])) {
119+
120+ // exit if we can't create a new file and we don't updatable existing file
121+ $ chunkInfo = \OC_FileChunking::decodeName ($ name );
122+ if (!$ this ->fileView ->isCreatable ($ this ->path ) &&
123+ !$ this ->fileView ->isUpdatable ($ this ->path . '/ ' . $ chunkInfo ['name ' ])
124+ ) {
125+ throw new \Sabre \DAV \Exception \Forbidden ();
126+ }
127+ } else {
128+ // For non-chunked upload it is enough to check if we can create a new file
129+ if (!$ this ->fileView ->isCreatable ($ this ->path )) {
130+ throw new \Sabre \DAV \Exception \Forbidden ();
131+ }
119132 }
120133
121134 $ this ->fileView ->verifyPath ($ this ->path , $ name );
@@ -140,8 +153,8 @@ public function createFile($name, $data = null) {
140153 $ this ->fileView ->unlockFile ($ path . '.upload.part ' , ILockingProvider::LOCK_EXCLUSIVE );
141154 $ node ->releaseLock (ILockingProvider::LOCK_SHARED );
142155 return $ result ;
143- } catch (StorageNotAvailableException $ e ) {
144- throw new ServiceUnavailable ($ e ->getMessage ());
156+ } catch (\ OCP \ Files \ StorageNotAvailableException $ e ) {
157+ throw new \ Sabre \ DAV \ Exception \ ServiceUnavailable ($ e ->getMessage (), $ e -> getCode (), $ e );
145158 } catch (InvalidPathException $ ex ) {
146159 throw new InvalidPath ($ ex ->getMessage (), false , $ ex );
147160 } catch (ForbiddenException $ ex ) {
@@ -157,22 +170,22 @@ public function createFile($name, $data = null) {
157170 * @param string $name
158171 * @throws FileLocked
159172 * @throws InvalidPath
160- * @throws Exception\Forbidden
161- * @throws ServiceUnavailable
173+ * @throws \Sabre\DAV\ Exception\Forbidden
174+ * @throws \Sabre\DAV\Exception\ ServiceUnavailable
162175 */
163176 public function createDirectory ($ name ) {
164177 try {
165178 if (!$ this ->info ->isCreatable ()) {
166- throw new Exception \Forbidden ();
179+ throw new \ Sabre \ DAV \ Exception \Forbidden ();
167180 }
168181
169182 $ this ->fileView ->verifyPath ($ this ->path , $ name );
170183 $ newPath = $ this ->path . '/ ' . $ name ;
171184 if (!$ this ->fileView ->mkdir ($ newPath )) {
172- throw new Exception \Forbidden ('Could not create directory ' . $ newPath );
185+ throw new \ Sabre \ DAV \ Exception \Forbidden ('Could not create directory ' . $ newPath );
173186 }
174- } catch (StorageNotAvailableException $ e ) {
175- throw new ServiceUnavailable ($ e ->getMessage ());
187+ } catch (\ OCP \ Files \ StorageNotAvailableException $ e ) {
188+ throw new \ Sabre \ DAV \ Exception \ ServiceUnavailable ($ e ->getMessage ());
176189 } catch (InvalidPathException $ ex ) {
177190 throw new InvalidPath ($ ex ->getMessage ());
178191 } catch (ForbiddenException $ ex ) {
@@ -190,7 +203,7 @@ public function createDirectory($name) {
190203 * @return \Sabre\DAV\INode
191204 * @throws InvalidPath
192205 * @throws \Sabre\DAV\Exception\NotFound
193- * @throws ServiceUnavailable
206+ * @throws \Sabre\DAV\Exception\ ServiceUnavailable
194207 */
195208 public function getChild ($ name , $ info = null ) {
196209 if (!$ this ->info ->isReadable ()) {
@@ -203,12 +216,12 @@ public function getChild($name, $info = null) {
203216 try {
204217 $ this ->fileView ->verifyPath ($ this ->path , $ name );
205218 $ info = $ this ->fileView ->getFileInfo ($ path );
206- } catch (StorageNotAvailableException $ e ) {
207- throw new ServiceUnavailable ($ e ->getMessage ());
219+ } catch (\ OCP \ Files \ StorageNotAvailableException $ e ) {
220+ throw new \ Sabre \ DAV \ Exception \ ServiceUnavailable ($ e ->getMessage ());
208221 } catch (InvalidPathException $ ex ) {
209222 throw new InvalidPath ($ ex ->getMessage ());
210223 } catch (ForbiddenException $ e ) {
211- throw new Exception \Forbidden ();
224+ throw new \ Sabre \ DAV \ Exception \Forbidden ();
212225 }
213226 }
214227
@@ -285,17 +298,17 @@ public function childExists($name) {
285298 *
286299 * @return void
287300 * @throws FileLocked
288- * @throws Exception\Forbidden
301+ * @throws \Sabre\DAV\ Exception\Forbidden
289302 */
290303 public function delete () {
291304 if ($ this ->path === '' || $ this ->path === '/ ' || !$ this ->info ->isDeletable ()) {
292- throw new Exception \Forbidden ();
305+ throw new \ Sabre \ DAV \ Exception \Forbidden ();
293306 }
294307
295308 try {
296309 if (!$ this ->fileView ->rmdir ($ this ->path )) {
297310 // assume it wasn't possible to remove due to permission issue
298- throw new Exception \Forbidden ();
311+ throw new \ Sabre \ DAV \ Exception \Forbidden ();
299312 }
300313 } catch (ForbiddenException $ ex ) {
301314 throw new Forbidden ($ ex ->getMessage (), $ ex ->getRetry ());
@@ -330,7 +343,7 @@ public function getQuotaInfo() {
330343 } catch (\OCP \Files \NotFoundException $ e ) {
331344 $ logger ->warning ("error while getting quota into " , ['exception ' => $ e ]);
332345 return [0 , 0 ];
333- } catch (StorageNotAvailableException $ e ) {
346+ } catch (\ OCP \ Files \ StorageNotAvailableException $ e ) {
334347 $ logger ->warning ("error while getting quota into " , ['exception ' => $ e ]);
335348 return [0 , 0 ];
336349 } catch (NotPermittedException $ e ) {
@@ -362,7 +375,7 @@ public function getQuotaInfo() {
362375 * @throws ServiceUnavailable
363376 * @throws Forbidden
364377 * @throws FileLocked
365- * @throws Exception\Forbidden
378+ * @throws \Sabre\DAV\ Exception\Forbidden
366379 */
367380 public function moveInto ($ targetName , $ fullSourcePath , INode $ sourceNode ) {
368381 if (!$ sourceNode instanceof Node) {
@@ -386,7 +399,7 @@ public function moveInto($targetName, $fullSourcePath, INode $sourceNode) {
386399 // at getNodeForPath we also check the path for isForbiddenFileOrDir
387400 // with that we have covered both source and destination
388401 if ($ sourceNode instanceof Directory && $ targetNodeExists ) {
389- throw new Exception \Forbidden ('Could not copy directory ' . $ sourceNode ->getName () . ', target exists ' );
402+ throw new \ Sabre \ DAV \ Exception \Forbidden ('Could not copy directory ' . $ sourceNode ->getName () . ', target exists ' );
390403 }
391404
392405 [$ sourceDir ,] = \Sabre \Uri \split ($ sourceNode ->getPath ());
@@ -407,19 +420,19 @@ public function moveInto($targetName, $fullSourcePath, INode $sourceNode) {
407420 if ($ targetNodeExists || $ sameFolder ) {
408421 // note that renaming a share mount point is always allowed
409422 if (!$ this ->fileView ->isUpdatable ($ destinationDir ) && !$ isMovableMount ) {
410- throw new Exception \Forbidden ();
423+ throw new \ Sabre \ DAV \ Exception \Forbidden ();
411424 }
412425 } else {
413426 if (!$ this ->fileView ->isCreatable ($ destinationDir )) {
414- throw new Exception \Forbidden ();
427+ throw new \ Sabre \ DAV \ Exception \Forbidden ();
415428 }
416429 }
417430
418431 if (!$ sameFolder ) {
419432 // moving to a different folder, source will be gone, like a deletion
420433 // note that moving a share mount point is always allowed
421434 if (!$ this ->fileView ->isDeletable ($ sourcePath ) && !$ isMovableMount ) {
422- throw new Exception \Forbidden ();
435+ throw new \ Sabre \ DAV \ Exception \Forbidden ();
423436 }
424437 }
425438
@@ -432,7 +445,7 @@ public function moveInto($targetName, $fullSourcePath, INode $sourceNode) {
432445
433446 $ renameOkay = $ this ->fileView ->rename ($ sourcePath , $ destinationPath );
434447 if (!$ renameOkay ) {
435- throw new Exception \Forbidden ('' );
448+ throw new \ Sabre \ DAV \ Exception \Forbidden ('' );
436449 }
437450 } catch (StorageNotAvailableException $ e ) {
438451 throw new ServiceUnavailable ($ e ->getMessage ());
@@ -452,7 +465,7 @@ public function copyInto($targetName, $sourcePath, INode $sourceNode) {
452465 $ sourcePath = $ sourceNode ->getPath ();
453466
454467 if (!$ this ->fileView ->isCreatable ($ this ->getPath ())) {
455- throw new Exception \Forbidden ();
468+ throw new \ Sabre \ DAV \ Exception \Forbidden ();
456469 }
457470
458471 try {
0 commit comments