5
0
mirror of git://git.proxmox.com/git/pve-common.git synced 2025-01-09 05:17:35 +03:00

sysfs tools: avoid using POSIX for just EEXIST error code

We can just save both $! and %! and use the latter to check for
specific errors. This is not really pretty but perl does the same
internally, so...

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2024-11-11 13:52:36 +01:00
parent 3b6ce501ad
commit 15075a54e9

View File

@ -4,7 +4,6 @@ use strict;
use warnings;
use IO::File;
use POSIX qw(EEXIST);
use PVE::Tools qw(file_read_firstline dir_glob_foreach);
@ -221,13 +220,13 @@ sub file_write {
return undef if !$fh;
my $res = syswrite($fh, $buf);
my $syserr = $!; # only relevant if $res is undefined
my ($syserr, %syserr) = ($!, %!); # only relevant if $res is undefined
$fh->close();
if (defined($res)) {
return 1;
} elsif ($syserr) {
return 1 if $allow_existing && $syserr == EEXIST;
return 1 if $allow_existing && $syserr{EEXIST};
warn "error writing '$buf' to '$filename': $syserr\n";
}