From 415cf9278446b4422ef7633d944ca0f3aebcd301 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 27 Oct 2015 12:10:23 +0100 Subject: [PATCH 1/2] Fix thrashbin wrapper when no user is loggedin --- apps/files_trashbin/lib/storage.php | 5 +++-- apps/files_trashbin/tests/storage.php | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/files_trashbin/lib/storage.php b/apps/files_trashbin/lib/storage.php index 0e42df1e967..becde5e635b 100644 --- a/apps/files_trashbin/lib/storage.php +++ b/apps/files_trashbin/lib/storage.php @@ -26,6 +26,7 @@ namespace OCA\Files_Trashbin; use OC\Files\Filesystem; use OC\Files\Storage\Wrapper\Wrapper; +use OC\Files\View; use OCP\IUserManager; class Storage extends Wrapper { @@ -151,8 +152,8 @@ class Storage extends Wrapper { $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path); $result = true; - if (!isset($this->deletedFiles[$normalized])) { - $view = Filesystem::getView(); + $view = Filesystem::getView(); + if (!isset($this->deletedFiles[$normalized]) && $view instanceof View) { $this->deletedFiles[$normalized] = $normalized; if ($filesPath = $view->getRelativePath($normalized)) { $filesPath = trim($filesPath, '/'); diff --git a/apps/files_trashbin/tests/storage.php b/apps/files_trashbin/tests/storage.php index 3ebbbc3ec9d..abd0810f212 100644 --- a/apps/files_trashbin/tests/storage.php +++ b/apps/files_trashbin/tests/storage.php @@ -531,4 +531,14 @@ class Storage extends \Test\TestCase { ['/schiesbn/', '/test.txt', false, false], ]; } + + /** + * Test that deleting a file doesn't error when nobody is logged in + */ + public function testSingleStorageDeleteFileLoggedOut() { + $this->logout(); + + $this->assertTrue($this->userView->file_exists('test.txt')); + $this->userView->unlink('test.txt'); + } } From 5b2957bad14adb7895f75dd27cafd2257e24e78a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 11 Dec 2015 14:29:38 +0100 Subject: [PATCH 2/2] skip test if we cant use the filesystem when not logged in --- apps/files_trashbin/tests/storage.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/files_trashbin/tests/storage.php b/apps/files_trashbin/tests/storage.php index abd0810f212..387bb20c6d4 100644 --- a/apps/files_trashbin/tests/storage.php +++ b/apps/files_trashbin/tests/storage.php @@ -538,7 +538,10 @@ class Storage extends \Test\TestCase { public function testSingleStorageDeleteFileLoggedOut() { $this->logout(); - $this->assertTrue($this->userView->file_exists('test.txt')); - $this->userView->unlink('test.txt'); + if (!$this->userView->file_exists('test.txt')) { + $this->markTestSkipped('Skipping since the current home storage backend requires the user to logged in'); + } else { + $this->userView->unlink('test.txt'); + } } }