Repository navigation
fix(cache): preserve root directory and handle empty folder on filesystem flush - #14059
Conversation
🔵 Tier A · Mergeable after minor fixes
Updates filesystem cache flushing to accept empty directories and preserve the cache root while removing its contents. Deletion failures now propagate through recursive calls instead of being reported as success. Regression tests cover root preservation, repeated flushing, health checks, nested entries, and deletion failure. Latest changes: The newest commits propagate unlink and recursive deletion failures and add a permission-based regression test.
Note @Spandan-Mishra does not have write access to this repository, so Hansi does not approve automatically. A maintainer can review and approve.
Fix with agent prompt### Issue 1
packages/cache/tests/FilesystemTest.php:124-130
**Skip the permission test when root cannot drop privileges**
When running as root without the POSIX extension, or when `posix_seteuid()` fails, chmod does not prevent deletion and this assertion fails even with the correct implementation. Please skip the test when an unprivileged execution context cannot be established; the package does not require ext-posix.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 2
✅ Fixed since the last review · 1
Reviewed the commits since |
Track deletion status across entries during directory traversal and return false when files or subdirectories cannot be deleted.
| if ($isRoot && function_exists('posix_seteuid')) { | ||
| $origEuid = posix_geteuid(); | ||
| $switched = @posix_seteuid(1000); | ||
| } | ||
|
|
||
| try { | ||
| $this->assertFalse($cache->flush()); |
There was a problem hiding this comment.
Skip the permission test when root cannot drop privileges
When running as root without the POSIX extension, or when posix_seteuid() fails, chmod does not prevent deletion and this assertion fails even with the correct implementation. Please skip the test when an unprivileged execution context cannot be established; the package does not require ext-posix.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cache/tests/FilesystemTest.php
Line: 124-130
Comment:
**Skip the permission test when root cannot drop privileges**
When running as root without the POSIX extension, or when `posix_seteuid()` fails, chmod does not prevent deletion and this assertion fails even with the correct implementation. Please skip the test when an unprivileged execution context cannot be established; the package does not require ext-posix.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · testing · Reply if this doesn't apply.
45641ad
into
appwrite:fix-cache-filesystem-flush
What does this PR do?
Fixes three issues in
Utopia\Cache\Adapter\Filesystem::flush():flush()was called on an empty cache directory,glob($path . '*', GLOB_MARK)returned[]. The error guardif (! $files)evaluated totrue, mistakenly treating an empty directory as a glob failure and throwingException: Error happened during glob. This is fixed by strictly checkingif ($files === false).deleteDirectory($path)unconditionally concluded withrmdir($path). When called fromflush(),$pathis$this->path(the root cache directory), causingflush()to delete the root folder from disk rather than clearing its contents. This is resolved by adding an optional$isRoot = falseparameter and calling$this->deleteDirectory($this->path, true), returningtruefor root while recursively removing emptied subdirectories withrmdir().ping()and Repeatedflush()Failures: Preserving the root directory ensures$cache->ping()remainstrueafterflush(), and subsequentflush()calls operate idempotently instead of throwingException: <path> must be a directory.Test Plan
Automated Unit Tests:
Ran the updated unit test suite covering empty flush, post-flush ping, idempotency, and recursive subdirectory clearing:
Output:
Sibling Adapter Pool Test:
Static Analysis & Monorepo Validation:
Related PRs and Issues
Fixes #14007
Checklist