2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-12-04 08:07:04 +00:00

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.
This commit is contained in:
Vinícius Ferrão
2026-11-24 07:27:11 -03:00
parent b1cdbf15fd
commit f3b6d57d87
+5 -6
View File
@@ -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;