Skip to content

server.sh cleanup: delete relative to the directory find walked - #106

Merged
margani merged 1 commit into
mainfrom
fix/103-cleanup-execdir
Nov 2, 2026
Merged

margani merged 1 commit into
mainfrom
fix/103-cleanup-execdir

Conversation

@margani

@margani margani commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Closes #103.

What changed

  • temp, rotated-logs, crash-dumps and thumbnails no longer pipe find's list into xargs rm. The listing functions take find actions, and the clean functions pass -execdir rm -f -- {} +, so rm runs on ./name inside the directory find itself walked.
  • The report path (sizes) is unchanged: it still uses -print0.

Why

Removing by a path printed earlier re-resolves every directory in it. When run as root over trees other users can write to, a directory replaced in between pointed the delete outside the tree.

Verification

  • New case in server/tests/cleanup_test.sh: a first-call rm shim swaps a user's thumbnail directory for a symlink to another directory, and the file there must survive. On the old code: FAIL: a swapped-in symlink redirected the delete out of the cleaned tree; new code: PASS.
  • ./run-tests: all 10 passed, 3 skipped.

Not verified

  • A real concurrent race as root (the swap is made deterministic with the shim).
  • server.ps1's Windows equivalent: it needs a Windows host with junctions. It remains a lead in the audit report.
  • clean_temp still removes empty old directories by path with rmdir. rmdir only removes empty directories; noted as hardening.

Files were listed by find and removed later by full path with xargs rm, so a
directory swapped for a symlink in between redirected root's unlink outside
the cleaned tree. find now runs rm with -execdir on ./name inside the
directory it walked. A test swaps a directory after the listing and checks a
file outside the tree survives.

Closes #103
@margani
margani merged commit a0a94b0 into main Nov 2, 2026
4 checks passed
@margani
margani deleted the fix/103-cleanup-execdir branch November 2, 2026 19:49
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.

server.sh cleanup: delete relative to the directory find walked, not by a path listed earlier

1 participant