If ClamavService fails then raise an error
This commit is contained in:
parent
2a5250b62c
commit
f6714cd9a3
2 changed files with 25 additions and 9 deletions
|
@ -1,15 +1,21 @@
|
|||
class ClamavService
|
||||
def self.safe_file?(file_path)
|
||||
if Rails.env.development?
|
||||
Rails.logger.info("Rails.env = development => fake scan") # FIXME : remove me
|
||||
return true
|
||||
end
|
||||
|
||||
FileUtils.chmod(0666, file_path)
|
||||
|
||||
client = ClamAV::Client.new
|
||||
response = client.execute(ClamAV::Commands::ScanCommand.new(file_path))
|
||||
Rails.logger.info("ClamAV response for #{file_path} : #{response.first.class.name}") # FIXME : remove me
|
||||
response.first.class != ClamAV::VirusResponse
|
||||
response = client.execute(ClamAV::Commands::ScanCommand.new(file_path)).first
|
||||
if response.class == ClamAV::SuccessResponse
|
||||
true
|
||||
elsif response.class == ClamAV::VirusResponse
|
||||
false
|
||||
elsif response.class == ClamAV::ErrorResponse
|
||||
raise "ClamAV ErrorResponse : #{response.error_str}"
|
||||
else
|
||||
raise "ClamAV unkown response #{response.class.name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue