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