Sha256: 6fa7203dcab5062f3ea1332decd413b697cea47a6063a95378bce2d9b3f49667

Contents?: true

Size: 1011 Bytes

Versions: 3

Compression:

Stored size: 1011 Bytes

Contents

module WatchmonkeyCli
  module Checkers
    class FileExists < Checker
      self.checker_name = "unix_file_exists"

      def enqueue host, file, opts = {}
        opts = { message: "File #{file} does not exist!" }.merge(opts)
        host = app.fetch_connection(:loopback, :local) if !host || host == :local
        host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
        app.enqueue(self, host, file, opts)
      end

      def check! result, host, file, opts = {}
        descriptor = "[#{self.class.checker_name} | #{host} | #{file} | #{opts}]\n\t"
        if host.is_a?(WatchmonkeyCli::LoopbackConnection)
          result.error! "#{descriptor}#{opts[:message]} (ENOENT)" if !File.exist?(file)
        else
          result.command = "test -f #{Shellwords.escape(file)} && echo exists"
          result.result = host.exec(result.command)
          result.error! "#{opts[:message]} (#{result.result.presence || "ENOENT"})" if result.result != "exists"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
watchmonkey_cli-1.6 lib/watchmonkey_cli/checkers/unix_file_exists.rb
watchmonkey_cli-1.5 lib/watchmonkey_cli/checkers/unix_file_exists.rb
watchmonkey_cli-1.4 lib/watchmonkey_cli/checkers/unix_file_exists.rb