Skip to content

fix(cache): preserve root directory and handle empty folder on filesystem flush - #14515

Merged
HarshMN2345 merged 7 commits into
mainfrom
fix-cache-filesystem-flush
Oct 29, 2026
Merged

HarshMN2345 merged 7 commits into
mainfrom
fix-cache-filesystem-flush

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

Filesystem::flush() threw on an empty cache directory (glob() returns [], which ! $files treated as a failure) and removed the cache root itself, so ping() returned false afterwards and the next flush() threw.

  • Treat only glob() === false as an error.
  • flush() empties the root but keeps it; nested directories are still removed, and the result is false if any file or directory could not be deleted.

Verified:

  • packages/cache unit suite in the appwrite-dev container: 116 tests passed, 2 skipped.
  • FilesystemTest on the host: testFlushEmpty and testFlushKeepsRoot fail against main's adapter and pass with this change.
  • bin/monorepo check cache: Rector and Pint passed. PHPStan reports 10 errors, all in the untouched Redis.php / RedisCluster.php; the same errors appear in the container run.

Closes #14007

Related: #14059 (merged into this branch), #14033 (superseded)

Spandan-Mishra and others added 5 commits October 1, 2026 23:11
Track deletion status across entries during directory traversal and
return false when files or subdirectories cannot be deleted.
…tem-flush-empty-and-rmdir-bug

fix(cache): preserve root directory and handle empty folder on filesystem flush
@luxor-code-review

luxor-code-review Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR reworks the packages/cache filesystem adapter so flush() no longer deletes the cache root directory itself — it clears children and recreates/keeps the root — and propagates child deletion failures through the return value, with deleteDirectory() adjusted to match and packages/cache/tests/FilesystemTest.php updated to assert the new behavior.

Files Change
packages/cache/src/Adapter/Filesystem.php flush() and deleteDirectory() now preserve the root directory, use GLOB_MARK globbing over children, and accumulate child deletion success into the return value.
packages/cache/tests/FilesystemTest.php Test expectations updated so flush() keeps the cache root directory present and empty.

Reviewed commit: 3e9e3ec

@ghost

ghost commented Oct 15, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The implementation addresses the hidden-entry issue, but the newly covered flush behavior lacks a regression test for dot-prefixed cache entries.

The filesystem cache flush now handles empty directories, keeps the cache root, and reports deletion failures while removing nested contents. Regression tests cover empty flushes and root preservation, and the latest update switches directory enumeration to include dot-prefixed entries and avoid traversing directory symlinks.

Latest changes: The latest commit replaces glob-based enumeration with scandir so flush includes dot-prefixed entries and unlinks directory symlinks instead of traversing them.

Verdict New comments Fixed Still open
✅ Approved 1 1 0
Finding Where
🟡 Add a regression test for dot-prefixed cache entries packages/cache/src/Adapter/Filesystem.php:173
Fix with agent prompt
### Issue 1
packages/cache/src/Adapter/Filesystem.php:173-174
**Add a regression test for dot-prefixed cache entries**

The `scandir` change makes dot-prefixed cache entries removable, but the filesystem tests do not create one and assert it is gone after `flush()`. A regression could therefore leave hidden entries behind while reporting success.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 2
File Change
packages/cache/src/Adapter/Filesystem.php Preserves the root during flush, handles empty directories and deletion failures, and uses scandir to include hidden entries without traversing directory symlinks.
packages/cache/tests/FilesystemTest.php Adds regression coverage for flushing an empty directory and retaining the cache root.
✅ Fixed since the last review · 1
  • Flush can report success while hidden entries remain · packages/cache/src/Adapter/Filesystem.php:181

Merged main (0f1e945); no changes to this PR's code since 6e04eea · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · See the inline comments. Summary

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-cache-filesystem-flush (after).

Metric Before After Change
🚀 Requests/sec 184.53 194.02 🟢 +5.1%
⏱️ Latency P50 92.44 ms 89.58 ms ⚪ -3.1%
⏱️ Latency P95 224.76 ms 206.21 ms 🟢 -8.3%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 89.58 206.21 12,483 194.02 -18.55
Account 166.17 307.09 657 10.95 -26.36
TablesDB 86.25 161.99 6,789 108.15 -14.73
Storage 83.81 195.72 3,285 53.6 -20.57
Functions 125.33 233.79 1,752 29.28 -21.38

Top API waits (after)

API request Max wait (ms)
account.name.update 410.02
tablesdb.rows.create 383.03
functions.create 362.64
functions.variables.update 353.31
tablesdb.rows.decrement 351.21

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · Looks good to merge. Summary

Comment on lines +173 to +174
foreach (array_diff($entries, ['.', '..']) as $entry) {
$file = $path . $entry;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a regression test for dot-prefixed cache entries

The scandir change makes dot-prefixed cache entries removable, but the filesystem tests do not create one and assert it is gone after flush(). A regression could therefore leave hidden entries behind while reporting success.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cache/src/Adapter/Filesystem.php
Line: 173-174

Comment:
**Add a regression test for dot-prefixed cache entries**

The `scandir` change makes dot-prefixed cache entries removable, but the filesystem tests do not create one and assert it is gone after `flush()`. A regression could therefore leave hidden entries behind while reporting success.

---

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.

@HarshMN2345
HarshMN2345 merged commit b82b398 into main Oct 29, 2026
127 of 131 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calling flush() on a cache backed by the Filesystem adapter leads runtime failures

2 participants