Sha256: dd850a8c11f97eee8fa386efc0f45003cdb5f95eb177e5b689b94bebbd42b99e
Contents?: true
Size: 1.02 KB
Versions: 3
Compression:
Stored size: 1.02 KB
Contents
# encoding: utf-8 module TestServer class VirusDetector private attr_reader :command, :timeout public def initialize(command: which('clamdscan')) @command = command @timeout = 60 end def use(file) file.virus_id = scan(file) end private include FeduxOrg::Stdlib::Command::Which include TestServer::RunCommand def scan(file) return "Scan commands \"clamdscan\" and \"clamscan\" not found. File \"#{file.name}\" could not be scanned." if command.blank? result = run_command("#{command} #{file.path}", timeout: timeout) return "Timeout \"#{timeout}\" reached before finishing scan." if result.status == 99 return "Scan failed due to error: #{extract_error(result.stdout)}" if result.stdout.first['ERROR'] extract_virus_id(result.stdout) end def extract_error(data) data.first.chomp.split(/:/).last end def extract_virus_id(data) data.first.scan(/^[^:]+:\s([[:alnum:]-]+)\s[[:alpha:]]+/).flatten.first end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
test_server-0.5.2 | lib/test_server/virus_detector.rb |
test_server-0.5.1 | lib/test_server/virus_detector.rb |
test_server-0.5.0 | lib/test_server/virus_detector.rb |