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
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/train/file/remote/unix.rb', line 12
def content
@content ||=
if !exist? || directory?
nil
elsif size.nil? || size == 0
""
else
@backend.run_command("cat #{@spath}").stdout || ""
end
end
|
#content=(new_content) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/train/file/remote/unix.rb', line 23
def content=(new_content)
execute_result = @backend.run_command("base64 --help")
if execute_result.exit_status != 0
raise TransportError, "#{self.class} found no base64 binary for file writes"
end
unix_cmd = format("echo '%<base64>s' | base64 --decode > %<file>s",
base64: Base64.strict_encode64(new_content),
file: @spath)
@backend.run_command(unix_cmd)
@content = new_content
end
|
#exist? ⇒ Boolean
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/train/file/remote/unix.rb', line 38
def exist?
@exist ||= begin
f = @follow_symlink ? "" : " || test -L #{@spath}"
if @backend.platform.solaris?
@backend.run_command("/usr/bin/test -e #{@spath}" + f)
else
@backend.run_command("test -e #{@spath}" + f)
end.exit_status == 0
end
end
|
#grouped_into?(sth) ⇒ Boolean
69
70
71
|
# File 'lib/train/file/remote/unix.rb', line 69
def grouped_into?(sth)
group == sth
end
|
#link_path ⇒ Object
77
78
79
|
# File 'lib/train/file/remote/unix.rb', line 77
def link_path
symlink? ? path : nil
end
|
#linked_to?(dst) ⇒ Boolean
73
74
75
|
# File 'lib/train/file/remote/unix.rb', line 73
def linked_to?(dst)
link_path == dst
end
|
#mode?(sth) ⇒ Boolean
65
66
67
|
# File 'lib/train/file/remote/unix.rb', line 65
def mode?(sth)
mode == sth
end
|
#mounted ⇒ Object
52
53
54
55
|
# File 'lib/train/file/remote/unix.rb', line 52
def mounted
@mounted ||=
@backend.run_command("mount | grep -- ' on #{@path} '")
end
|
#path ⇒ Object
98
99
100
101
102
|
# File 'lib/train/file/remote/unix.rb', line 98
def path
return @path unless @follow_symlink && symlink?
@link_path ||= read_target_path
end
|
#sanitize_filename(path) ⇒ Object
8
9
10
|
# File 'lib/train/file/remote/unix.rb', line 8
def sanitize_filename(path)
@spath = Shellwords.escape(path) || @path
end
|
#shallow_link_path ⇒ Object
81
82
83
84
85
86
|
# File 'lib/train/file/remote/unix.rb', line 81
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
88
89
90
91
92
93
94
95
96
|
# File 'lib/train/file/remote/unix.rb', line 88
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
|