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

add command brew cask cleanup #2759

Merged
merged 1 commit into from
Feb 11, 2014
Merged

Conversation

rolandwalker
Copy link
Contributor

It came to my attention that Homebrew's brew cleanup is not reliably cleaning up cached downloads from homebrew-cask.

There is no easy way to solve that for old downloads (users must figure out that the cache directory is huge and clean it out manually).

This PR addresses downloads going forward, by making a tracker symlink to all files downloaded by homebrew-cask, and adding a new command brew cask cleanup which chases the tracker symlinks and deletes cached downloads older than 7 days.


def self.remove_old_downloads
ohai "Removing old downloads"
seven_days = Time.now - (60 * 60 * 24 * 7)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't agree with old being seven days. How about we raise this to at least 10 days? Thoughts @phinze @vitorgalvao @fanquake

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have no strong opinion about a specific cutoff time and am happy to change this PR to 10 days.

But note, that cutoff only affects users who explicitly issue brew cask clean. Arguably, those users would find zero to be the cutoff of least surprise, which I also believe is more consistent with Homebrew. Though I stopped following the Homebrew source at a certain point.

My main purpose is to get the tracker symlinks in there, which then enables us to iterate on any type of cleanup behavior/interface going forward.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I agree the least surprising thing to a user explicitly running brew cask clean would probably be removal of all downloads.

But no strong opinion on the cutoff length of the v1 solution here.

I would say that if we have a cutoff, that we should mention it in the output, like: "Removing cached downloads older than N days".

@vitorgalvao
Copy link
Member

Similarly, I have no strong opinion regarding cutoff time (I always remove the cache directory after cleanup, through an alias).

I agree with doing the same as homebrew (to match expectations, as @rolandwalker posited), but I'm fine either way.

@rolandwalker
Copy link
Contributor Author

Then is only a question of interface. Let's provide an interface which accommodates all usecases: that's what interfaces are for.

How about:

  • brew cask cleanup does an immediate cleanup, for least surprise to a naive user
  • brew cask cleanup --outdated uses the 10-day cutoff (or higher?) desired by @nanoxd

def self.remove_dead_symlinks
ohai "Removing dead symlinks"
HOMEBREW_CACHE_CASKS.children.select(&:symlink?).each do |symlink|
unless symlink.exist?
Copy link
Contributor

Choose a reason for hiding this comment

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

Is Pathname#exist? what you want here?

I think you might want to resolve the symlink with Pathname#realpath then check if that exists:

  unless symlink.realpath.exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It may be a weird interface, but symlink.exist? does correctly check for bad symlinks.

symlink.realpath raises an exception, because the real path isn't there.

symlink.readlink.exist? is even worse, as I learned in #2670, because if you don't wrap that in a Dir.chdir(symlink.dirname) do ... end, relative symlinks won't raise an exception, but will give the wrong answer.

There might be yet another method that works there if you want greater code clarity, but I don't know what it is.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey cool!

If you checked that it does The Right Thing (tm), then .exist? actually does seem like the most natural interface to me.

Good on ya, ruby stdlib! 😄

@phinze
Copy link
Contributor

phinze commented Feb 8, 2014

Yeah I like the compromise with default immediate and --outdated for old.

plus new option --outdated
@rolandwalker
Copy link
Contributor Author

Revised to use the compromise interface with a 10-day cutoff, improved tests, and documented in the man page.

rolandwalker added a commit that referenced this pull request Feb 11, 2014
add command `brew cask cleanup`
@rolandwalker rolandwalker merged commit d097094 into Homebrew:master Feb 11, 2014
@rolandwalker rolandwalker deleted the cleanup_cmd branch February 11, 2014 11:25
@Homebrew Homebrew locked and limited conversation to collaborators May 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants