Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up dangling temporary directories on Windows #70

Merged
merged 3 commits into from
Mar 6, 2021
Merged

Clean up dangling temporary directories on Windows #70

merged 3 commits into from
Mar 6, 2021

Conversation

t-mw
Copy link
Contributor

@t-mw t-mw commented Feb 24, 2021

Easiest solution I can think of to avoid temporary directories building up as discussed in #69. This creates a separate temporary directory just for the exe backup, which is manually removed on Windows the next time the updated exe is run. Could go in a patch release (last PR from me hopefully).

Backing up the exe to a separate temporary directory allows us to:

  • check its contents before deleting, because it will always contain just the exe, not the download.
  • have the other temporary directory for the zip download be automatically removed by the tempfile crate now that it isn't used to store the exe backup.

@t-mw
Copy link
Contributor Author

t-mw commented Feb 24, 2021

Getting a docker rate limit error on one of the CI jobs, need to try again later.

@t-mw
Copy link
Contributor Author

t-mw commented Feb 27, 2021

Tests passed now

let is_expected_tmp_file = |tmp_file_entry: std::io::Result<fs::DirEntry>| {
tmp_file_entry
.ok()
.filter(|e| e.file_name() == expected_tmp_filename)
Copy link
Owner

Choose a reason for hiding this comment

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

do we care to check if the dir contains other subdirs (this is only checking the files in the dir, right?)?

Copy link
Contributor Author

@t-mw t-mw Feb 28, 2021

Choose a reason for hiding this comment

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

fs::read_dir returns subdirectories as well, so the cleanup fails if there are any (just double-checked now). self_update doesn't create any subdirectories in the temp directory because it's only used for replace_using_temp. If subdirectories exist then the user is using the temp directory for something else (not sure why that would be the case, but wanted to be careful with fs::remove_dir_all).

@jaemk
Copy link
Owner

jaemk commented Mar 6, 2021

Nice, thanks @t-mw !

@jaemk jaemk merged commit e94b91b into jaemk:master Mar 6, 2021
@t-mw t-mw deleted the patch-4 branch March 7, 2021 13:32
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