Skip to content
Open
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);
}
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);
}
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);
}
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);
}
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
;;
*) 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