v0.9.2 — cleanup orphans + PID base names #1
jamesgober
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
mod-tempdir — v0.9.2 Design Note: cleanup_orphans
Goal
Add
cleanup_orphans(max_age_hours: u64) -> io::Result<usize>: atop-level free function that sweeps the OS temp dir for default-prefix
entries this crate could have created, identifies orphans from dead
processes, and removes them.
Key calls
Default-basename format gains a PID segment.
TempDir:.tmp-{pid}-{name12}(was.tmp-{name12}in 0.9.0).NamedTempFile:.tmpfile-{pid}-{name12}(was.tmpfile-{name12}in 0.9.1).
with_prefix(p)is unchanged.cleanup_orphansnever touchesentries outside the default prefixes. The user's namespace is
theirs to clean.
starts_with(".tmp-")/starts_with(".tmpfile-")keep passing:.tmp-1234-XYZstillstarts with
.tmp-. No test rewrites needed beyond the new ones.cleanup_orphansremoval condition is(PID dead) AND (age >= max_age_hours). Both must hold.PID liveness check is platform-conditional, no deps added.
Path::new(&format!("/proc/{pid}")).exists().for the purpose of the AND). The age check is the sole gate
on those platforms. Documented behavior. Picking
max_age_hourslarger than any legitimate process lifetime isthe caller's responsibility on non-Linux.
libc/windows-sysis genuinely not available in
std. Adding those deps isforbidden by the project rules. The honest cross-platform
story is the asymmetric fallback above.
Legacy 0.9.0 / 0.9.1 entries (no PID in name) are ignored.
The parser requires a
{digits}-segment after the prefix; entrieswithout one are not eligible. Safer than trying to guess PIDs.
Per-entry errors are silent, matching the Drop philosophy.
The function returns the count of successful removals. The only
Errpath is failure to read the OS temp dir itself.Test strategy
Five tests in
tests/cleanup_orphans.rs. Each creates orphan entriesunder unique-to-this-test bogus PIDs to avoid cross-test interference
with the shared temp dir.
mtime: kept (live process guard).
File mtime backdating uses
std::fs::File::set_modified, stable inMSRV 1.75. If that turns out not to be in 1.75 after all, I'll fall
back to
set_times.Doc and CHANGELOG updates
the API listing, add a short "Cleaning up after crashes" section
showing typical usage.
signature.
[Unreleased]:### Added+### Changed(thebasename format shift) + a migration sentence.
No version bump, no release ceremony. Accumulating into the next
release per the new workflow.
Full Changelog: v0.9.0...v0.9.2
This discussion was created from the release v0.9.2 — cleanup orphans + PID base names.
All reactions