Class: Train::File::Remote::Unix
  
  
  
  Constant Summary
  
  Constants inherited
     from Train::File
  DATA_FIELDS
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  #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 Method Details
    
      
  
  
    #content  ⇒ Object 
  
  
  
  
    | 
11
12
13
14
15
16
17
18
19
20 | # File 'lib/train/file/remote/unix.rb', line 11
def content
  @content ||=
    if !exist? || directory?
      nil
    elsif size.nil? || size == 0
      ""
    else
      @backend.run_command("cat #{@spath}").stdout || ""
    end
end | 
 
    
      
  
  
    #exist?  ⇒ Boolean 
  
  
  
  
    | 
22
23
24
25
26
27
28 | # File 'lib/train/file/remote/unix.rb', line 22
def exist?
  @exist ||= begin
    f = @follow_symlink ? "" : " || test -L #{@spath}"
    @backend.run_command("test -e #{@spath}" + f)
      .exit_status == 0
  end
end | 
 
    
      
  
  
    #grouped_into?(sth)  ⇒ Boolean 
  
  
  
  
    | 
47
48
49 | # File 'lib/train/file/remote/unix.rb', line 47
def grouped_into?(sth)
  group == sth
end | 
 
    
      
  
  
    #link_path  ⇒ Object 
  
  
  
  
    | 
55
56
57 | # File 'lib/train/file/remote/unix.rb', line 55
def link_path
  symlink? ? path : nil
end | 
 
    
      
  
  
    #linked_to?(dst)  ⇒ Boolean 
  
  
  
  
    | 
51
52
53 | # File 'lib/train/file/remote/unix.rb', line 51
def linked_to?(dst)
  link_path == dst
end | 
 
    
      
  
  
    #mode?(sth)  ⇒ Boolean 
  
  
  
  
    | 
43
44
45 | # File 'lib/train/file/remote/unix.rb', line 43
def mode?(sth)
  mode == sth
end | 
 
    
      
  
  
    #mounted  ⇒ Object 
  
  
  
  
    | 
30
31
32
33 | # File 'lib/train/file/remote/unix.rb', line 30
def mounted
  @mounted ||=
    @backend.run_command("mount | grep -- ' on #{@path} '")
end | 
 
    
      
  
  
    #path  ⇒ Object 
  
  
  
  
    | 
76
77
78
79
80 | # File 'lib/train/file/remote/unix.rb', line 76
def path
  return @path unless @follow_symlink && symlink?
  @link_path ||= read_target_path
end | 
 
    
      
  
  
    #sanitize_filename(path)  ⇒ Object 
  
  
  
  
    | 
7
8
9 | # File 'lib/train/file/remote/unix.rb', line 7
def sanitize_filename(path)
  @spath = Shellwords.escape(path) || @path
end | 
 
    
      
  
  
    #shallow_link_path  ⇒ Object 
  
  
  
  
    | 
59
60
61
62
63
64 | # File 'lib/train/file/remote/unix.rb', line 59
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 
  
  
  
  
    | 
66
67
68
69
70
71
72
73
74 | # File 'lib/train/file/remote/unix.rb', line 66
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 |