Class: Train::Extras::UnixFile

Inherits:
FileCommon show all
Defined in:
lib/train/extras/file_unix.rb

Direct Known Subclasses

AixFile, LinuxFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FileCommon

#basename, #block_device?, #character_device?, #directory?, #file?, #grouped_into?, #linked_to?, #md5sum, #mode?, #mounted?, #owned_by?, #pipe?, #sha256sum, #socket?, #symlink?, #type, #unix_mode_mask, #version?

Constructor Details

#initialize(backend, path) ⇒ UnixFile

Returns a new instance of UnixFile.



11
12
13
14
15
# File 'lib/train/extras/file_unix.rb', line 11

def initialize(backend, path)
  @backend = backend
  @path = path
  @spath = Shellwords.escape(@path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/train/extras/file_unix.rb', line 10

def path
  @path
end

Instance Method Details

#contentObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/train/extras/file_unix.rb', line 17

def content
  @content ||= case
               when !exist?, directory?
                 nil
               when size.nil?, size == 0
                 ''
               else
                 @backend.run_command("cat #{@spath}").stdout || ''
               end
end

#exist?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'lib/train/extras/file_unix.rb', line 28

def exist?
  @exist ||= (
    @backend.run_command("test -e #{@spath}")
            .exit_status == 0
  )
end

#file_versionObject



64
65
66
# File 'lib/train/extras/file_unix.rb', line 64

def file_version
  nil
end


41
42
43
44
45
# File 'lib/train/extras/file_unix.rb', line 41

def link_path
  return nil unless symlink?
  @link_path ||=
    @backend.run_command("readlink #{@spath}").stdout.chomp
end


35
36
37
38
39
# File 'lib/train/extras/file_unix.rb', line 35

def link_target
  return @link_target if defined? @link_target
  return @link_target = nil if link_path.nil?
  @link_target = @backend.file(link_path)
end

#mountedObject



47
48
49
50
# File 'lib/train/extras/file_unix.rb', line 47

def mounted
  @mounted ||=
    @backend.run_command("mount | grep -- ' on #{@spath}'")
end

#product_versionObject



60
61
62
# File 'lib/train/extras/file_unix.rb', line 60

def product_version
  nil
end

#statObject



68
69
70
71
# File 'lib/train/extras/file_unix.rb', line 68

def stat
  return @stat if defined?(@stat)
  @stat = Train::Extras::Stat.stat(@spath, @backend)
end