diff options
author | Guillem Jover <guillem@debian.org> | 2018-12-24 03:05:05 +0100 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2019-01-15 03:42:39 +0100 |
commit | 39eb793a685273f520b25179bf118f8845ece0f6 (patch) | |
tree | 6c5ad397c42ee8d9ef98b73faaf5afd5ebc69ae4 /scripts/Dpkg/File.pm | |
parent | e326eda15c84d0456aa2e1c22c996e89ef6c40f2 (diff) | |
download | dpkg-39eb793a685273f520b25179bf118f8845ece0f6.tar.gz |
Dpkg::File: Make file_slurp() also accept pathnames in addition to filehandles
This makes several call sites more clear, as we move the logic inside
the function.
Diffstat (limited to 'scripts/Dpkg/File.pm')
-rw-r--r-- | scripts/Dpkg/File.pm | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/scripts/Dpkg/File.pm b/scripts/Dpkg/File.pm index 884923852..6ba49a6e6 100644 --- a/scripts/Dpkg/File.pm +++ b/scripts/Dpkg/File.pm @@ -25,12 +25,26 @@ our @EXPORT = qw( ); use Exporter qw(import); +use Scalar::Util qw(openhandle); + +use Dpkg::ErrorHandling; +use Dpkg::Gettext; sub file_slurp { - my $fh = shift; + my $file = shift; + my $fh; + my $doclose = 0; + if (openhandle($file)) { + $fh = $file; + } else { + open $fh, '<', $file or syserr(g_('cannot read %s'), $fh); + $doclose = 1; + } local $/; my $data = <$fh>; + close $fh if $doclose; + return $data; } |