class TargetIO::TrainCompat::Dir

Public Class Methods

[](*patterns, base: ".", sort: true) click to toggle source

TODO: chdir, mktmpdir, pwd, home (Used in Resources)

# 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) click to toggle source
# File lib/chef/target_io/train/dir.rb, line 59
def __run_command(cmd)
  __transport_connection.run_command(cmd)
end
__transport_connection() click to toggle source
# File lib/chef/target_io/train/dir.rb, line 63
def __transport_connection
  Chef.run_context&.transport_connection
end
delete(dir_name) click to toggle source
# File lib/chef/target_io/train/dir.rb, line 14
def delete(dir_name)
  ::TargetIO::FileUtils.rm_rf(dir_name)
end
directory?(dir_name) click to toggle source
# File lib/chef/target_io/train/dir.rb, line 18
def directory?(dir_name)
  ::TargetIO::File.directory? dir_name
end
entries(dirname) click to toggle source
# 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) click to toggle source
# 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
mkdir(dir_name, mode = nil) click to toggle source
# File lib/chef/target_io/train/dir.rb, line 50
def mkdir(dir_name, mode = nil)
  ::TargetIO::FileUtils.mkdir(dir_name)
  ::TargetIO::FileUtils.chmod(dir_name, mode) if mode
end