Class: TargetIO::TrainCompat::Dir
- Inherits:
-
Object
- Object
- TargetIO::TrainCompat::Dir
- Defined in:
- lib/chef/target_io/train/dir.rb
Class Method Summary collapse
-
.[](*patterns, base: ".", sort: true) ⇒ Object
TODO: chdir, mktmpdir, pwd, home (Used in Resources).
- .__run_command(cmd) ⇒ Object
- .__transport_connection ⇒ Object
- .delete(dir_name) ⇒ Object
- .directory?(dir_name) ⇒ Boolean
- .entries(dirname) ⇒ Object
- .glob(pattern, flags = 0, base: ".", sort: true) ⇒ Object
- .mkdir(dir_name, mode = nil) ⇒ Object
- .unlink(dir_name) ⇒ Object
Class Method Details
.[](*patterns, base: ".", sort: true) ⇒ Object
TODO: chdir, mktmpdir, pwd, home (Used in Resources)
10 11 12 |
# File 'lib/chef/target_io/train/dir.rb', line 10 def [](*patterns, base: ".", sort: true) Dir.glob(patterns, 0, base, sort) end |
.__run_command(cmd) ⇒ Object
59 60 61 |
# File 'lib/chef/target_io/train/dir.rb', line 59 def __run_command(cmd) __transport_connection.run_command(cmd) end |
.__transport_connection ⇒ Object
63 64 65 |
# File 'lib/chef/target_io/train/dir.rb', line 63 def __transport_connection Chef.run_context&.transport_connection end |
.delete(dir_name) ⇒ Object
14 15 16 |
# File 'lib/chef/target_io/train/dir.rb', line 14 def delete(dir_name) ::TargetIO::FileUtils.rm_rf(dir_name) end |
.directory?(dir_name) ⇒ Boolean
18 19 20 |
# File 'lib/chef/target_io/train/dir.rb', line 18 def directory?(dir_name) ::TargetIO::File.directory? dir_name end |
.entries(dirname) ⇒ Object
22 23 24 25 26 |
# File 'lib/chef/target_io/train/dir.rb', line 22 def entries(dirname) cmd = "ls -1a #{dirname}" output = __run_command(cmd).stdout output.split("\n") end |
.glob(pattern, flags = 0, base: ".", sort: true) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/chef/target_io/train/dir.rb', line 28 def glob(pattern, flags = 0, base: ".", sort: true) raise "Dir.glob flags not supported except FNM_DOTMATCH" unless [0, ::File::FNM_DOTMATCH].include? flags pattern = Array(pattern) matchdot = flags || ::File::FNM_DOTMATCH ? "dotglob" : "" # TODO: Check for bash remotely cmd += <<-BASH4 shopt -s globstar #{matchdot} cd #{base} for f in #{pattern.join(" ")}; do printf '%s\n' "$f"; done BASH4 output = __run_command(cmd).stdout files = output.split("\n") files.sort! if sort files end |