From ef9b299319aabefee2dd281866f53a2f921c7b65 Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Tue, 15 Sep 2015 14:52:27 +0200 Subject: [PATCH] api: specinfra reports nil on non-existent files Check the responses and make sure we dont blindly return eg: size=0 or group="" or user="" for files that dont exist. Signed-off-by: Dominik Richter --- lib/vulcano/backend/specinfra.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/vulcano/backend/specinfra.rb b/lib/vulcano/backend/specinfra.rb index 76a3129ec..007d59b79 100644 --- a/lib/vulcano/backend/specinfra.rb +++ b/lib/vulcano/backend/specinfra.rb @@ -223,15 +223,18 @@ module Vulcano::Backends end def mode - Specinfra::Runner.get_file_mode(@path).stdout.to_i(8) + m = Specinfra::Runner.get_file_mode(@path).stdout.strip + m.empty? ? nil : m.to_i(8) end def owner - Specinfra::Runner.get_file_owner_user(@path).stdout.strip + o = Specinfra::Runner.get_file_owner_user(@path).stdout.strip + o.empty? ? nil : o end def group - Specinfra::Runner.get_file_owner_group(@path).stdout.strip + g = Specinfra::Runner.get_file_owner_group(@path).stdout.strip + g.empty? ? nil : g end def link_path @@ -242,7 +245,7 @@ module Vulcano::Backends def content s = Specinfra::Runner.get_file_content(@path).stdout.strip - if s.empty? && (size > 0 or block_device?) + if s.empty? && (size.nil? or size > 0 or block_device?) nil else s @@ -261,12 +264,13 @@ module Vulcano::Backends def mtime mt = Specinfra::Runner.get_file_mtime(@path).stdout.strip - return -1 if mt.empty? + return nil if mt.empty? mt.to_i end def size - Specinfra::Runner.get_file_size(@path).stdout.strip.to_i + s = Specinfra::Runner.get_file_size(@path).stdout.strip + s.empty? ? nil : s.to_i end def selinux_label