Class: TargetIO::TrainCompat::FileUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/target_io/train/fileutils.rb

Class Method Summary collapse

Class Method Details

.chmod(mode, list, noop: nil, verbose: nil) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/chef/target_io/train/fileutils.rb', line 5

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



14
15
16
17
18
19
20
21
# File 'lib/chef/target_io/train/fileutils.rb', line 14

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



23
24
25
26
27
28
29
30
# File 'lib/chef/target_io/train/fileutils.rb', line 23

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



32
33
34
35
36
37
38
39
# File 'lib/chef/target_io/train/fileutils.rb', line 32

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

cmp collect_method commands compare_file compare_stream



47
48
49
50
51
52
53
54
# File 'lib/chef/target_io/train/fileutils.rb', line 47

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



57
58
59
60
61
62
63
64
# File 'lib/chef/target_io/train/fileutils.rb', line 57

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



66
67
68
69
70
71
72
73
# File 'lib/chef/target_io/train/fileutils.rb', line 66

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)



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/chef/target_io/train/fileutils.rb', line 79

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



93
94
95
96
97
98
99
100
# File 'lib/chef/target_io/train/fileutils.rb', line 93

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



103
104
105
106
107
108
109
110
# File 'lib/chef/target_io/train/fileutils.rb', line 103

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



113
114
115
# File 'lib/chef/target_io/train/fileutils.rb', line 113

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

uptodate?



199
200
201
# File 'lib/chef/target_io/train/fileutils.rb', line 199

def method_missing(m, *_args, **_kwargs, &_block)
  raise "Unsupported #{self.class} method #{m}"
end

.mkdir(list, mode: nil, noop: nil, verbose: nil) ⇒ Object



117
118
119
120
121
122
123
124
# File 'lib/chef/target_io/train/fileutils.rb', line 117

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



126
127
128
129
130
131
132
133
# File 'lib/chef/target_io/train/fileutils.rb', line 126

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



137
138
139
140
141
142
143
144
# File 'lib/chef/target_io/train/fileutils.rb', line 137

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

options options_of pwd remove remove_entry_secure remove_file



153
154
155
156
157
158
159
160
# File 'lib/chef/target_io/train/fileutils.rb', line 153

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



162
163
164
# File 'lib/chef/target_io/train/fileutils.rb', line 162

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



166
167
168
169
170
171
172
173
# File 'lib/chef/target_io/train/fileutils.rb', line 166

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



175
176
177
# File 'lib/chef/target_io/train/fileutils.rb', line 175

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



182
183
184
185
186
187
188
189
# File 'lib/chef/target_io/train/fileutils.rb', line 182

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



191
192
193
194
195
# File 'lib/chef/target_io/train/fileutils.rb', line 191

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