Skip to content

Commit

Permalink
fix: file size in cache is set back to zero if empty content is writt…
Browse files Browse the repository at this point in the history
…en to a non-empty file
  • Loading branch information
DeepDiver1975 committed Jul 16, 2021
1 parent d8dc837 commit 53196ce
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/39016
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: Update file size in cache after writing empty content to non-empty file

https://github.com/owncloud/core/pull/39016
2 changes: 1 addition & 1 deletion lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ private function basicOperation($operation, $path, $hooks = [], $extraParam = nu
throw $e;
}

if ($result) {
if ($result !== false) {
if (\in_array('delete', $hooks)) {
$this->removeUpdate($storage, $internalPath);
}
Expand Down
27 changes: 25 additions & 2 deletions tests/lib/Files/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected function tearDown(): void {
\OC_User::setUserId($this->user);
foreach ($this->storages as $storage) {
$cache = $storage->getCache();
$ids = $cache->getAll();
$cache->getAll();
$cache->clear();
}

Expand Down Expand Up @@ -1884,7 +1884,7 @@ function () use ($view, $lockedPath, &$lockTypeDuring, $operation) {
$lockTypeDuring = $this->getFileLockType($view, $lockedPath);

if ($operation === 'fopen') {
return \fopen('data://text/plain,test', 'r');
return \fopen('data://text/plain,test', 'rb');
}
return true;
}
Expand Down Expand Up @@ -2750,4 +2750,27 @@ public function testDeleteNonShareFolder($shareFolder, $deleteFolder) {
$view->mkdir($deleteFolder);
$this->assertTrue($view->rmdir($deleteFolder));
}

public function testCacheSizeUpdatedWhenEmptyingFile (): void {
$storage1 = $this->getTestStorage();
Filesystem::mount($storage1, [], '/');

$rootView = new View('');

# test with string as $data
$rootView->file_put_contents('welcome.txt', '1234567890');
$this->assertEquals(10, $rootView->filesize('welcome.txt'));

$rootView->file_put_contents('welcome.txt', '');
$this->assertEquals(0, $rootView->filesize('welcome.txt'));

# test with resource as $data
$stream = fopen('data://text/plain,1234567890', 'rb');
$rootView->file_put_contents('welcome.txt', $stream);
$this->assertEquals(10, $rootView->filesize('welcome.txt'));

$stream = fopen('data://text/plain,', 'rb');
$rootView->file_put_contents('welcome.txt', '');
$this->assertEquals(0, $rootView->filesize('welcome.txt'));
}
}

0 comments on commit 53196ce

Please sign in to comment.