From 1ac0a30a0a939609aaffe7a59837048f9e8a8c05 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Tue, 13 Jun 2023 07:12:06 +0200 Subject: [PATCH] read firstline: only map ENOENT to undef, raise error otherwise Errors like permission denied or I/O ones should bubble up, otherwise it might hide serious issues and seemingly continue to work, with a wrong state or the like. One could argue that the case for not existent should return undef, while an empty file should return an empty string, but for that we might want to check all use-sites first. Signed-off-by: Thomas Lamprecht --- src/PVE/Tools.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index 174ded8..2d728f8 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -291,7 +291,10 @@ sub file_read_firstline { my ($filename) = @_; my $fh = IO::File->new ($filename, "r"); - return undef if !$fh; + if (!$fh) { + return undef if $! == POSIX::ENOENT; + die "file '$filename' exists but open for reading failed - $!\n"; + } my $res = <$fh>; chomp $res if $res; $fh->close;