module DistributedCache::Utils

Public Class Methods

rm_rf(dir) click to toggle source

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

# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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