-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Support xz format for template registration #11786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. Positive FeedbackNegative Feedback |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. Positive FeedbackNegative Feedback |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. Positive FeedbackNegative Feedback |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,8 @@ uncompress() { | |
;; | ||
[zZ][iI][pP]) unzip -p $1 | cat > $tmpfile | ||
;; | ||
XZ) xz -d -c $1 > $tmpfile | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a case sensitive check. Use |
||
;; | ||
*) printf "$1" | ||
return 0 | ||
;; | ||
|
There was a problem hiding this comment.
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.