Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
20cefcf4
Commit
20cefcf4
authored
May 15, 2015
by
Olivier Halligon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added `pod cache clean` command (#3508)
parent
805be62f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
121 additions
and
24 deletions
+121
-24
cache.rb
lib/cocoapods/command/cache.rb
+121
-24
No files found.
lib/cocoapods/command/cache.rb
View file @
20cefcf4
...
@@ -18,23 +18,37 @@ module Pod
...
@@ -18,23 +18,37 @@ module Pod
private
private
# @return [Hash<String, Hash<S
tring, Request
>>]
# @return [Hash<String, Hash<S
ymbol, String
>>]
# A hash whose keys are the pod spec name
# A hash whose keys are the pod spec name
# And values are a hash keyed by the specs file paths
# And values are a hash with the following keys:
# :spec_file : path to the spec file
# :name : name of the pod
# :version : pod version
# :release : boolean to tell if that's a release pod
# :slug : the slug path where the pod cache is located
#
#
def
cache_
requests
_per_pod
def
cache_
info
_per_pod
specs_dir
=
@cache_root
+
'Specs'
specs_dir
=
@cache_root
+
'Specs'
spec_files
=
specs_dir
.
find
.
select
{
|
f
|
f
.
fnmatch
(
'*.podspec.json'
)
}
spec_files
=
specs_dir
.
find
.
select
{
|
f
|
f
.
fnmatch
(
'*.podspec.json'
)
}
spec_files
.
reduce
({})
do
|
hash
,
spec_file
|
spec_files
.
reduce
({})
do
|
hash
,
spec_file
|
spec
=
Specification
.
from_file
(
spec_file
)
spec
=
Specification
.
from_file
(
spec_file
)
hash
[
spec
.
name
]
=
{}
if
hash
[
spec
.
name
].
nil?
hash
[
spec
.
name
]
=
[]
if
hash
[
spec
.
name
].
nil?
release
=
spec_file
.
to_s
.
start_with?
((
specs_dir
+
'Release'
).
to_s
)
is_release
=
spec_file
.
to_s
.
start_with?
((
specs_dir
+
'Release'
).
to_s
)
request
=
Downloader
::
Request
.
new
(
:spec
=>
spec
,
:released
=>
release
)
request
=
Downloader
::
Request
.
new
(
:spec
=>
spec
,
:released
=>
is_release
)
hash
[
spec
.
name
][
spec_file
]
=
request
hash
[
spec
.
name
]
<<
{
:spec_file
=>
spec_file
,
:version
=>
request
.
spec
.
version
,
:release
=>
is_release
,
:slug
=>
@cache_root
+
request
.
slug
,
}
hash
hash
end
end
end
end
def
pod_type
(
pod_cache_info
)
pod_cache_info
[
:release
]
?
'Release'
:
'External'
end
class
List
<
Cache
class
List
<
Cache
self
.
summary
=
'List the paths of pod caches for each known pod'
self
.
summary
=
'List the paths of pod caches for each known pod'
...
@@ -54,24 +68,24 @@ module Pod
...
@@ -54,24 +68,24 @@ module Pod
end
end
def
initialize
(
argv
)
def
initialize
(
argv
)
@podname
=
argv
.
shift_argument
@pod
_
name
=
argv
.
shift_argument
@short_output
=
argv
.
flag?
(
'short'
)
@short_output
=
argv
.
flag?
(
'short'
)
super
super
end
end
def
run
def
run
UI
.
puts
(
"Cache root:
#{
@cache_root
}
"
)
if
@short_output
UI
.
puts
(
"Cache root:
#{
@cache_root
}
"
)
if
@short_output
if
@podname
.
nil?
# Print all
if
@pod
_
name
.
nil?
# Print all
cache_
requests_per_pod
.
each
do
|
pod
,
list
|
cache_
info_per_pod
.
each
do
|
pod
,
infos
|
UI
.
title
pod
UI
.
title
pod
print_pod_cache_
list
(
list
)
print_pod_cache_
infos
(
infos
)
end
end
else
# Print only for the requested pod
else
# Print only for the requested pod
cache_
list
=
cache_requests_per_pod
[
@pod
name
]
cache_
infos
=
cache_info_per_pod
[
@pod_
name
]
if
cache_
list
.
nil?
if
cache_
infos
.
nil?
UI
.
notice
(
"No cache for pod named
#{
@podname
}
found"
)
UI
.
notice
(
"No cache for pod named
#{
@pod
_
name
}
found"
)
else
else
print_pod_cache_
list
(
cache_list
)
print_pod_cache_
infos
(
cache_infos
)
end
end
end
end
end
end
...
@@ -80,20 +94,103 @@ module Pod
...
@@ -80,20 +94,103 @@ module Pod
# Prints the list of specs & pod cache dirs for a single pod name
# Prints the list of specs & pod cache dirs for a single pod name
#
#
# @param [
Hash<String,Request>]
list
# @param [
Array<Hash>] info_
list
# The
list of spec_file => Downloader::Request
# The
various infos about a pod cache. Keys are
#
for a given pod name
#
:spec_file, :version, :release and :slug
#
#
def
print_pod_cache_list
(
list
)
def
print_pod_cache_infos
(
info_list
)
list
.
each
do
|
spec_file
,
request
|
info_list
.
each
do
|
info
|
type
=
request
.
released_pod?
?
'Release'
:
'External'
UI
.
section
(
"
#{
info
[
:version
]
}
(
#{
pod_type
(
info
)
}
)"
)
do
UI
.
section
(
"
#{
request
.
spec
.
version
}
(
#{
type
}
)"
)
do
if
@short_output
UI
.
labeled
(
'Spec'
,
@short_output
?
spec_file
.
relative_path_from
(
@cache_root
)
:
spec_file
)
[
:spec_file
,
:slug
].
each
{
|
k
|
info
[
k
]
=
info
[
k
].
relative_path_from
(
@cache_root
)
}
UI
.
labeled
(
'Pod'
,
@short_output
?
request
.
slug
:
@cache_root
+
request
.
slug
)
end
UI
.
labeled
(
'Spec'
,
info
[
:spec_file
])
UI
.
labeled
(
'Pod'
,
info
[
:slug
])
end
end
end
end
end
end
end
end
class
Clean
<
Cache
self
.
summary
=
'Remove the cache for pods'
self
.
description
=
<<-
DESC
Remove the cache for a given pod, or clear the cache completely.
If there is multiple cache for various versions of the requested pod,
you will be asked which one to clean. Use `--all` to clean them all.
If you don't give a pod `NAME`, you need to specify the `--all`
flag (this is to avoid cleaning all the cache by mistake).
DESC
self
.
arguments
=
[
CLAide
::
Argument
.
new
(
'NAME'
,
false
),
]
def
self
.
options
[[
'--all'
,
'Remove all the cached pods without asking'
]].
concat
(
super
)
end
def
initialize
(
argv
)
@pod_name
=
argv
.
shift_argument
@wipe_all
=
argv
.
flag?
(
'all'
)
super
end
def
run
if
@pod_name
.
nil?
# && @wipe_all
# Remove all
clear_cache
else
# Remove only cache for this pod
cache_list
=
cache_info_per_pod
[
@pod_name
]
if
cache_list
.
nil?
UI
.
notice
(
"No cache for pod named
#{
@pod_name
}
found"
)
elsif
cache_list
.
count
>
1
&&
!
@wipe_all
# Ask which to remove
choices
=
cache_list
.
map
{
|
c
|
"
#{
@pod_name
}
v
#{
c
[
:version
]
}
(
#{
pod_type
(
c
)
}
)"
}
index
=
UI
.
choose_from_array
(
choices
,
'Which pod cache do you want to remove?'
)
remove_caches
([
cache_list
[
index
]])
else
# Remove all found cache of this pod
remove_caches
(
cache_list
)
end
end
end
def
validate!
super
if
@pod_name
.
nil?
&&
!
@wipe_all
# Security measure, to avoid removing the pod cache too agressively by mistake
help!
'You should either specify a pod name or use the --all flag'
end
end
private
# Removes the specified cache
#
# @param [Array<Hash>] cache_infos
# An array of caches to remove, each specified with the same
# hash as cache_info_per_pod especially :spec_file and :slug
#
def
remove_caches
(
cache_infos
)
cache_infos
.
each
do
|
info
|
UI
.
message
(
"Removing spec
#{
info
[
:spec_file
]
}
(v
#{
info
[
:version
]
}
)"
)
FileUtils
.
rm
(
info
[
:spec_file
])
UI
.
message
(
"Removing cache
#{
info
[
:slug
]
}
"
)
FileUtils
.
rm_rf
(
info
[
:slug
])
end
end
def
clear_cache
UI
.
message
(
"Removing the whole cache dir
#{
@cache_root
}
"
)
FileUtils
.
rm_rf
(
@cache_root
)
end
end
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment