]> git.proxmox.com Git - pve-common.git/commitdiff
read firstline: only map ENOENT to undef, raise error otherwise
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 13 Jun 2023 05:12:06 +0000 (07:12 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 13 Jun 2023 05:16:40 +0000 (07:16 +0200)
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 <t.lamprecht@proxmox.com>
src/PVE/Tools.pm

index 174ded8ca945db631029b8087d7e2cebd8728d6a..2d728f8fc73739942020290d2db3f475d7c9c148 100644 (file)
@@ -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;