Class/Module Index [+]

Quicksearch

Pkg::Util::File

Utility methods for handling files and directories

Public Class Methods

empty_dir?(dir) click to toggle source
# 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
erb_file(erbfile, outfile=nil, remove_orig = false, opts = { :binding => binding }) click to toggle source
# 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
erb_string(erbfile, b = binding) click to toggle source
# 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_exists?(file, args={:required => false}) click to toggle source
# 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_writable?(file, args={:required => false}) click to toggle source
# 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
get_temp() click to toggle source
Alias for: mktemp
mktemp() click to toggle source
# 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
Also aliased as: get_temp
untar_into(source, target = nil, options = "") click to toggle source
# 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.