Include empty layers when listing and extracting
Fixes gh-21301
This commit is contained in:
@@ -20,16 +20,16 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -41,18 +41,19 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
class IndexedLayers implements Layers {
|
||||
|
||||
private MultiValueMap<String, String> layers = new LinkedMultiValueMap<>();
|
||||
private final Map<String, List<String>> layers = new LinkedHashMap<>();
|
||||
|
||||
IndexedLayers(String indexFile) {
|
||||
String[] lines = Arrays.stream(indexFile.split("\n")).map((line) -> line.replace("\r", ""))
|
||||
.filter(StringUtils::hasText).toArray(String[]::new);
|
||||
String layer = null;
|
||||
List<String> contents = null;
|
||||
for (String line : lines) {
|
||||
if (line.startsWith("- ")) {
|
||||
layer = line.substring(3, line.length() - 2);
|
||||
contents = new ArrayList<>();
|
||||
this.layers.put(line.substring(3, line.length() - 2), contents);
|
||||
}
|
||||
else if (line.startsWith(" - ")) {
|
||||
this.layers.add(layer, line.substring(5, line.length() - 1));
|
||||
contents.add(line.substring(5, line.length() - 1));
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Layer index file is malformed");
|
||||
|
||||
Reference in New Issue
Block a user