Skip to content

Commit

Permalink
Remove leading ./ from zip entries (#682)
Browse files Browse the repository at this point in the history
The leading `.` on zip entry names is ignored by (at least) the Mac OS
`unzip` utility which means that every file appears to have an absolute
path, so unpacking a diagnostics bundle emits a warning for every entry:

    warning:  stripped absolute path spec from ...

There's no need to prefix every entry name with `./`, so this commit
removes the prefix to avoid these warnings.
  • Loading branch information
DaveCTurner committed Jun 24, 2024
1 parent b073813 commit 420b260
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/co/elastic/support/util/ArchiveUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static File createZipArchive(String dir, String archiveFileName) throws D
try (
FileOutputStream fout = new FileOutputStream(filename);
ZipArchiveOutputStream taos = new ZipArchiveOutputStream(fout)) {
archiveResultsZip(archiveFileName, taos, srcDir, ".", true);
archiveResultsZip(archiveFileName, taos, srcDir, null, true);
logger.info(Constants.CONSOLE, "Archive: " + filename + " was created");
return file;
} catch (IOException ioe) {
Expand All @@ -44,7 +44,7 @@ private static void archiveResultsZip(
File file,
String path,
boolean append) {
String relPath = path + "/" + file.getName();
String relPath = (path == null ? "" : path + "/") + file.getName();

try {
if (append) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ public HashMap<String, ZipEntry> zipFileContents(File result) throws IOException

while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
assertFalse(entry.getName().startsWith("./"), entry.getName());

if (!entry.isDirectory()) {
// Add file path without leading directory
contents.put(entry.getName().replaceFirst("^(\\.\\/.+\\/)(.+)", "$2"), entry);
contents.put(entry.getName().replaceFirst("^(.+\\/)(.+)", "$2"), entry);
}
}

Expand Down

0 comments on commit 420b260

Please sign in to comment.