diff options
author | ringmaster <epithet@gmail.com> | 2014-05-24 09:18:24 -0400 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-06-04 07:55:44 +0200 |
commit | 6b94732bdfdc59836968240e0f4682b964a5253a (patch) | |
tree | 3c6a2d83accbaa2fc1ce7b31c00372530176b20b /lib/private/connector/sabre | |
parent | 428510a4f8109dd8aea61871de2b49b4bbd64078 (diff) | |
download | nextcloud-server-6b94732bdfdc59836968240e0f4682b964a5253a.tar.gz nextcloud-server-6b94732bdfdc59836968240e0f4682b964a5253a.zip |
Respect locked files, surface correct exception.
Diffstat (limited to 'lib/private/connector/sabre')
-rw-r--r-- | lib/private/connector/sabre/exception/filelocked.php | 28 | ||||
-rw-r--r-- | lib/private/connector/sabre/file.php | 21 |
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..c00fd783529 --- /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. %s', $previous->path, $previous->getMessage()); + } + parent::__construct($message, $code, $previous); + } + + /** + * Returns the HTTP statuscode 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..fc57c82624e 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(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 |