Respect locked files, surface correct exception.

This commit is contained in:
ringmaster 2014-05-24 09:18:24 -04:00 committed by Thomas Müller
parent 428510a4f8
commit 6b94732bdf
2 changed files with 43 additions and 6 deletions

View File

@ -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;
}
}

View 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