Skip to content

Do not recursively clean tempdir#2245

Open
Johan-Liebert1 wants to merge 1 commit into
bootc-dev:mainfrom
Johan-Liebert1:tmpdir-fix
Open

Do not recursively clean tempdir#2245
Johan-Liebert1 wants to merge 1 commit into
bootc-dev:mainfrom
Johan-Liebert1:tmpdir-fix

Conversation

@Johan-Liebert1

@Johan-Liebert1 Johan-Liebert1 commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Ran into this issue by chance in bootupd where the following drop ordering

drop(tempdir)
drop(mount) // unmounts thing mounted at tempdir

was causing all the contents of the mounted device to be deleted because the tempdir was being deleted. We might run into the same issue with our Tempdir impl if we fail to unount the ESP and tempdir is dropped deleting everything in the ESP.

To prevent that, explicitly set disable_cleanup to false on the Tempdir and only enable cleanup after we've successfully unmounted whatever was mounted

@bootc-bot bootc-bot Bot requested a review from jeckersb June 11, 2026 05:20
@Johan-Liebert1 Johan-Liebert1 force-pushed the tmpdir-fix branch 2 times, most recently from 452cc1d to 9efe4d6 Compare June 11, 2026 05:21

@cgwalters cgwalters left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh, that is horrifying.

How about this instead: We have a MountpointTempdir whose Drop only does rmdir (not recursively).

Of course, in many cases I think the real fix here is for us to always use the new mount API to just mount a fd, not a tempdir.

Ran into this issue by chance in bootupd where the following drop ordering

```rust
drop(tempdir)
drop(mount) // unmounts thing mounted at tempdir
```

was causing all the contents of the mounted device to be deleted because
the tempdir was being deleted. We might run into the same issue with our
Tempdir impl if we fail to unount the ESP and tempdir is dropped
deleting everything in the ESP.

To prevent that, we now have a separate struct `MountpointTempdir` which
creates the tempdir for us, explicitly sets `disable_cleanup` to false
so that the dir isn't cleaned up on Drop. On drop, we clean it up
ourselves intentionally using `remove_dir` and not `remove_dir_all` to
make sure we don't end up deleting stuff in the dir.

Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
@Johan-Liebert1

Copy link
Copy Markdown
Collaborator Author

Of course, in many cases I think the real fix here is for us to always use the new mount API to just mount a fd, not a tempdir

we still need a mount point with that right? We could also always mount the ESP at /boot since that's what the spec says?

We have a MountpointTempdir whose Drop only does rmdir (not recursively)

Done

@Johan-Liebert1 Johan-Liebert1 requested a review from cgwalters June 12, 2026 06:17
@Johan-Liebert1 Johan-Liebert1 changed the title Do not clean tempdir if we fail to unmount Do not recursively clean tempdir Jun 12, 2026
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.

2 participants