]> source.dussan.org Git - nextcloud-server.git/commitdiff
Respect locked files, surface correct exception.
authorringmaster <epithet@gmail.com>
Sat, 24 May 2014 13:18:24 +0000 (09:18 -0400)
committerThomas Müller <thomas.mueller@tmit.eu>
Wed, 4 Jun 2014 05:55:44 +0000 (07:55 +0200)
lib/private/connector/sabre/exception/filelocked.php [new file with mode: 0644]
lib/private/connector/sabre/file.php

diff --git a/lib/private/connector/sabre/exception/filelocked.php b/lib/private/connector/sabre/exception/filelocked.php
new file mode 100644 (file)
index 0000000..c00fd78
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Owen Winkler
+ * @copyright 2013 Owen Winkler <owen@owncloud.com>
+ *
+ */
+
+class OC_Connector_Sabre_Exception_FileLocked extends Sabre_DAV_Exception {
+
+       public function __construct($message = "", $code = 0, Exception $previous = null) {
+               if($previous instanceof \OCP\Files\LockNotAcquiredException) {
+                       $message = sprintf('Target file %s is locked by another process. %s', $previous->path, $previous->getMessage());
+               }
+               parent::__construct($message, $code, $previous);
+       }
+
+       /**
+        * Returns the HTTP statuscode for this exception
+        *
+        * @return int
+        */
+       public function getHTTPCode() {
+
+               return 503;
+       }
+}
index 8a16ba55e7a92d03290892464220ec76ce28572f..fc57c82624efab4d9fbe6dcc03f64ad67ce4415b 100644 (file)
@@ -97,15 +97,24 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
                        // the path for the file was not valid
                        // TODO: find proper http status code for this case
                        throw new Sabre_DAV_Exception_Forbidden($e->getMessage());
+               } catch (\OCP\Files\LockNotAcquiredException $e) {
+                       // the file is currently being written to by another process
+                       throw new OC_Connector_Sabre_Exception_FileLocked(sprintf('Target file %s is locked by another process. %s', $e->path, $e->getMessage()), $e->getCode(), $e);
                }
 
                // rename to correct path
-               $renameOkay = $this->fileView->rename($partpath, $this->path);
-               $fileExists = $this->fileView->file_exists($this->path);
-               if ($renameOkay === false || $fileExists === false) {
-                       \OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR);
-                       $this->fileView->unlink($partpath);
-                       throw new Sabre_DAV_Exception('Could not rename part file to final file');
+               try {
+                       $renameOkay = $this->fileView->rename($partpath, $this->path);
+                       $fileExists = $this->fileView->file_exists($this->path);
+                       if ($renameOkay === false || $fileExists === false) {
+                               \OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR);
+                               $this->fileView->unlink($partpath);
+                               throw new Sabre_DAV_Exception('Could not rename part file to final file');
+                       }
+               }
+               catch (\OCP\Files\LockNotAcquiredException $e) {
+                       // the file is currently being written to by another process
+                       throw new OC_Connector_Sabre_Exception_FileLocked($e->getMessage(), $e->getCode(), $e);
                }
 
                // allow sync clients to send the mtime along in a header