class Train::Extras::UnixFile

Attributes

path[R]

Public Class Methods

new(backend, path, follow_symlink = true) click to toggle source
Calls superclass method Train::Extras::FileCommon::new
# File lib/train/extras/file_unix.rb, line 11
def initialize(backend, path, follow_symlink = true)
  super(backend, path, follow_symlink)
  @spath = Shellwords.escape(@path)
end

Public Instance Methods

content() click to toggle source
# File lib/train/extras/file_unix.rb, line 16
def content
  @content ||= case
               when !exist?, directory?
                 nil
               when size.nil?, size == 0
                 ''
               else
                 @backend.run_command("cat #{@spath}").stdout || ''
               end
end
exist?() click to toggle source
# File lib/train/extras/file_unix.rb, line 27
def exist?
  @exist ||= (
    f = @follow_symlink ? '' : " || test -L #{@spath}"
    @backend.run_command("test -e #{@spath}"+f)
            .exit_status == 0
  )
end
file_version() click to toggle source
# File lib/train/extras/file_unix.rb, line 57
def file_version
  nil
end
mounted() click to toggle source
# File lib/train/extras/file_unix.rb, line 40
def mounted
  @mounted ||=
    @backend.run_command("mount | grep -- ' on #{@spath} '")
end
product_version() click to toggle source
# File lib/train/extras/file_unix.rb, line 53
def product_version
  nil
end
stat() click to toggle source
# File lib/train/extras/file_unix.rb, line 61
def stat
  return @stat if defined?(@stat)
  @stat = Train::Extras::Stat.stat(@spath, @backend, @follow_symlink)
end

Private Instance Methods

read_target_path() click to toggle source

Returns full path of a symlink target(real dest) or '' on symlink loop

# File lib/train/extras/file_unix.rb, line 69
def read_target_path
  full_path = @backend.run_command("readlink -n #{@spath} -f").stdout
  # Needed for some OSes like OSX that returns relative path
  # when the link and target are in the same directory
  if !full_path.start_with?('/') && full_path != ''
    full_path = File.expand_path("../#{full_path}", @spath)
  end
  full_path
end