Skip to content

Commit

Permalink
Don't write LIBARCHIVE.creationtime attribute in tar.gz archive entries
Browse files Browse the repository at this point in the history
Fixes #2586
  • Loading branch information
HannesWell committed Nov 10, 2024
1 parent 2e98ec9 commit eef9e7f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ public final class ProductArchiverMojo extends AbstractProductMojo {
@Parameter
private boolean parallel;

/**
* Controls if for {@code .tar.gz} archives the creation-time is stored as
* {@code LIBARCHIVE.creationtime } attribute in each entry. Currently {@code GNU tar} does not
* support that attributes and emits warnings about the {@code unknown extended header keyword
* 'LIBARCHIVE.creationtime'} when extracting such archive.
*/
@Parameter(defaultValue = "false")
private boolean storeCreationTime;

@Component
private MavenProjectHelper helper;

Expand Down Expand Up @@ -230,6 +239,7 @@ private void materialize(Product product, TargetEnvironment env) throws MojoExec

private void createCommonsCompressTarGz(File productArchive, File sourceDir) throws IOException {
TarGzArchiver archiver = new TarGzArchiver();
archiver.setStoreCreationTimeAttribute(storeCreationTime);
archiver.setLog(getLog());
archiver.addDirectory(sourceDir);
archiver.setDestFile(productArchive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class TarGzArchiver {
private File destFile;
private List<File> sourceDirs = new ArrayList<>();
private Log log = new SystemStreamLog();
private boolean storeCreationTime;

public TarGzArchiver() {
}
Expand All @@ -64,6 +65,10 @@ public void setDestFile(File destFile) {
this.destFile = destFile;
}

public void setStoreCreationTimeAttribute(boolean storeCreationTime) {
this.storeCreationTime = storeCreationTime;
}

public void addDirectory(File directory) {
this.sourceDirs.add(directory);
}
Expand Down Expand Up @@ -129,6 +134,9 @@ private TarArchiveEntry createTarEntry(File tarRootDir, File source) throws IOEx
tarEntry.setMode(FilePermissionHelper.toOctalFileMode(attrs.permissions()));
}
tarEntry.setModTime(source.lastModified());
if (!storeCreationTime) { // GNU tar cannot handle 'LIBARCHIVE.creationtime' attributes and emits a lot of warnings on it
tarEntry.setCreationTime(null);
}
return tarEntry;
}

Expand Down

0 comments on commit eef9e7f

Please sign in to comment.