summaryrefslogtreecommitdiffstats
path: root/lib/private/connector
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/connector')
-rw-r--r--lib/private/connector/sabre/exception/filelocked.php28
-rw-r--r--lib/private/connector/sabre/file.php21
2 files changed, 43 insertions, 6 deletions
diff --git a/lib/private/connector/sabre/exception/filelocked.php b/lib/private/connector/sabre/exception/filelocked.php
new file mode 100644
index 00000000000..ec200f847e3
--- /dev/null
+++ b/lib/private/connector/sabre/exception/filelocked.php
@@ -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.', $previous->path);
+ }
+ parent::__construct($message, $code, $previous);
+ }
+
+ /**
+ * Returns the HTTP status code for this exception
+ *
+ * @return int
+ */
+ public function getHTTPCode() {
+
+ return 503;
+ }
+}
diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php
index 8a16ba55e7a..48287b1e503 100644
--- a/lib/private/connector/sabre/file.php
+++ b/lib/private/connector/sabre/file.php
@@ -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($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