core icon indicating copy to clipboard operation
core copied to clipboard

fix: file size in cache is set back to zero if empty content is writt…

Open DeepDiver1975 opened this issue 2 years ago • 15 comments

…en to a non-empty file

Description

When writing zero length content to a non-empty file the file size in the file cache was not updated.

How Has This Been Tested?

see provided test

Types of changes

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Database schema changes (next release will require increase of minor version instead of patch)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] Technical debt
  • [ ] Tests only (no source changes)

Checklist:

  • [x] Code changes
  • [x] Unit tests added
  • [ ] Acceptance tests added
  • [ ] Documentation ticket raised:
  • [ ] Changelog item, see TEMPLATE

DeepDiver1975 avatar Jul 16 '21 10:07 DeepDiver1975

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

update-docs[bot] avatar Jul 16 '21 10:07 update-docs[bot]

https://drone.owncloud.com/owncloud/core/31293/2/7 make test-php-style fails.

phil-davis avatar Jul 16 '21 10:07 phil-davis

Only the PHP unit tests on Oracle failed: https://drone.owncloud.com/owncloud/core/31304/19/9

There were 1508 errors:

1) Test\Cache\FileCacheTest::testGarbageCollectOldKeys
Doctrine\DBAL\Exception\DriverException: An exception occurred while executing 'UPDATE "oc_filecache" SET "mtime" = NULL, "storage_mtime" = NULL WHERE ("mtime" IS NOT NULL OR "storage_mtime" IS NOT NULL) AND "fileid" = ?' with params [4]:

ORA-01407: cannot update ("AUTOTEST"."oc_filecache"."mtime") to NULL

/drone/src/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php:69
/drone/src/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:182
/drone/src/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:159
/drone/src/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:2212
/drone/src/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1302
/drone/src/lib/private/DB/Connection.php:191
/drone/src/lib/private/Files/Cache/Cache.php:388
/drone/src/lib/private/Files/Cache/Updater.php:247
/drone/src/lib/private/Files/Cache/Updater.php:160
/drone/src/lib/private/Files/View.php:342
/drone/src/lib/private/Files/View.php:1239
/drone/src/lib/private/Files/View.php:776
/drone/src/lib/public/Events/EventEmitterTrait.php:50
/drone/src/lib/private/Files/View.php:786
/drone/src/lib/private/Cache/File.php:160
/drone/src/tests/lib/Cache/TestCache.php:19
/drone/src/tests/lib/Cache/FileCacheTest.php:91

Caused by
Doctrine\DBAL\Driver\OCI8\OCI8Exception: ORA-01407: cannot update ("AUTOTEST"."oc_filecache"."mtime") to NULL

/drone/src/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php:25
/drone/src/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php:409
/drone/src/lib/composer/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1290
/drone/src/lib/private/DB/Connection.php:191
/drone/src/lib/private/Files/Cache/Cache.php:388
/drone/src/lib/private/Files/Cache/Updater.php:247
/drone/src/lib/private/Files/Cache/Updater.php:160
/drone/src/lib/private/Files/View.php:342
/drone/src/lib/private/Files/View.php:1239
/drone/src/lib/private/Files/View.php:776
/drone/src/lib/public/Events/EventEmitterTrait.php:50
/drone/src/lib/private/Files/View.php:786
/drone/src/lib/private/Cache/File.php:160
/drone/src/tests/lib/Cache/TestCache.php:19
/drone/src/tests/lib/Cache/FileCacheTest.php:91

2) Test\Cache\FileCacheTest::testGarbageCollectLeaveRecentKeys
Exception: Missing tearDown call in Test\Cache\FileCacheTest

/drone/src/tests/lib/Traits/UserTrait.php:52
/drone/src/tests/lib/TestCase.php:127
/drone/src/tests/lib/Cache/FileCacheTest.php:55

3) Test\Cache\FileCacheTest::testGarbageCollectIgnoreLockedKeys with data set #0 (OCP\Lock\LockedException Object (...))
Exception: Missing tearDown call in Test\Cache\FileCacheTest

