1313use OC \Files \Storage \Storage ;
1414use OCP \Files \Cache \ICache ;
1515use OCP \Files \Cache \ICacheEntry ;
16+ use OCP \Files \Cache \IPropagator ;
17+ use OCP \Files \Cache \IScanner ;
1618use OCP \Files \Cache \IUpdater ;
1719use OCP \Files \Storage \IStorage ;
1820use OCP \Server ;
21+ use Override ;
1922use Psr \Log \LoggerInterface ;
2023
21- /**
22- * Update the cache and propagate changes
23- *
24- */
2524class Updater implements IUpdater {
26- /**
27- * @var bool
28- */
29- protected $ enabled = true ;
30-
31- /**
32- * @var Propagator
33- */
34- protected $ propagator ;
35-
36- /**
37- * @var Scanner
38- */
39- protected $ scanner ;
40-
41- /**
42- * @var Cache
43- */
44- protected $ cache ;
45-
25+ protected bool $ enabled = true ;
26+ protected IPropagator $ propagator ;
27+ protected IScanner $ scanner ;
28+ protected ICache $ cache ;
4629 private LoggerInterface $ logger ;
4730
48- /**
49- * @param Storage $storage
50- */
5131 public function __construct (
5232 protected Storage $ storage ,
5333 ) {
@@ -60,46 +40,32 @@ public function __construct(
6040 /**
6141 * Disable updating the cache through this updater
6242 */
63- public function disable () {
43+ public function disable (): void {
6444 $ this ->enabled = false ;
6545 }
6646
6747 /**
6848 * Re-enable the updating of the cache through this updater
6949 */
70- public function enable () {
50+ public function enable (): void {
7151 $ this ->enabled = true ;
7252 }
7353
74- /**
75- * Get the propagator for etags and mtime for the view the updater works on
76- *
77- * @return Propagator
78- */
79- public function getPropagator () {
54+ #[Override]
55+ public function getPropagator (): IPropagator {
8056 return $ this ->propagator ;
8157 }
8258
83- /**
84- * Propagate etag and mtime changes for the parent folders of $path up to the root of the filesystem
85- *
86- * @param string $path the path of the file to propagate the changes for
87- * @param int|null $time the timestamp to set as mtime for the parent folders, if left out the current time is used
88- */
89- public function propagate ($ path , $ time = null ) {
59+ #[Override]
60+ public function propagate (string $ path , ?int $ time = null ): void {
9061 if (Scanner::isPartialFile ($ path )) {
9162 return ;
9263 }
9364 $ this ->propagator ->propagateChange ($ path , $ time );
9465 }
9566
96- /**
97- * Update the cache for $path and update the size, etag and mtime of the parent folders
98- *
99- * @param string $path
100- * @param int $time
101- */
102- public function update ($ path , $ time = null , ?int $ sizeDifference = null ) {
67+ #[Override]
68+ public function update (string $ path , ?int $ time = null , ?int $ sizeDifference = null ): void {
10369 if (!$ this ->enabled || Scanner::isPartialFile ($ path )) {
10470 return ;
10571 }
@@ -126,12 +92,8 @@ public function update($path, $time = null, ?int $sizeDifference = null) {
12692 $ this ->propagator ->propagateChange ($ path , $ time , $ sizeDifference ?? 0 );
12793 }
12894
129- /**
130- * Remove $path from the cache and update the size, etag and mtime of the parent folders
131- *
132- * @param string $path
133- */
134- public function remove ($ path ) {
95+ #[Override]
96+ public function remove (string $ path ): void {
13597 if (!$ this ->enabled || Scanner::isPartialFile ($ path )) {
13698 return ;
13799 }
@@ -156,14 +118,8 @@ public function remove($path) {
156118 }
157119 }
158120
159- /**
160- * Rename a file or folder in the cache.
161- *
162- * @param IStorage $sourceStorage
163- * @param string $source
164- * @param string $target
165- */
166- public function renameFromStorage (IStorage $ sourceStorage , $ source , $ target ) {
121+ #[Override]
122+ public function renameFromStorage (IStorage $ sourceStorage , string $ source , string $ target ): void {
167123 $ this ->copyOrRenameFromStorage ($ sourceStorage , $ source , $ target , function (ICache $ sourceCache ) use ($ sourceStorage , $ source , $ target ): void {
168124 // Remove existing cache entry to no reuse the fileId.
169125 if ($ this ->cache ->inCache ($ target )) {
@@ -178,9 +134,7 @@ public function renameFromStorage(IStorage $sourceStorage, $source, $target) {
178134 });
179135 }
180136
181- /**
182- * Copy a file or folder in the cache.
183- */
137+ #[Override]
184138 public function copyFromStorage (IStorage $ sourceStorage , string $ source , string $ target ): void {
185139 $ this ->copyOrRenameFromStorage ($ sourceStorage , $ source , $ target , function (ICache $ sourceCache , ICacheEntry $ sourceInfo ) use ($ target ): void {
186140 $ parent = dirname ($ target );
@@ -250,7 +204,7 @@ private function copyOrRenameFromStorage(IStorage $sourceStorage, string $source
250204 $ this ->propagator ->propagateChange ($ target , $ time );
251205 }
252206
253- private function updateStorageMTimeOnly ($ internalPath ) {
207+ private function updateStorageMTimeOnly (string $ internalPath ): void {
254208 $ fileId = $ this ->cache ->getId ($ internalPath );
255209 if ($ fileId !== -1 ) {
256210 $ mtime = $ this ->storage ->filemtime ($ internalPath );
@@ -266,11 +220,9 @@ private function updateStorageMTimeOnly($internalPath) {
266220 }
267221
268222 /**
269- * update the storage_mtime of the direct parent in the cache to the mtime from the storage
270- *
271- * @param string $internalPath
223+ * Update the storage_mtime of the direct parent in the cache to the mtime from the storage
272224 */
273- private function correctParentStorageMtime ($ internalPath ) {
225+ private function correctParentStorageMtime (string $ internalPath ): void {
274226 $ parentId = $ this ->cache ->getParentId ($ internalPath );
275227 $ parent = dirname ($ internalPath );
276228 if ($ parentId != -1 ) {
0 commit comments