Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public KVMPhysicalDisk createDiskFromTemplateBacking(KVMPhysicalDisk template, S
*/
public static boolean isTemplateExtractable(String templatePath) {
String type = Script.runSimpleBashScript("file " + templatePath + " | awk -F' ' '{print $2}'");
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip") || type.equalsIgnoreCase("zip");
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip")
|| type.equalsIgnoreCase("zip") || type.equalsIgnoreCase("xz");
}

/**
Expand All @@ -193,6 +194,8 @@ public static String getExtractCommandForDownloadedFile(String downloadedTemplat
return "bunzip2 -c " + downloadedTemplateFile + " > " + templateUuid;
} else if (downloadedTemplateFile.endsWith(".gz")) {
return "gunzip -c " + downloadedTemplateFile + " > " + templateUuid;
} else if (downloadedTemplateFile.endsWith(".xz")) {
return "xz -d -c " + downloadedTemplateFile + " > " + templateUuid;
} else {
throw new CloudRuntimeException("Unable to extract template " + downloadedTemplateFile);
}
Comment on lines 195 to 201
Copy link
Preview

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZIP archives are flagged as extractable in isTemplateExtractable(), but there is no handling for ".zip" here, which will cause a runtime exception. Add a ZIP branch, e.g., return "unzip -p " + downloadedTemplateFile + " > " + templateUuid;

Copilot uses AI. Check for mistakes.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,8 @@ public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool,
boolean isTemplateExtractable(String templatePath) {
ScriptResult result = runScript("file", 5000L, templatePath, "| awk -F' ' '{print $2}'");
String type = result.getResult();
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip") || type.equalsIgnoreCase("zip");
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip")
|| type.equalsIgnoreCase("zip") || type.equalsIgnoreCase("xz");
}

String getExtractCommandForDownloadedFile(String downloadedTemplateFile, String templateFile) {
Expand All @@ -436,6 +437,8 @@ String getExtractCommandForDownloadedFile(String downloadedTemplateFile, String
return "bunzip2 -c " + downloadedTemplateFile + " > " + templateFile;
} else if (downloadedTemplateFile.endsWith(".gz")) {
return "gunzip -c " + downloadedTemplateFile + " > " + templateFile;
} else if (downloadedTemplateFile.endsWith(".xz")) {
return "xz -d -c " + downloadedTemplateFile + " > " + templateFile;
} else {
throw new CloudRuntimeException("Unable to extract template " + downloadedTemplateFile);
}
Comment on lines 438 to 444
Copy link
Preview

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZIP is allowed by isTemplateExtractable(), but ".zip" is not handled here, leading to an exception for ZIP templates. Add a ZIP case similar to other formats, e.g., return "unzip -p " + downloadedTemplateFile + " > " + templateFile;

Copilot uses AI. Check for mistakes.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,8 @@ public KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFileP

private boolean isTemplateExtractable(String templatePath) {
String type = Script.runSimpleBashScript("file " + templatePath + " | awk -F' ' '{print $2}'");
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip") || type.equalsIgnoreCase("zip");
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip")
|| type.equalsIgnoreCase("zip") || type.equalsIgnoreCase("xz");
}

private String getExtractCommandForDownloadedFile(String downloadedTemplateFile, String templateFile) {
Expand All @@ -623,6 +624,8 @@ private String getExtractCommandForDownloadedFile(String downloadedTemplateFile,
return "bunzip2 -c " + downloadedTemplateFile + " > " + templateFile;
} else if (downloadedTemplateFile.endsWith(".gz")) {
return "gunzip -c " + downloadedTemplateFile + " > " + templateFile;
} else if (downloadedTemplateFile.endsWith(".xz")) {
return "xz -d -c " + downloadedTemplateFile + " > " + templateFile;
} else {
throw new CloudRuntimeException("Unable to extract template " + downloadedTemplateFile);
}
Comment on lines 625 to 631
Copy link
Preview

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZIP is considered extractable in isTemplateExtractable(), but there is no extraction branch for ".zip" here. Add ZIP extraction support to avoid throwing for valid ZIP templates, e.g., return "unzip -p " + downloadedTemplateFile + " > " + templateFile;

Copilot uses AI. Check for mistakes.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,8 @@ private String extractTemplate(String templateFilePath, File sourceFile, String

private boolean isTemplateExtractable(String templatePath) {
String type = Script.runSimpleBashScript("file " + templatePath + " | awk -F' ' '{print $2}'");
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip") || type.equalsIgnoreCase("zip");
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip")
|| type.equalsIgnoreCase("zip") || type.equalsIgnoreCase("xz");
}

private String getExtractCommandForDownloadedFile(String downloadedTemplateFile, String templateFile) {
Expand All @@ -549,6 +550,8 @@ private String getExtractCommandForDownloadedFile(String downloadedTemplateFile,
return "bunzip2 -c " + downloadedTemplateFile + " > " + templateFile;
} else if (downloadedTemplateFile.endsWith(".gz")) {
return "gunzip -c " + downloadedTemplateFile + " > " + templateFile;
} else if (downloadedTemplateFile.endsWith(".xz")) {
return "xz -d -c " + downloadedTemplateFile + " > " + templateFile;
} else {
throw new CloudRuntimeException("Unable to extract template " + downloadedTemplateFile);
}
Comment on lines 551 to 557
Copy link
Preview

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isTemplateExtractable() treats ZIP as extractable, but getExtractCommandForDownloadedFile() has no branch for ".zip", which will cause ZIP files to hit the exception path. Add ZIP handling consistent with other scripts, for example: return "unzip -p " + downloadedTemplateFile + " > " + templateFile;

Copilot uses AI. Check for mistakes.

Expand Down
2 changes: 2 additions & 0 deletions scripts/installer/createtmplt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ uncompress() {
;;
[zZ][iI][pP]) unzip -p $1 | cat > $tmpfile
;;
XZ) xz -d -c $1 > $tmpfile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a case sensitive check. Use [xX][zZ] to match xz, XZ, xZ & Xz.

;;
*) printf "$1"
return 0
;;
Expand Down
2 changes: 2 additions & 0 deletions scripts/installer/createvolume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ uncompress() {
;;
ZIP) unzip -p $1 | cat > $tmpfile
;;
XZ) xz -d -c $1 > $tmpfile
;;
*) printf "$1"
return 0
;;
Expand Down
2 changes: 2 additions & 0 deletions scripts/storage/qcow2/createtmplt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ uncompress() {
;;
[zZ][iI][pP]) unzip -p $1 | cat > $tmpfile
;;
XZ) xz -d -c $1 > $tmpfile
;;
*) printf "$1"
return 0
;;
Expand Down
2 changes: 2 additions & 0 deletions scripts/storage/qcow2/createvolume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ uncompress() {
;;
ZIP) unzip -p $1 | cat > $tmpfile
;;
XZ) xz -d -c $1 > $tmpfile
;;
*) printf "$1"
return 0
;;
Expand Down
4 changes: 4 additions & 0 deletions scripts/storage/secondary/createtmplt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ is_compressed() {
;;
[zZ][iI][pP]) ctype="zip"
;;
XZ) ctype="xz"
;;
*) echo "File $1 does not appear to be compressed" >&2
return 1
;;
Expand All @@ -82,6 +84,8 @@ uncompress() {
;;
[zZ][iI][pP]) unzip -q -p $1 | cat > $tmpfile
;;
XZ) xz -d -c $1 > $tmpfile
;;
*) printf "$1"
return 0
;;
Expand Down
4 changes: 4 additions & 0 deletions scripts/storage/secondary/createvolume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ is_compressed() {
;;
ZIP) ctype="zip"
;;
XZ) ctype="xz"
;;
*) echo "File $1 does not appear to be compressed" >&2
return 1
;;
Expand All @@ -104,6 +106,8 @@ uncompress() {
;;
ZIP) unzip -q -p $1 | cat > $tmpfile
;;
XZ) xz -d -c $1 > $tmpfile
;;
*) printf "$1"
return 0
;;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ is_compressed() {
;;
ZIP) ctype="zip"
;;
XZ) ctype="xz"
;;
*) echo "File $1 does not appear to be compressed" >&2
return 1
;;
Expand All @@ -94,6 +96,8 @@ uncompress() {
;;
ZIP) unzip -q -p $1 | cat > $tmpfile
;;
XZ) xz -d -c $1 > $tmpfile
;;
*) printf "$1"
return 0
;;
Expand Down
2 changes: 1 addition & 1 deletion utils/src/main/java/com/cloud/utils/UriUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public static List<String> getMetalinkUrls(String metalinkUrl) {
return urls;
}

public static final Set<String> COMPRESSION_FORMATS = ImmutableSet.of("zip", "bz2", "gz");
public static final Set<String> COMPRESSION_FORMATS = ImmutableSet.of("zip", "bz2", "gz", "xz");

public static final Set<String> buildExtensionSet(boolean metalink, String... baseExtensions) {
final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public interface ThrowingBlock<E extends Exception> {
}

private static final Set<String> COMMPRESSION_FORMATS = ImmutableSet.of("",".zip", ".bz2", ".gz");
private static final Set<String> ILLEGAL_COMMPRESSION_FORMATS = ImmutableSet.of(".7z", ".xz");
private static final Set<String> ILLEGAL_COMMPRESSION_FORMATS = ImmutableSet.of(".7z");
private final static Set<String> FORMATS = ImmutableSet.of(
"vhd",
"vhdx",
Expand Down
1 change: 1 addition & 0 deletions utils/src/test/java/com/cloud/utils/UriUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public void testIsUrlForCompressedFile() {
Assert.assertTrue(UriUtils.isUrlForCompressedFile("https://abc.com/xyz.bz2"));
Assert.assertTrue(UriUtils.isUrlForCompressedFile("http://abc.com/xyz.zip"));
Assert.assertTrue(UriUtils.isUrlForCompressedFile("https://abc.com/xyz.gz"));
Assert.assertTrue(UriUtils.isUrlForCompressedFile("http://abc.com/xyz.xz"));
Assert.assertFalse(UriUtils.isUrlForCompressedFile("http://abc.com/xyz.qcow2"));
}

Expand Down
Loading