-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvolume_manager.rb
More file actions
97 lines (68 loc) · 1.98 KB
/
Copy pathvolume_manager.rb
File metadata and controls
97 lines (68 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env ruby
# -*-Ruby-*-
require 'digest'
require 'fileutils'
WORK_VOLUME=ENV['WORK_VOLUME'] || "./workspace"
class VolumeManager
def initialize( dir = WORK_VOLUME )
puts "#{Time.now} Workdir #{dir}"
@dir = dir
end
def dir_time t = Time.now
t.strftime( "%Y%j" )
end
def last_x_days( count = 10 )
count.times.collect do |t|
dir_time( Time.now - (86400 * t) )
end
end
def dir( url, t = Time.now )
digest = Digest::MD5.hexdigest url
FileUtils.mkdir_p "#{@dir}/#{dir_time(t)}"
path = "#{@dir}/#{dir_time(t)}/#{digest}"
existing = Dir.glob( "#{@dir}/*/#{digest}" ).select { |d| d != path }.first
if existing
puts "#{Time.now} Found #{existing}, moving to #{path}"
FileUtils.mv( existing, path )
end
FileUtils.mkdir_p path
gc
path
end
def gc(keep_days = 10)
entries = Dir.entries(@dir).select { |x| x[0] != '.' }
(entries - last_x_days(keep_days)).each do |dir|
puts "{Time.now} Removing #{@dir}/#{dir}"
system "rm -rf #{@dir}/#{dir}"
end
end
end
if __FILE__ == $0
def write_file( file )
puts "Writing to #{file}"
system( "cp /Users/wschenk/pixel6downloads/FEMAwood_gas_generator.pdf #{file}" )
end
v = VolumeManager.new
p v.last_x_days
dir = v.dir( "willschenk.com", Time.now - (86400*3) )
write_file( "#{dir}/10m" )
dir = v.dir( "willschenk.com", Time.now - 86400 )
write_file( "#{dir}/10m" )
dir = v.dir( "willschenk.com" )
write_file( "#{dir}/10m" )
dir = v.dir( "gitgratitude.com", Time.now - (86400 * 13) )
write_file( "#{dir}/10m" )
dir = v.dir( "gitgratitude.com", Time.now - (86400 * 6) )
write_file( "#{dir}/10m" )
dir = v.dir( "gitgratitude.com" )
write_file( "#{dir}/10m" )
dir = v.dir( "happyfuncorp.com", Time.now - (86400 * 15) )
write_file( "#{dir}/10m" )
system( "du -sh workspace" )
puts "Running gc"
v.gc
system( "du -sh workspace" )
puts "Running gc"
v.gc(5)
system( "du -sh workspace" )
end