class Train::Transports::Local::Connection::File
Public Instance Methods
block_device?()
click to toggle source
# File lib/train/transports/local_file.rb, line 34 def block_device? ::File.blockdev?(@path) end
character_device?()
click to toggle source
# File lib/train/transports/local_file.rb, line 38 def character_device? ::File.chardev?(@path) end
content()
click to toggle source
# File lib/train/transports/local_file.rb, line 10 def content @content ||= ::File.read(@path, encoding: 'UTF-8') rescue StandardError => _ nil end
link_path()
click to toggle source
# File lib/train/transports/local_file.rb, line 24 def link_path return nil unless symlink? begin @link_path ||= ::File.realpath(@path) rescue Errno::ELOOP => _ # Leave it blank on symbolic loop, same as readlink @link_path = '' end end
Private Instance Methods
pw_groupname(gid)
click to toggle source
# File lib/train/transports/local_file.rb, line 50 def pw_groupname(gid) Etc.getgrgid(gid).name rescue ArgumentError => _ nil end
pw_username(uid)
click to toggle source
# File lib/train/transports/local_file.rb, line 44 def pw_username(uid) Etc.getpwuid(uid).name rescue ArgumentError => _ nil end
stat()
click to toggle source
# File lib/train/transports/local_file.rb, line 56 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 & 00777, 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