@@ -117,7 +117,7 @@ protected function tearDown(): void {
117117 \OC_User::setUserId ($ this ->user );
118118 foreach ($ this ->storages as $ storage ) {
119119 $ cache = $ storage ->getCache ();
120- $ ids = $ cache ->getAll ();
120+ $ cache ->getAll ();
121121 $ cache ->clear ();
122122 }
123123
@@ -1884,7 +1884,7 @@ function () use ($view, $lockedPath, &$lockTypeDuring, $operation) {
18841884 $ lockTypeDuring = $ this ->getFileLockType ($ view , $ lockedPath );
18851885
18861886 if ($ operation === 'fopen ' ) {
1887- return \fopen ('data://text/plain,test ' , 'r ' );
1887+ return \fopen ('data://text/plain,test ' , 'rb ' );
18881888 }
18891889 return true ;
18901890 }
@@ -2750,4 +2750,27 @@ public function testDeleteNonShareFolder($shareFolder, $deleteFolder) {
27502750 $ view ->mkdir ($ deleteFolder );
27512751 $ this ->assertTrue ($ view ->rmdir ($ deleteFolder ));
27522752 }
2753+
2754+ public function testCacheSizeUpdatedWhenEmptyingFile (): void {
2755+ $ storage1 = $ this ->getTestStorage ();
2756+ Filesystem::mount ($ storage1 , [], '/ ' );
2757+
2758+ $ rootView = new View ('' );
2759+
2760+ # test with string as $data
2761+ $ rootView ->file_put_contents ('welcome.txt ' , '1234567890 ' );
2762+ $ this ->assertEquals (10 , $ rootView ->filesize ('welcome.txt ' ));
2763+
2764+ $ rootView ->file_put_contents ('welcome.txt ' , '' );
2765+ $ this ->assertEquals (0 , $ rootView ->filesize ('welcome.txt ' ));
2766+
2767+ # test with resource as $data
2768+ $ stream = fopen ('data://text/plain,1234567890 ' , 'rb ' );
2769+ $ rootView ->file_put_contents ('welcome.txt ' , $ stream );
2770+ $ this ->assertEquals (10 , $ rootView ->filesize ('welcome.txt ' ));
2771+
2772+ $ stream = fopen ('data://text/plain, ' , 'rb ' );
2773+ $ rootView ->file_put_contents ('welcome.txt ' , '' );
2774+ $ this ->assertEquals (0 , $ rootView ->filesize ('welcome.txt ' ));
2775+ }
27532776}
0 commit comments