14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/smallcage/commands/clean.rb', line 14
def execute
start = Time.now
count = 0
target = Pathname.new(@opts[:path])
fail 'target directory or file does not exist.: ' + target.to_s unless target.exist?
loader = SmallCage::Loader.new(target)
root = loader.root
list = SmallCage::UpdateList.create(root, target)
uris = list.expire
uris.each do |uri|
file = root + uri[1..-1]
if file.exist?
puts "D #{uri}" unless @opts[:quiet]
file.delete
count += 1
end
end
tmpdir = root + '_smc/tmp'
if tmpdir.exist?
FileUtils.rm_r(tmpdir)
puts 'D /_smc/tmp' unless @opts[:quiet]
count += 1
end
elapsed = Time.now - start
puts "-- #{ count } files. #{ sprintf('%.3f', elapsed) } sec." +
" #{ sprintf('%.3f', count == 0 ? 0 : elapsed / count) } sec/file." unless @opts[:quiet]
end
|