diff options
-rwxr-xr-x | sbofind | 11 | ||||
-rwxr-xr-x | t/27-race-sbofind.t | 6 |
2 files changed, 6 insertions, 11 deletions
@@ -13,7 +13,7 @@ use 5.16.0; use strict; use warnings FATAL => 'all'; -use SBO::Lib qw/ slackbuilds_or_fetch script_error open_read get_build_queue %config $slackbuilds_txt $repo_path show_version in indent /; +use SBO::Lib qw/ slackbuilds_or_fetch slurp script_error open_read get_build_queue %config $slackbuilds_txt $repo_path show_version in indent /; use File::Basename; use Getopt::Long qw(:config bundling); @@ -132,13 +132,8 @@ sub perform_search { sub get_file_contents { script_error 'get_file_contents requires an argument.' unless @_ == 1; my $file = shift; - -f $file or return "$file doesn't exist.\n"; - my ($fh, $exit) = open_read($file); - if ($exit) { - warn $fh; - return(); - } - my $contents = do {local $/; <$fh>}; + my $contents = slurp($file); + return "Unable to open $file.\n" unless defined $contents; return "\n" . indent 6, $contents; } diff --git a/t/27-race-sbofind.t b/t/27-race-sbofind.t index 5d0d1e4..c4384e8 100755 --- a/t/27-race-sbofind.t +++ b/t/27-race-sbofind.t @@ -71,7 +71,7 @@ my $tags_file = '/usr/sbo/repo/TAGS.txt'; my $out = capture_merged { $exit = exit_code { $ret = get_file_contents($file); }; }; is ($out, '', 'get_file_contents gave no output'); - is ($ret, "$file doesn't exist.\n", 'get_file_contents returned correctly'); + is ($ret, "Unable to open $file.\n", 'get_file_contents returned correctly'); is ($exit, undef, 'get_file_contents didn\'t exit'); system 'touch', $file; @@ -87,7 +87,7 @@ my $tags_file = '/usr/sbo/repo/TAGS.txt'; undef $ret; $out = capture_merged { $exit = exit_code { $ret = get_file_contents($file); }; }; - is ($out, "Unable to open $file.\n", 'get_file_contents correct output'); - is ($ret, undef, 'get_file_contents returned undef'); + is ($out, '', 'get_file_contents gave no output'); + is ($ret, "Unable to open $file.\n", 'get_file_contents returned correctly'); is ($exit, undef, 'get_file_contents still didn\'t exit'); } |