/drone/src/tests/lib/Traits/UserTrait.php:52
/drone/src/tests/lib/TestCase.php:127
/drone/src/tests/lib/Cache/FileCacheTest.php:55
...

The first fail might be real?

But then it complains many times about Exception: Missing tearDown call in Test\Cache\FileCacheTest

I restarted CI so we can see if the fail is "variable".

phil-davis avatar Jul 16 '21 12:07 phil-davis

@DeepDiver1975 I used current master and tried overwriting a file with an empty file, then downloading it. The download comes back empty, which is correct. So this problem does not seem to have an externally-observable bad behavior.

Is that correct? This just fixes an internal cache problem?

phil-davis avatar Jul 16 '21 12:07 phil-davis

This just fixes and internal cache problem?

This is a pure PHP API fix from my understanding - it was discovered while working on some other app which used these functions that way ....

DeepDiver1975 avatar Jul 16 '21 12:07 DeepDiver1975

:boom: Acceptance tests pipeline apiFederationToRoot1-git-mariadb10.2-php7.4 failed. The build has been cancelled.

https://drone.owncloud.com/owncloud/core/31469/107/1

ownclouders avatar Jul 22 '21 14:07 ownclouders

https://drone.owncloud.com/owncloud/core/31515/36/9 "something happened" (tm) in unit tests with Oracle.

phil-davis avatar Jul 26 '21 09:07 phil-davis

https://drone.owncloud.com/owncloud/core/31515/36/9 "something happened" (tm) in unit tests with Oracle.

:shrug:

DeepDiver1975 avatar Jul 26 '21 10:07 DeepDiver1975

Screenshot from 2021-07-26 13-03-40

DeepDiver1975 avatar Jul 26 '21 11:07 DeepDiver1975

looks like I need to fire up oracle locally one more time ....

DeepDiver1975 avatar Jul 26 '21 11:07 DeepDiver1975

:boom: Acceptance tests pipeline webUISharingPublic1-chrome-mariadb10.2-php7.4 failed. The build has been cancelled.

https://drone.owncloud.com/owncloud/core/32396/144/1

ownclouders avatar Sep 15 '21 09:09 ownclouders

@DeepDiver1975 merga master or rebase to kick ci again?

butonic avatar Jul 26 '22 10:07 butonic

:see_no_evil:

There were 5 failures:

1) Test\Files\Cache\UpdaterTest::testMove
Failed asserting that 0 matches expected 1699446390.

/drone/src/tests/lib/Files/Cache/UpdaterTest.php:147
phpvfscomposer:///drone/src/lib/composer/phpunit/phpunit/phpunit:106

2) Test\Files\Cache\UpdaterTest::testMoveNonExistingOverwrite
Failed asserting that 0 matches expected 1699446390.

/drone/src/tests/lib/Files/Cache/UpdaterTest.php:165
phpvfscomposer:///drone/src/lib/composer/phpunit/phpunit/phpunit:106

3) Test\Files\Cache\UpdaterTest::testUpdateStorageMTime
file mtime preserved
Failed asserting that 0 matches expected 1699446390.

/drone/src/tests/lib/Files/Cache/UpdaterTest.php:200
phpvfscomposer:///drone/src/lib/composer/phpunit/phpunit/phpunit:106

4) Test\Files\Cache\UpdaterTest::testMoveCrossStorage
Failed asserting that 0 matches expected 1699446390.

/drone/src/tests/lib/Files/Cache/UpdaterTest.php:246
phpvfscomposer:///drone/src/lib/composer/phpunit/phpunit/phpunit:106

5) Test\Files\Cache\UpdaterTest::testMoveFolderCrossStorage
Failed asserting that 0 matches expected 1699446390.

/drone/src/tests/lib/Files/Cache/UpdaterTest.php:300
phpvfscomposer:///drone/src/lib/composer/phpunit/phpunit/phpunit:106

DeepDiver1975 avatar Nov 08 '23 13:11 DeepDiver1975