From 67dd4b018abde6523c283738411590cf85f5308d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 28 May 2019 13:05:20 +0200 Subject: [PATCH] Check for free space on touch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/private/Files/Node/Folder.php | 7 ++++--- lib/private/Files/Storage/Wrapper/Quota.php | 10 ++++++++++ tests/lib/Files/Storage/Wrapper/QuotaTest.php | 5 +++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index ebf67e47a2..1e9088a7c1 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -181,14 +181,15 @@ class Folder extends Node implements \OCP\Files\Folder { $nonExisting = new NonExistingFile($this->root, $this->view, $fullPath); $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); $this->root->emit('\OC\Files', 'preCreate', array($nonExisting)); - $this->view->touch($fullPath); + if (!$this->view->touch($fullPath)) { + throw new NotPermittedException('Could not create path'); + } $node = new File($this->root, $this->view, $fullPath); $this->root->emit('\OC\Files', 'postWrite', array($node)); $this->root->emit('\OC\Files', 'postCreate', array($node)); return $node; - } else { - throw new NotPermittedException('No create permission for path'); } + throw new NotPermittedException('No create permission for path'); } /** diff --git a/lib/private/Files/Storage/Wrapper/Quota.php b/lib/private/Files/Storage/Wrapper/Quota.php index 4cbe918959..492b5aba43 100644 --- a/lib/private/Files/Storage/Wrapper/Quota.php +++ b/lib/private/Files/Storage/Wrapper/Quota.php @@ -209,4 +209,14 @@ class Quota extends Wrapper { return parent::mkdir($path); } + + public function touch($path, $mtime = null) { + $free = $this->free_space($path); + if ($free === 0.0) { + return false; + } + + return parent::touch($path, $mtime); + } + } diff --git a/tests/lib/Files/Storage/Wrapper/QuotaTest.php b/tests/lib/Files/Storage/Wrapper/QuotaTest.php index adfd60d053..0b80467fcc 100644 --- a/tests/lib/Files/Storage/Wrapper/QuotaTest.php +++ b/tests/lib/Files/Storage/Wrapper/QuotaTest.php @@ -213,4 +213,9 @@ class QuotaTest extends \Test\Files\Storage\Storage { $instance = $this->getLimitedStorage(0.0); $this->assertFalse($instance->mkdir('foobar')); } + + public function testNoTouchQuotaZero() { + $instance = $this->getLimitedStorage(0.0); + $this->assertFalse($instance->touch('foobar')); + } }