Class: Train::Extras::UnixFile

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

Direct Known Subclasses

AixFile, LinuxFile

Constant Summary

Constants inherited from FileCommon

FileCommon::DATA_FIELDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FileCommon

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

Constructor Details

#initialize(backend, path, follow_symlink = true) ⇒ UnixFile

Returns a new instance of UnixFile.



11
12
13
14
# 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

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



16
17
18
19
20
21
22
23
24
25
# 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?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
# 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_versionObject



57
58
59
# File 'lib/train/extras/file_unix.rb', line 57

def file_version
  nil
end

#mountedObject



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

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

#product_versionObject



53
54
55
# File 'lib/train/extras/file_unix.rb', line 53

def product_version
  nil
end

#statObject



61
62
63
64
# 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