2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-10-22 23:58:13 +00:00

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.
This commit is contained in:
Vinícius Ferrão
2026-10-14 00:46:24 -03:00
parent be9c063981
commit 085ee7991d
+10 -3
View File
@@ -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;
}