lxc-config/hooks/lib/lxc/utils.rb

23 lines
475 B
Ruby
Raw Normal View History

2015-01-30 08:08:18 +00:00
require "fileutils"
module Lxc
module Utils
def self.safe_write(path, content)
dir = File.dirname(path)
unless Dir.exist?(dir)
FileUtils.mkdir_p(dir)
end
temp_path = path.to_s + ".tmp"
File.open(temp_path, 'w+') do |f|
f.write(content)
end
FileUtils.mv(temp_path, path)
end
def self.sh(cmd, *args)
puts "$ #{cmd} " + args.map {|a| "'#{a}'" }.join(" ")
system(cmd, *args)
end
end
end