Skip to content

Commit 9a10310

Browse files
committed
utils: Fix isCorrectExtension regression
This fixes a regression to fix and allow uploading of ISOs and templates from the UI. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent d3b292a commit 9a10310

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

utils/src/main/java/org/apache/cloudstack/utils/imagestore/ImageStoreUtil.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
*/
1919
package org.apache.cloudstack.utils.imagestore;
2020

21-
import com.cloud.utils.UriUtils;
22-
import com.cloud.utils.script.Script;
2321
import org.apache.commons.lang.StringUtils;
2422
import org.apache.log4j.Logger;
2523

24+
import com.cloud.utils.UriUtils;
25+
import com.cloud.utils.script.Script;
26+
2627
public class ImageStoreUtil {
2728
public static final Logger s_logger = Logger.getLogger(ImageStoreUtil.class.getName());
2829

@@ -58,7 +59,7 @@ public static String checkTemplateFormat(String path, String uripath) {
5859
return "";
5960
}
6061
// raw
61-
if ((output.contains("x86 boot") || output.contains("data")) && (isCorrectExtension(uripath, "raw"))) {
62+
if ((output.contains("x86 boot") || output.contains("data")) && (isCorrectExtension(uripath, "raw") || isCorrectExtension(uripath, "img"))) {
6263
s_logger.debug("File at path " + path + " looks like a raw image :" + output);
6364
return "";
6465
}
@@ -93,10 +94,11 @@ public static String checkTemplateFormat(String path, String uripath) {
9394

9495
public static boolean isCorrectExtension(String path, String format) {
9596
final String lowerCasePath = path.toLowerCase();
96-
return UriUtils.getSupportedExtensions(format)
97-
.stream()
98-
.filter(ext -> !ext.equals(".metalink"))
99-
.anyMatch(lowerCasePath::endsWith);
97+
return lowerCasePath.endsWith(format) ||
98+
UriUtils.getSupportedExtensions(format)
99+
.stream()
100+
.filter(ext -> !ext.equals(".metalink"))
101+
.anyMatch(lowerCasePath::endsWith);
100102
}
101103

102104
public static boolean isCompressedExtension(String path) {

utils/src/test/java/com/cloud/utils/UriUtilsParametrizedTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.LinkedList;
2424
import java.util.Set;
2525

26+
import org.apache.cloudstack.utils.imagestore.ImageStoreUtil;
2627
import org.hamcrest.Matchers;
2728
import org.junit.Assert;
2829
import org.junit.Test;
@@ -32,8 +33,6 @@
3233

3334
import com.google.common.collect.ImmutableSet;
3435

35-
import org.apache.cloudstack.utils.imagestore.ImageStoreUtil;
36-
3736
@RunWith(Parameterized.class)
3837
public class UriUtilsParametrizedTest {
3938
@FunctionalInterface
@@ -62,10 +61,9 @@ public interface ThrowingBlock<E extends Exception> {
6261

6362
private final static Set<String> ILLEGAL_EXTENSIONS = ImmutableSet.of(
6463
"rar",
65-
"supernova",
66-
"straw",
67-
"miso",
68-
"tartar"
64+
"supernoba",
65+
"straws",
66+
"tarar"
6967
);
7068

7169
private String format;

0 commit comments

Comments
 (0)