Class: Train::File::Remote::Unix

Inherits:
Train::File::Remote show all
Defined in:
lib/train/file/remote/unix.rb

Direct Known Subclasses

Aix, Linux, Qnx

Constant Summary

Constants inherited from Train::File

DATA_FIELDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Train::File::Remote

#basename, #stat

Methods inherited from Train::File

#block_device?, #character_device?, #directory?, #file?, #file_version, #initialize, #md5sum, #mounted?, #owned_by?, #pipe?, #product_version, #sha256sum, #socket?, #source, #source_path, #symlink?, #to_json, #type, #version?

Constructor Details

This class inherits a constructor from Train::File

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/train/file/remote/unix.rb', line 9

def path
  @path
end

Instance Method Details

#contentObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/train/file/remote/unix.rb', line 15

def content
  @content ||=
    if !exist? || directory?
      nil
    elsif size.nil? || size.zero?
      ''
    else
      @backend.run_command("cat #{@spath}").stdout || ''
    end
end

#exist?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# File 'lib/train/file/remote/unix.rb', line 26

def exist?
  @exist ||= (
    f = @follow_symlink ? '' : " || test -L #{@spath}"
    @backend.run_command("test -e #{@spath}"+f)
            .exit_status == 0
  )
end

#grouped_into?(sth) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/train/file/remote/unix.rb', line 51

def grouped_into?(sth)
  group == sth
end


59
60
61
# File 'lib/train/file/remote/unix.rb', line 59

def link_path
  symlink? ? path : nil
end

#linked_to?(dst) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/train/file/remote/unix.rb', line 55

def linked_to?(dst)
  link_path == dst
end

#mode?(sth) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/train/file/remote/unix.rb', line 47

def mode?(sth)
  mode == sth
end

#mountedObject



34
35
36
37
# File 'lib/train/file/remote/unix.rb', line 34

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

#sanitize_filename(path) ⇒ Object



11
12
13
# File 'lib/train/file/remote/unix.rb', line 11

def sanitize_filename(path)
  @spath = Shellwords.escape(path) || @path
end


63
64
65
66
67
# File 'lib/train/file/remote/unix.rb', line 63

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

#unix_mode_mask(owner, type) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/train/file/remote/unix.rb', line 69

def unix_mode_mask(owner, type)
  o = UNIX_MODE_OWNERS[owner.to_sym]
  return nil if o.nil?

  t = UNIX_MODE_TYPES[type.to_sym]
  return nil if t.nil?

  t & o
end