Skip to content

Commit 7cb467b

Browse files
authored
Merge pull request #9355 from nextcloud/dav-upload-lock
only allow a single concurrent dav write to a file
2 parents ceb6746 + dd1b079 commit 7cb467b

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

apps/dav/lib/Connector/Sabre/Directory.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* along with this program. If not, see <http://www.gnu.org/licenses/>
2929
*
3030
*/
31+
3132
namespace OCA\DAV\Connector\Sabre;
3233

3334
use OC\Files\View;
@@ -147,8 +148,16 @@ public function createFile($name, $data = null) {
147148
$info = new \OC\Files\FileInfo($path, null, null, [], null);
148149
}
149150
$node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info);
151+
152+
// only allow 1 process to upload a file at once but still allow reading the file while writing the part file
150153
$node->acquireLock(ILockingProvider::LOCK_SHARED);
151-
return $node->put($data);
154+
$this->fileView->lockFile($path . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE);
155+
156+
$result = $node->put($data);
157+
158+
$this->fileView->unlockFile($path . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE);
159+
$node->releaseLock(ILockingProvider::LOCK_SHARED);
160+
return $result;
152161
} catch (\OCP\Files\StorageNotAvailableException $e) {
153162
throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage(), $e->getCode(), $e);
154163
} catch (InvalidPathException $ex) {

0 commit comments

Comments
 (0)