Utility methods for handling files and directories
# File ext/packaging/lib/packaging/util/file.rb, line 11 def empty_dir?(dir) File.exist?(dir) and File.directory?(dir) and Dir["#{dir}/**/*"].empty? end
# File ext/packaging/lib/packaging/util/file.rb, line 39 def erb_file(erbfile, outfile=nil, remove_orig = false, opts = { :binding => binding }) outfile ||= File.join(mktemp, File.basename(erbfile).sub(File.extname(erbfile),"")) output = erb_string(erbfile, opts[:binding]) File.open(outfile, 'w') { |f| f.write output } puts "Generated: #{outfile}" FileUtils.rm_rf erbfile if remove_orig outfile end
# File ext/packaging/lib/packaging/util/file.rb, line 33 def erb_string(erbfile, b = binding) template = File.read(erbfile) message = ERB.new(template, nil, "-") message.result(b) end
# File ext/packaging/lib/packaging/util/file.rb, line 15 def file_exists?(file, args={:required => false}) exists = File.exist? file if !exists and args[:required] fail "Required file #{file} could not be found" end exists end
# File ext/packaging/lib/packaging/util/file.rb, line 23 def file_writable?(file, args={:required => false}) writable = File.writable? file if !writable and args[:required] fail "File #{file} is not writable" end writable end
# File ext/packaging/lib/packaging/util/file.rb, line 6 def mktemp mktemp = Pkg::Util::Tool.find_tool('mktemp', :required => true) `#{mktemp} -d -t pkgXXXXXX`.strip end
# File ext/packaging/lib/packaging/util/file.rb, line 48 def untar_into(source, target = nil, options = "") tar = Pkg::Util::Tool.find_tool('tar', :required => true) # We only accept a writable directory as a target if target and !target.empty? and file_writable?(target) and File.directory?(target) target_opts = "-C #{target}" end if file_exists?(source, :required => true) ex(%[#{tar} #{options} #{target_opts} -xf #{source}]) end end
Generated with the Darkfish Rdoc Generator 2.