Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2022-10-27 13:29:17 +0300
committerGitHub <noreply@github.com>2022-10-27 13:29:17 +0300
commit220d71d99798df9d64873be0d67a35989258754e (patch)
tree17e373dcb16d4e2267d5413501d5519a44f9a726
parenta117878240a27fe8e400b04e97a5a1d4be35e42c (diff)
parent8cf947f0dae66649359aac190f1bcd8b5c37cd6b (diff)
Merge pull request #34410 from nextcloud/backport/33566/stable24
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/FileTest.php4
-rw-r--r--lib/private/Files/Storage/Local.php9
-rw-r--r--lib/private/Files/View.php12
-rw-r--r--tests/lib/Files/ViewTest.php19
4 files changed, 40 insertions, 4 deletions
diff --git a/apps/dav/tests/unit/Connector/Sabre/FileTest.php b/apps/dav/tests/unit/Connector/Sabre/FileTest.php
index 9870a62845c..81d1f71aedf 100644
--- a/apps/dav/tests/unit/Connector/Sabre/FileTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/FileTest.php
@@ -1151,7 +1151,7 @@ class FileTest extends TestCase {
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL,
- 'type' => FileInfo::TYPE_FOLDER,
+ 'type' => FileInfo::TYPE_FILE,
], null);
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@@ -1172,7 +1172,7 @@ class FileTest extends TestCase {
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL,
- 'type' => FileInfo::TYPE_FOLDER,
+ 'type' => FileInfo::TYPE_FILE,
], null);
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php
index d637b3d194f..990ebdc20ab 100644
--- a/lib/private/Files/Storage/Local.php
+++ b/lib/private/Files/Storage/Local.php
@@ -157,6 +157,9 @@ class Local extends \OC\Files\Storage\Common {
public function stat($path) {
$fullPath = $this->getSourcePath($path);
clearstatcache(true, $fullPath);
+ if (!file_exists($fullPath)) {
+ return false;
+ }
$statResult = @stat($fullPath);
if (PHP_INT_SIZE === 4 && $statResult && !$this->is_dir($path)) {
$filesize = $this->filesize($path);
@@ -373,8 +376,12 @@ class Local extends \OC\Files\Storage\Common {
}
public function fopen($path, $mode) {
+ $sourcePath = $this->getSourcePath($path);
+ if (!file_exists($sourcePath) && $mode === 'r') {
+ return false;
+ }
$oldMask = umask(022);
- $result = fopen($this->getSourcePath($path), $mode);
+ $result = @fopen($sourcePath, $mode);
umask($oldMask);
return $result;
}
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index c209c8594f7..a909cf46769 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -1007,7 +1007,17 @@ class View {
\OC::$server->getLogger()->info('Trying to open a file with a mode other than "r" or "w" can cause severe performance issues with some backends');
}
- return $this->basicOperation('fopen', $path, $hooks, $mode);
+ $handle = $this->basicOperation('fopen', $path, $hooks, $mode);
+ if (!is_resource($handle) && $mode === 'r') {
+ // trying to read a file that isn't on disk, check if the cache is out of sync and rescan if needed
+ $mount = $this->getMount($path);
+ $internalPath = $mount->getInternalPath($this->getAbsolutePath($path));
+ $storage = $mount->getStorage();
+ if ($storage->getCache()->inCache($internalPath) && !$storage->file_exists($path)) {
+ $this->writeUpdate($storage, $internalPath);
+ }
+ }
+ return $handle;
}
/**
diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php
index 7b735720ff1..d33007cfa8a 100644
--- a/tests/lib/Files/ViewTest.php
+++ b/tests/lib/Files/ViewTest.php
@@ -2722,4 +2722,23 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals(25, $info->getUploadTime());
$this->assertEquals(0, $info->getCreationTime());
}
+
+ public function testFopenGone() {
+ $storage = new Temporary([]);
+ $scanner = $storage->getScanner();
+ $storage->file_put_contents('foo.txt', 'bar');
+ $scanner->scan('');
+ $cache = $storage->getCache();
+
+ Filesystem::mount($storage, [], '/test/');
+ $view = new View('/test');
+
+ $storage->unlink('foo.txt');
+
+ $this->assertTrue($cache->inCache('foo.txt'));
+
+ $this->assertFalse($view->fopen('foo.txt', 'r'));
+
+ $this->assertFalse($cache->inCache('foo.txt'));
+ }
}