Skip to content

deleter: handle non-openpilot created files#37728

Open
pkb94 wants to merge 1 commit intocommaai:masterfrom
pkb94:fix/deleter-handle-non-openpilot-files
Open

deleter: handle non-openpilot created files#37728
pkb94 wants to merge 1 commit intocommaai:masterfrom
pkb94:fix/deleter-handle-non-openpilot-files

Conversation

@pkb94
Copy link
Copy Markdown

@pkb94 pkb94 commented Mar 25, 2026

Fixes #30102

Description

The deleter crashes with NotADirectoryError when stray files (e.g. .tar.gz archives) or symlinks exist in the log root directory. Two root causes:

  1. os.listdir(delete_path) was called without try/except — crashes on race conditions or unexpected entry types
  2. shutil.rmtree() was called on symlinks, which raises NotADirectoryError
  3. listdir_by_creation() filters to directories only, so stray files/symlinks are never seen and accumulate indefinitely, filling the disk

Fix

  • Wrap the os.listdir() lock check in try/except OSError
  • Check os.path.islink() before shutil.rmtree(); use os.unlink() for symlinks
  • Add a secondary scan of the log root to delete stray non-directory entries not managed by openpilot

Verification

Tested with pytest system/loggerd/tests/test_deleter.py -v. Added 7 new unit tests covering:

  • Single and multiple stray files
  • Valid symlinks (symlink removed, target directory preserved)
  • Broken/dangling symlinks
  • Stray files mixed with normal segment directories
  • Continued operation after a per-entry deletion failure
  • Non-segment directories in log root

Fixes commaai#30102

- Wrap os.listdir() lock check in try/except OSError to handle race
  conditions and unexpected entry types
- Check os.path.islink() before shutil.rmtree(); use os.unlink() for
  symlinks to avoid NotADirectoryError
- Add secondary scan of log root to delete stray files/symlinks that
  are invisible to listdir_by_creation and would otherwise fill the disk

Add 7 new tests covering: stray files, multiple strays, valid symlinks
(target preserved), broken symlinks, mixed entries, error recovery, and
non-segment directories
@github-actions
Copy link
Copy Markdown
Contributor

Process replay diff report

Replays driving segments through this PR and compares the behavior to master.
Please review any changes carefully to ensure they are expected.

✅ 0 changed, 66 passed, 0 errors

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.

deleter: handle non-openpilot created files

1 participant