From 15075a54e9a2b6fde39bc74b07dabda48c11c4a3 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 11 Nov 2024 13:52:36 +0100 Subject: [PATCH] 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 --- src/PVE/SysFSTools.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/PVE/SysFSTools.pm b/src/PVE/SysFSTools.pm index 74f3242..cf9854b 100644 --- a/src/PVE/SysFSTools.pm +++ b/src/PVE/SysFSTools.pm @@ -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"; }