Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brew
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
brew
Commits
4f6a46f4
Commit
4f6a46f4
authored
8 years ago
by
Josh Hagins
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #791 from reitermarkus/per-cask-cleanup
Allow per-cask `cleanup`.
parents
8d79cf1e
911edb0e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Library/Homebrew/cask/lib/hbc/cli/cleanup.rb
+25
-5
25 additions, 5 deletions
Library/Homebrew/cask/lib/hbc/cli/cleanup.rb
Library/Homebrew/cask/spec/cask/cli/cleanup_spec.rb
+32
-6
32 additions, 6 deletions
Library/Homebrew/cask/spec/cask/cli/cleanup_spec.rb
with
57 additions
and
11 deletions
Library/Homebrew/cask/lib/hbc/cli/cleanup.rb
+
25
−
5
View file @
4f6a46f4
...
...
@@ -10,8 +10,12 @@ class Hbc::CLI::Cleanup < Hbc::CLI::Base
true
end
def
self
.
run
(
*
_ignored
)
default
.
cleanup!
def
self
.
run
(
*
args
)
if
args
.
empty?
default
.
cleanup!
else
default
.
cleanup
(
args
)
end
end
def
self
.
default
...
...
@@ -25,7 +29,11 @@ class Hbc::CLI::Cleanup < Hbc::CLI::Base
end
def
cleanup!
remove_all_cache_files
remove_cache_files
end
def
cleanup
(
tokens
)
remove_cache_files
(
*
tokens
)
end
def
cache_files
...
...
@@ -55,11 +63,23 @@ class Hbc::CLI::Cleanup < Hbc::CLI::Base
Hbc
::
Utils
.
size_in_bytes
(
cache_files
)
end
def
remove_
all_
cache_files
def
remove_cache_files
(
*
tokens
)
message
=
"Removing cached downloads"
message
.
concat
" for
#{
tokens
.
join
(
', '
)
}
"
unless
tokens
.
empty?
message
.
concat
" older than
#{
OUTDATED_DAYS
}
days old"
if
outdated_only
ohai
message
delete_paths
(
cache_files
)
deletable_cache_files
=
if
tokens
.
empty?
cache_files
else
start_withs
=
tokens
.
map
{
|
token
|
"
#{
token
}
--"
}
cache_files
.
select
{
|
path
|
path
.
basename
.
to_s
.
start_with?
(
*
start_withs
)
}
end
delete_paths
(
deletable_cache_files
)
end
def
delete_paths
(
paths
)
...
...
This diff is collapsed.
Click to expand it.
Library/Homebrew/cask/spec/cask/cli/cleanup_spec.rb
+
32
−
6
View file @
4f6a46f4
...
...
@@ -10,6 +10,32 @@ describe Hbc::CLI::Cleanup do
cache_location
.
rmtree
end
describe
"cleanup"
do
it
"removes cached downloads of given casks"
do
cleaned_up_cached_download
=
'caffeine'
cached_downloads
=
[
cache_location
.
join
(
"
#{
cleaned_up_cached_download
}
--latest.zip"
),
cache_location
.
join
(
"transmission--2.61.dmg"
),
]
cached_downloads
.
each
(
&
FileUtils
.
method
(
:touch
))
cleanup_size
=
Hbc
::
Utils
.
size_in_bytes
(
cached_downloads
[
0
])
expect
{
subject
.
cleanup
(
cleaned_up_cached_download
)
}.
to
output
(
<<-
EOS
.
undent
).
to_stdout
==> Removing cached downloads for
#{
cleaned_up_cached_download
}
#{
cached_downloads
[
0
]
}
==> This operation has freed approximately
#{
disk_usage_readable
(
cleanup_size
)
}
of disk space.
EOS
expect
(
cached_downloads
[
0
].
exist?
).
to
eq
(
false
)
expect
(
cached_downloads
[
1
].
exist?
).
to
eq
(
true
)
end
end
describe
"cleanup!"
do
it
"removes cached downloads"
do
cached_download
=
cache_location
.
join
(
"SomeDownload.dmg"
)
...
...
@@ -18,11 +44,11 @@ describe Hbc::CLI::Cleanup do
expect
{
subject
.
cleanup!
}.
to
output
(
<<-
OUTPUT
.
undent
).
to_stdout
}.
to
output
(
<<-
EOS
.
undent
).
to_stdout
==> Removing cached downloads
#{
cached_download
}
==> This operation has freed approximately
#{
disk_usage_readable
(
cleanup_size
)
}
of disk space.
OUTPUT
EOS
expect
(
cached_download
.
exist?
).
to
eq
(
false
)
end
...
...
@@ -38,11 +64,11 @@ describe Hbc::CLI::Cleanup do
expect
{
subject
.
cleanup!
}.
to
output
(
<<-
OUTPUT
.
undent
).
to_stdout
}.
to
output
(
<<-
EOS
.
undent
).
to_stdout
==> Removing cached downloads
skipping:
#{
cached_download
}
is locked
==> This operation has freed approximately
#{
disk_usage_readable
(
cleanup_size
)
}
of disk space.
OUTPUT
EOS
expect
(
cached_download
.
exist?
).
to
eq
(
true
)
end
...
...
@@ -56,10 +82,10 @@ describe Hbc::CLI::Cleanup do
expect
{
subject
.
cleanup!
}.
to
output
(
<<-
OUTPUT
.
undent
).
to_stdout
}.
to
output
(
<<-
EOS
.
undent
).
to_stdout
==> Removing cached downloads older than 10 days old
Nothing to do
OUTPUT
EOS
expect
(
cached_download
.
exist?
).
to
eq
(
true
)
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment