Module: DistributedCache::Utils
- Defined in:
- lib/distributed_cache/utils.rb
Class Method Summary collapse
-
.rm_rf(dir) ⇒ Object
these folders could contain 100s of thousands of files faster to just mv the folder out of the way and delete it in a forked process.
- .rsync(server) ⇒ Object
- .tar(name, files) ⇒ Object
- .untar(file) ⇒ Object
Class Method Details
.rm_rf(dir) ⇒ Object
these folders could contain 100s of thousands of files faster to just mv the folder out of the way and delete it in a forked process
7 8 9 10 11 12 13 14 15 |
# File 'lib/distributed_cache/utils.rb', line 7 def self.rm_rf(dir) return unless File.exists?(dir) time = Time.now.to_i dest_dir = "#{dir}.#{time}" FileUtils.mv dir, dest_dir Process.fork do FileUtils.rm_rf dest_dir end end |
.rsync(server) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/distributed_cache/utils.rb', line 45 def self.rsync(server) cmd = "rsync -alrz #{DistributedCache.config.bundle_dir}/ #{DistributedCache.config.file_server_user}@#{server}:#{DistributedCache.config.file_server_bundle_dir}/" `#{cmd}`.tap do status = $? raise "failed to (#{cmd}), status #{status}" unless status == 0 end end |
.tar(name, files) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/distributed_cache/utils.rb', line 17 def self.tar(name, files) cmd = if name[-3..-1] == 'tgz' "tar zcf #{name} #{files}" else "tar cf #{name} #{files}" end `#{cmd}`.tap do status = $? raise "failed to (#{cmd}), status #{status}" unless status == 0 end end |
.untar(file) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/distributed_cache/utils.rb', line 31 def self.untar(file) cmd = if file[-3..-1] == 'tgz' "tar zxf #{file}" else "tar xf #{file}" end `#{cmd}`.tap do status = $? raise "failed to (#{cmd}), status #{status}" unless status == 0 end end |