Skip to content

Commit 1e2517e

Browse files
authored
fix(backend): Starter zip file entries being created with leadin (dotCMS#32249) (dotCMS#32250)
### Proposed Changes * Minimal fix for path issue causing leading slash in starter zip assets entries ### Checklist - [ ] Tests - [ ] Translations - [ ] Security Implications Contemplated (add notes if applicable) ### Testing * Download a starter from the Maintenance page * Use "unzip -l {starter filename}" to list the file paths, ensure that non start with a / ### Additional Info This PR resolves dotCMS#32249 (Starter zip file entries being created with leadin). ### Screenshots Original | Updated :-------------------------:|:-------------------------: ** original screenshot ** | ** updated screenshot **
1 parent d801353 commit 1e2517e

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

dotCMS/src/main/java/com/dotmarketing/util/starter/ExportStarterUtil.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import java.nio.charset.Charset;
6868
import java.nio.charset.StandardCharsets;
6969
import java.nio.file.Files;
70+
import java.nio.file.Path;
7071
import java.nio.file.Paths;
7172
import java.sql.Connection;
7273
import java.sql.PreparedStatement;
@@ -118,7 +119,7 @@ public class ExportStarterUtil {
118119
private static final Lazy<Integer> QUEUE_CAPACITY =
119120
Lazy.of(() -> Config.getIntProperty(STARTER_GENERATION_QUEUE_CAPACITY_PROP, 1000));
120121
private static final Lazy<String> ZIP_FILE_ASSETS_FOLDER =
121-
Lazy.of(() -> Config.getStringProperty(STARTER_GENERATION_ASSETS_FOLDER_PROP, "/assets/"));
122+
Lazy.of(() -> Config.getStringProperty(STARTER_GENERATION_ASSETS_FOLDER_PROP, "assets"));
122123

123124
private static final String JSON_FILE_EXT = ".json";
124125

@@ -484,10 +485,28 @@ private void addFolderToZip(final ZipOutputStream zip, final FileFilter fileFilt
484485
return;
485486
}
486487
FileUtil.listFilesRecursively(source, fileFilter).stream().filter(File::isFile).forEach(file -> {
487-
final String filePath = file.getPath().replace(ConfigUtils.getAssetPath(), ZIP_FILE_ASSETS_FOLDER.get());
488-
Logger.debug(this, String.format("-> File path: %s", filePath));
489-
final FileEntry entry = new FileEntry(filePath, file);
490-
this.addFileToZip(entry, zip);
488+
try {
489+
Path sourcePath = Paths.get(ConfigUtils.getAssetPath()).normalize();
490+
Path currentFilePath = file.toPath().normalize();
491+
Path targetFolderPath = Paths.get(ZIP_FILE_ASSETS_FOLDER.get()).normalize();
492+
493+
// Get relative path from source to current file
494+
Path relativePath = sourcePath.relativize(currentFilePath);
495+
496+
// Construct the final path by combining target folder with relative path
497+
Path finalPath = targetFolderPath.resolve(relativePath);
498+
499+
// Convert to string with forward slashes for ZIP compatibility
500+
String filePath = finalPath.toString().replace('\\', '/');
501+
502+
Logger.debug(this, String.format("-> File path: %s", filePath));
503+
final FileEntry entry = new FileEntry(filePath, file);
504+
this.addFileToZip(entry, zip);
505+
506+
} catch (Exception e) {
507+
Logger.error(this, String.format("Error processing file path for %s: %s",
508+
file.getPath(), e.getMessage()));
509+
}
491510
});
492511

493512

0 commit comments

Comments
 (0)