Update extract to write files to their original, unlayered location
This commit is contained in:
@@ -83,7 +83,7 @@ class ExtractCommand extends Command {
|
||||
}
|
||||
|
||||
private void write(ZipInputStream zip, ZipEntry entry, File destination) throws IOException {
|
||||
String path = StringUtils.cleanPath(entry.getName());
|
||||
String path = StringUtils.cleanPath(this.layers.getOriginalLocation(entry));
|
||||
File file = new File(destination, path);
|
||||
if (file.getAbsolutePath().startsWith(destination.getAbsolutePath())) {
|
||||
mkParentDirs(file);
|
||||
|
||||
@@ -44,7 +44,7 @@ class IndexedLayers implements Layers {
|
||||
|
||||
private static final String SPRING_BOOT_APPLICATION_LAYER = "springbootapplication";
|
||||
|
||||
private static final Pattern LAYER_PATTERN = Pattern.compile("^BOOT-INF\\/layers\\/([a-zA-Z0-9-]+)\\/.*$");
|
||||
private static final Pattern LAYER_PATTERN = Pattern.compile("^BOOT-INF\\/layers\\/([a-zA-Z0-9-]+)\\/(.*$)");
|
||||
|
||||
private List<String> layers;
|
||||
|
||||
@@ -74,6 +74,18 @@ class IndexedLayers implements Layers {
|
||||
}
|
||||
return this.layers.contains(APPLICATION_LAYER) ? APPLICATION_LAYER : SPRING_BOOT_APPLICATION_LAYER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOriginalLocation(ZipEntry entry) {
|
||||
String name = entry.getName();
|
||||
Matcher matcher = LAYER_PATTERN.matcher(name);
|
||||
if (matcher.matches()) {
|
||||
String layer = matcher.group(1);
|
||||
Assert.state(this.layers.contains(layer), () -> "Unexpected layer '" + layer + "'");
|
||||
return "BOOT-INF/" + matcher.group(2);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an {@link IndexedLayers} instance of possible.
|
||||
|
||||
@@ -41,6 +41,13 @@ interface Layers extends Iterable<String> {
|
||||
* @return the layer that the entry is in
|
||||
*/
|
||||
String getLayer(ZipEntry entry);
|
||||
|
||||
/**
|
||||
* Returns the original, unlayered location of the given entry.
|
||||
* @param entry the entry for which the original location is required
|
||||
* @return the original location
|
||||
*/
|
||||
String getOriginalLocation(ZipEntry entry);
|
||||
|
||||
/**
|
||||
* Return a {@link Layers} instance for the currently running application.
|
||||
|
||||
Reference in New Issue
Block a user