From f3b6d57d87efeec0c87c9212876b873acc4f9079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 24 Nov 2026 07:27:11 -0300 Subject: [PATCH] refactor(netboot): use owned temporary files for publication Use File::Temp for same-directory checksum and marker staging. Keep the final mode, rename publication and returned error policy. Leave unrelated files at old PID-based staging names untouched. --- xCAT-server/lib/perl/xCAT/SvrUtils.pm | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/SvrUtils.pm b/xCAT-server/lib/perl/xCAT/SvrUtils.pm index cd8aedb08e..1152887b9d 100644 --- a/xCAT-server/lib/perl/xCAT/SvrUtils.pm +++ b/xCAT-server/lib/perl/xCAT/SvrUtils.pm @@ -2933,14 +2933,13 @@ sub _read_published_file { # A rename publishes the file, so no reader sees it partial. sub _write_published_file { my ($path, $content) = @_; - my $temp = "$path.$$"; - my $written; - if (open(my $file, '>', $temp)) { - $written = print($file $content) && close($file); - } + my $file = eval { File::Temp->new( + TEMPLATE => '.' . basename($path) . '.XXXXXXXX', DIR => dirname($path)) }; + return "Cannot write $path: $!" unless $file; + my $temp = $file->filename; + my $written = print($file $content) && close($file); unless ($written && chmod(0644, $temp) && rename($temp, $path)) { my $error = $!; - unlink($temp); return "Cannot write $path: $error"; } return;