Class: Train::Extras::LinuxFile

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

Direct Known Subclasses

AixFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FileCommon

#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) ⇒ LinuxFile



11
12
13
14
15
# File 'lib/train/extras/linux_file.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/linux_file.rb', line 10

def path
  @path
end

Instance Method Details

#contentObject



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

def content
  return @content if defined?(@content)
  @content = @backend.run_command(
    "cat #{@spath} || echo -n").stdout
  return @content unless @content.empty?
  @content = nil if directory? or size.nil? or size > 0
  @content
end

#exist?Boolean



26
27
28
29
30
31
# File 'lib/train/extras/linux_file.rb', line 26

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

#file_versionObject



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

def file_version
  nil
end


39
40
41
42
43
44
# File 'lib/train/extras/linux_file.rb', line 39

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


33
34
35
36
37
# File 'lib/train/extras/linux_file.rb', line 33

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



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

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

#product_versionObject



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

def product_version
  nil
end

#statObject



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

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