Class: TargetIO::TrainCompat::FileUtils
- Inherits:
-
Object
- Object
- TargetIO::TrainCompat::FileUtils
show all
- Extended by:
- Support
- Defined in:
- lib/chef/target_io/train/fileutils.rb
Class Method Summary
collapse
-
.chmod(mode, list, noop: nil, verbose: nil) ⇒ Object
-
.chmod_R(mode, list, noop: nil, verbose: nil, force: nil) ⇒ Object
-
.chown(user, group, list, noop: nil, verbose: nil) ⇒ Object
-
.chown_R(user, group, list, noop: nil, verbose: nil, force: nil) ⇒ Object
-
.cp(src, dest, preserve: nil, noop: nil, verbose: nil) ⇒ Object
(also: copy)
-
.cp_lr(src, dest, noop: nil, verbose: nil, dereference_root: true, remove_destination: false) ⇒ Object
-
.cp_r(src, dest, preserve: nil, noop: nil, verbose: nil, dereference_root: true, remove_destination: nil) ⇒ Object
-
.install(src, dest, mode: nil, owner: nil, group: nil, preserve: nil, noop: nil, verbose: nil) ⇒ Object
getwd (alias pwd) have_option? identical? (alias compare_file).
-
.ln(src, dest, force: nil, noop: nil, verbose: nil) ⇒ Object
(also: link)
-
.ln_s(src, dest, force: nil, noop: nil, verbose: nil) ⇒ Object
(also: symlink)
-
.ln_sf(src, dest, noop: nil, verbose: nil) ⇒ Object
-
.method_missing(m, *_args, **_kwargs, &_block) ⇒ Object
-
.mkdir(list, mode: nil, noop: nil, verbose: nil) ⇒ Object
-
.mkdir_p(list, mode: nil, noop: nil, verbose: nil) ⇒ Object
(also: makedirs, mkpath)
-
.mv(src, dest, force: nil, noop: nil, verbose: nil, secure: nil) ⇒ Object
-
.rm(list, force: nil, noop: nil, verbose: nil) ⇒ Object
-
.rm_f(list, force: nil, noop: nil, verbose: nil, secure: nil) ⇒ Object
-
.rm_r(list, force: nil, noop: nil, verbose: nil, secure: nil) ⇒ Object
-
.rm_rf(list, noop: nil, verbose: nil, secure: nil) ⇒ Object
(also: remove_entry, rmtree, safe_unlink)
-
.rmdir(list, parents: nil, noop: nil, verbose: nil) ⇒ Object
-
.touch(list, noop: nil, verbose: nil, mtime: nil, nocreate: nil) ⇒ Object
Methods included from Support
clean_staging, read_file, remote_user, run_command, staging_file, sudo?, transport_connection, upload, write_file
Class Method Details
.chmod(mode, list, noop: nil, verbose: nil) ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'lib/chef/target_io/train/fileutils.rb', line 9
def chmod(mode, list, noop: nil, verbose: nil)
cmd = sprintf("chmod %s %s", __mode_to_s(mode), Array(list).join(" "))
Chef::Log.debug cmd if verbose
return if noop
run_command(cmd)
end
|
.chmod_R(mode, list, noop: nil, verbose: nil, force: nil) ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'lib/chef/target_io/train/fileutils.rb', line 18
def chmod_R(mode, list, noop: nil, verbose: nil, force: nil)
cmd = sprintf("chmod -R%s %s %s", (force ? "f" : ""), mode_to_s(mode), Array(list).join(" "))
Chef::Log.debug cmd if verbose
return if noop
run_command(cmd)
end
|
.chown(user, group, list, noop: nil, verbose: nil) ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/chef/target_io/train/fileutils.rb', line 27
def chown(user, group, list, noop: nil, verbose: nil)
cmd = sprintf("chown %s %s", (group ? "#{user}:#{group}" : user || ":"), Array(list).join(" "))
Chef::Log.debug cmd if verbose
return if noop
run_command(cmd)
end
|
.chown_R(user, group, list, noop: nil, verbose: nil, force: nil) ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'lib/chef/target_io/train/fileutils.rb', line 36
def chown_R(user, group, list, noop: nil, verbose: nil, force: nil)
cmd = sprintf("chown -R%s %s %s", (force ? "f" : ""), (group ? "#{user}:#{group}" : user || ":"), Array(list).join(" "))
Chef::Log.debug cmd if verbose
return if noop
run_command(cmd)
end
|
.cp(src, dest, preserve: nil, noop: nil, verbose: nil) ⇒ Object
Also known as:
copy
45
46
47
48
49
50
51
52
|
# File 'lib/chef/target_io/train/fileutils.rb', line 45
def cp(src, dest, preserve: nil, noop: nil, verbose: nil)
cmd = "cp#{preserve ? " -p" : ""} #{[src, dest].flatten.join(" ")}"
Chef::Log.debug cmd if verbose
return if noop
run_command(cmd)
end
|
.cp_lr(src, dest, noop: nil, verbose: nil, dereference_root: true, remove_destination: false) ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'lib/chef/target_io/train/fileutils.rb', line 55
def cp_lr(src, dest, noop: nil, verbose: nil, dereference_root: true, remove_destination: false)
cmd = "cp -lr#{remove_destination ? " --remove-destination" : ""} #{[src, dest].flatten.join(" ")}"
Chef::Log.debug cmd if verbose
return if noop
run_command(cmd)
end
|
.cp_r(src, dest, preserve: nil, noop: nil, verbose: nil, dereference_root: true, remove_destination: nil) ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/chef/target_io/train/fileutils.rb', line 64
def cp_r(src, dest, preserve: nil, noop: nil, verbose: nil, dereference_root: true, remove_destination: nil)
cmd = "cp -r#{preserve ? "p" : ""}#{remove_destination ? " --remove-destination" : ""} #{[src, dest].flatten.join(" ")}"
Chef::Log.debug cmd if verbose
return if noop
run_command(cmd)
end
|
.install(src, dest, mode: nil, owner: nil, group: nil, preserve: nil, noop: nil, verbose: nil) ⇒ Object
getwd (alias pwd)
have_option?
identical? (alias compare_file)
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/chef/target_io/train/fileutils.rb', line 77
def install(src, dest, mode: nil, owner: nil, group: nil, preserve: nil, noop: nil, verbose: nil)
cmd = "install -c"
cmd << " -p" if preserve
cmd << " -m " << mode_to_s(mode) if mode
cmd << " -o #{owner}" if owner
cmd << " -g #{group}" if group
cmd << " " << [src, dest].flatten.join(" ")
Chef::Log.debug cmd if verbose
return if noop
run_command(cmd)
end
|
.ln(src, dest, force: nil, noop: nil, verbose: nil) ⇒ Object
Also known as:
link
91
92
93
94
95
96
97
98
|
# File 'lib/chef/target_io/train/fileutils.rb', line 91
def ln(src, dest, force: nil, noop: nil, verbose: nil)
cmd = "ln#{force ? " -f" : ""} #{[src, dest].flatten.join(" ")}"
Chef::Log.debug cmd if verbose
return if noop
run_command(cmd)
end
|
.ln_s(src, dest, force: nil, noop: nil, verbose: nil) ⇒ Object
Also known as:
symlink
101
102
103
104
105
106
107
108
|
# File 'lib/chef/target_io/train/fileutils.rb', line 101
def ln_s(src, dest, force: nil, noop: nil, verbose: nil)
cmd = "ln -s#{force ? "f" : ""} #{[src, dest].flatten.join(" ")}"
Chef::Log.debug cmd if verbose
return if noop
run_command(cmd)
end
|
.ln_sf(src, dest, noop: nil, verbose: nil) ⇒ Object
111
112
113
|
# File 'lib/chef/target_io/train/fileutils.rb', line 111
def ln_sf(src, dest, noop: nil, verbose: nil)
ln_s(src, dest, force: true, noop: noop, verbose: verbose)
end
|
.method_missing(m, *_args, **_kwargs, &_block) ⇒ Object
188
189
190
|
# File 'lib/chef/target_io/train/fileutils.rb', line 188
def method_missing(m, *_args, **_kwargs, &_block)
raise "Unsupported #{self.class} method #{m}"
end
|
.mkdir(list, mode: nil, noop: nil, verbose: nil) ⇒ Object
115
116
117
118
119
120
121
122
|
# File 'lib/chef/target_io/train/fileutils.rb', line 115
def mkdir(list, mode: nil, noop: nil, verbose: nil)
cmd = "mkdir #{mode ? ("-m %03o " % mode) : ""}#{Array(list).join(" ")}"
Chef::Log.debug cmd if verbose
return if noop
run_command(cmd)
end
|
.mkdir_p(list, mode: nil, noop: nil, verbose: nil) ⇒ Object
Also known as:
makedirs, mkpath
124
125
126
127
128
129
130
131
|
# File 'lib/chef/target_io/train/fileutils.rb', line 124
def mkdir_p(list, mode: nil, noop: nil, verbose: nil)
cmd = "mkdir -p #{mode ? ("-m %03o " % mode) : ""}#{Array(list).join(" ")}"
Chef::Log.debug cmd if verbose
return if noop
run_command(cmd)
end
|
.mv(src, dest, force: nil, noop: nil, verbose: nil, secure: nil) ⇒ Object
135
136
137
138
139
140
141
142
|
# File 'lib/chef/target_io/train/fileutils.rb', line 135
def mv(src, dest, force: nil, noop: nil, verbose: nil, secure: nil)
cmd = "mv#{force ? " -f" : ""} #{[src, dest].flatten.join(" ")}"
Chef::Log.debug cmd if verbose
return if noop
run_command(cmd)
end
|
.rm(list, force: nil, noop: nil, verbose: nil) ⇒ Object
144
145
146
147
148
149
150
151
|
# File 'lib/chef/target_io/train/fileutils.rb', line 144
def rm(list, force: nil, noop: nil, verbose: nil)
cmd = "rm#{force ? " -f" : ""} #{Array(list).join(" ")}"
Chef::Log.debug cmd if verbose
return if noop
run_command(cmd)
end
|
.rm_f(list, force: nil, noop: nil, verbose: nil, secure: nil) ⇒ Object
153
154
155
|
# File 'lib/chef/target_io/train/fileutils.rb', line 153
def rm_f(list, force: nil, noop: nil, verbose: nil, secure: nil)
rm(list, force: true, noop: noop, verbose: verbose)
end
|
.rm_r(list, force: nil, noop: nil, verbose: nil, secure: nil) ⇒ Object
157
158
159
160
161
162
163
164
|
# File 'lib/chef/target_io/train/fileutils.rb', line 157
def rm_r(list, force: nil, noop: nil, verbose: nil, secure: nil)
cmd = "rm -r#{force ? "f" : ""} #{Array(list).join(" ")}"
Chef::Log.debug cmd if verbose
return if noop
run_command(cmd)
end
|
.rm_rf(list, noop: nil, verbose: nil, secure: nil) ⇒ Object
Also known as:
remove_entry, rmtree, safe_unlink
166
167
168
|
# File 'lib/chef/target_io/train/fileutils.rb', line 166
def rm_rf(list, noop: nil, verbose: nil, secure: nil)
rm_r(list, force: true, noop: noop, verbose: verbose, secure: secure)
end
|
.rmdir(list, parents: nil, noop: nil, verbose: nil) ⇒ Object
173
174
175
176
177
178
179
180
|
# File 'lib/chef/target_io/train/fileutils.rb', line 173
def rmdir(list, parents: nil, noop: nil, verbose: nil)
cmd = "rmdir #{parents ? "-p " : ""}#{Array(list).join(" ")}"
Chef::Log.debug cmd if verbose
return if noop
run_command(cmd)
end
|
.touch(list, noop: nil, verbose: nil, mtime: nil, nocreate: nil) ⇒ Object
182
183
184
185
186
|
# File 'lib/chef/target_io/train/fileutils.rb', line 182
def touch(list, noop: nil, verbose: nil, mtime: nil, nocreate: nil)
return if noop
run_command "touch #{nocreate ? "-c " : ""}#{mtime ? mtime.strftime("-t %Y%m%d%H%M.%S ") : ""}#{Array(list).join(" ")}"
end
|