From 085ee7991da737b5ecaec72097818576faeadd43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Wed, 14 Oct 2026 00:46:24 -0300 Subject: [PATCH] fix(imgport): copy an extra file into its destination directory imgexport records an extra file with its destination directory. When that directory did not exist, imgimport copied the file to the path of the directory, so the file took the name of the directory. When a file was at that path, imgimport replaced it. imgimport now creates the destination directory and its missing parents, as it does for an extra directory. A file at that path fails the import and stays as it was. The copy runs without a shell, so a file name with glob characters cannot match another file. A failed backup of the previous file now fails the import. --- xCAT-server/lib/xcat/plugins/imgport.pm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/imgport.pm b/xCAT-server/lib/xcat/plugins/imgport.pm index cf8b9cdd8..d42e0c13f 100644 --- a/xCAT-server/lib/xcat/plugins/imgport.pm +++ b/xCAT-server/lib/xcat/plugins/imgport.pm @@ -2218,12 +2218,19 @@ sub moveExtra { #print "This is a file\n"; # this extra file is a file and we can just copy to the destination. $callback->({ data => ["$dest/$f"] }); + mkpath($dest, { error => \my $errors }) unless -d $dest; + unless (-d $dest) { + $callback->({ error => ["Failed to create $dest"], errorcode => 1 }); + return 0; + } if (-r "$dest/$f") { $callback->({ data => [" Moving old $dest/$f to $dest/$f.ORIG."] }); - move("$dest/$f", "$dest/$f.ORIG"); + unless (move("$dest/$f", "$dest/$f.ORIG")) { + $callback->({ error => ["Failed to move $dest/$f to $dest/$f.ORIG"], errorcode => 1 }); + return 0; + } } - `cp $imgdir/extra/$f $dest`; - if ($?) { + if (system('cp', "$imgdir/extra/$f", $dest)) { $callback->({ error => ["Failed to copy $imgdir/extra/$f to $dest"], errorcode => 1 }); return 0; }