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

Delete content of downloads dir of user home in update subcommand #2046

Merged
merged 1 commit into from
Oct 18, 2019

Conversation

BeniCheni
Copy link
Contributor

@BeniCheni BeniCheni commented Oct 9, 2019

Resolves #2038.

P.S.: can use some mentoring from review comments to:

  • polish code pattern
  • improve test to actually download a binary, run updateand assert the deleted content of downloads folder of user home.

I'll keep thinking, and will push edit(s), if I could figure out a better test. But thought that I'd start the PR to collect some feedback.

@BeniCheni BeniCheni force-pushed the clean-downloads-after-update branch 7 times, most recently from 594bd10 to 8cc51ff Compare October 10, 2019 14:34
src/cli/rustup_mode.rs Outdated Show resolved Hide resolved
@BeniCheni BeniCheni force-pushed the clean-downloads-after-update branch 2 times, most recently from 60eb620 to 3b87cba Compare October 12, 2019 04:38
@BeniCheni
Copy link
Contributor Author

OR, even simpler ...

@timw4mail, good 👁. format! is definitely more elegant. Updated.

Copy link
Contributor

@kinnison kinnison left a comment

Choose a reason for hiding this comment

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

Thank you for trying to solve this particular issue. However there are a couple of fundamental things which need changing.

One is that you need to properly manage the download path by means of the Cfg instance which exists already, and not keep casting paths into strings. String guarantees utf8 correctness, but UNIX paths are NOT guaranteed to be valid UTF8, hence Rust has Pathbuf and Path.

The second is that I really don't want to see the downloads dir cleaned up unless the user has just completed a full rustup update because that's the only time where we can be sure that the partials are no longer needed.

There is a call to common::update_all_channels() in update() in rustup_mode.rs which is where you should be adding your call to delete the downloads contents. i.e. in update() after common::update_all_channels().

If you want additional help with making these changes, just let me know.

Thanks again,

D.

src/cli/rustup_mode.rs Outdated Show resolved Hide resolved
src/cli/rustup_mode.rs Outdated Show resolved Hide resolved
src/cli/rustup_mode.rs Outdated Show resolved Hide resolved
src/cli/rustup_mode.rs Outdated Show resolved Hide resolved
src/cli/rustup_mode.rs Outdated Show resolved Hide resolved
tests/cli-misc.rs Outdated Show resolved Hide resolved
@kinnison
Copy link
Contributor

It may also make sense to solve #1252 at the same time, by adding support for cleaning up the content of the temp directory in dist/temp.rs's impl Cfg. Perhaps you could split your cleanup function into utils/utils.rs and then use it from update() to clean up cfg.download_dir and add cfg.temp_cfg.clean() to ask dist::temp::Cfg to clean up too? If that's too much for you then just ignore this suggestion and I'll add it once your PR is mergeable.

src/cli/rustup_mode.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/cli/rustup_mode.rs Outdated Show resolved Hide resolved
src/cli/rustup_mode.rs Outdated Show resolved Hide resolved
@BeniCheni BeniCheni force-pushed the clean-downloads-after-update branch 6 times, most recently from 4ff9ee1 to cdc32c2 Compare October 15, 2019 16:24
src/utils/utils.rs Outdated Show resolved Hide resolved
@BeniCheni BeniCheni force-pushed the clean-downloads-after-update branch 2 times, most recently from cb9c20c to f33ed66 Compare October 15, 2019 17:54
@BeniCheni
Copy link
Contributor Author

Perhaps you could split your cleanup function into utils/utils.rs and then use it from update() to clean up cfg.download_dir and add cfg.temp_cfg.clean() to ask dist::temp::Cfg to clean up too?

@kinnison, thanks for the insightful comments. Last commit attempted to follow the suggestion, hopefully, make the calls to clean up "downloads/" and "tmp/" dirs at the right place where after a full rustup update.

PTAL at convenience? Will promptly edit under guidance, if this version still is calling the cleanup functions at the right place.

Copy link
Contributor

@kinnison kinnison left a comment

Choose a reason for hiding this comment

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

The change looks good, but I don't understand why there's a Cargo.lock change here since you don't touch Cargo.toml -- could you please remove that from the diff, and rename the variable as per my comment, then I think we're almost good to merge.

src/utils/utils.rs Outdated Show resolved Hide resolved
@BeniCheni BeniCheni force-pushed the clean-downloads-after-update branch 2 times, most recently from 416dcf3 to 8825fdb Compare October 15, 2019 21:47
@BeniCheni
Copy link
Contributor Author

BeniCheni commented Oct 15, 2019

but I don't understand why there's a Cargo.lock change here

Reverted the overlook of Cargo.lock file in the PR.

just call this dir_contents?

Sounds great. Last commit renamed to dir_contents. Thanks, @kinnison

Copy link
Contributor

@kinnison kinnison left a comment

Choose a reason for hiding this comment

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

One little tweak, but I can do that on merge if you don't want to.

src/utils/utils.rs Outdated Show resolved Hide resolved
@BeniCheni
Copy link
Contributor Author

One little tweak, but I can do that on merge if you don't want to.

@kinnison, pushed another update for another tweak. Thanks for catching the unnecessary borrow. 👍

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.

Feature Request: Clean up download dir (partials etc) after successful full update run.
4 participants