Class: Train::File::Local::Unix

Inherits:
Train::File::Local show all
Defined in:
lib/train/file/local/unix.rb

Constant Summary

Constants inherited from Train::File

DATA_FIELDS

Instance Method Summary collapse

Methods inherited from Train::File::Local

#block_device?, #character_device?, #content, #link_path, #linked_to?, #mode?, #shallow_link_path, #type

Methods inherited from Train::File

#block_device?, #character_device?, #directory?, #file?, #file_version, #initialize, #md5sum, #mounted?, #owned_by?, #path, #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

#grouped_into?(sth) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/train/file/local/unix.rb', line 53

def grouped_into?(sth)
  group == sth
end

#mountedObject



48
49
50
51
# File 'lib/train/file/local/unix.rb', line 48

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

#sanitize_filename(path) ⇒ Object



10
11
12
# File 'lib/train/file/local/unix.rb', line 10

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

#statObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/train/file/local/unix.rb', line 14

def stat
  return @stat if defined?(@stat)

  begin
    file_stat =
      if @follow_symlink
        ::File.stat(@path)
      else
        ::File.lstat(@path)
      end
  rescue StandardError => _err
    return @stat = {}
  end

  @stat = {
    type: Train::Extras::Stat.find_type(file_stat.mode),
    mode: file_stat.mode & 07777,
    mtime: file_stat.mtime.to_i,
    size: file_stat.size,
    owner: pw_username(file_stat.uid),
    uid: file_stat.uid,
    group: pw_groupname(file_stat.gid),
    gid: file_stat.gid,
  }

  lstat = @follow_symlink ? ' -L' : ''
  res = @backend.run_command("stat#{lstat} #{@spath} 2>/dev/null --printf '%C'")
  if res.exit_status == 0 && !res.stdout.empty? && res.stdout != '?'
    @stat[:selinux_label] = res.stdout.strip
  end

  @stat
end

#unix_mode_mask(owner, type) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/train/file/local/unix.rb', line 57

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