From e3b02db232f773cf85cacbd9a0a49de23401c5af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Thu, 4 May 2023 19:23:31 +0200 Subject: [PATCH] add umask support and use 022 in RB mode --- pom.xml | 2 +- .../plexus/archiver/AbstractArchiver.java | 24 ++++++++++++++++++- .../codehaus/plexus/archiver/Archiver.java | 10 ++++++++ .../archiver/diags/DelgatingArchiver.java | 12 ++++++++++ .../plexus/archiver/diags/NoOpArchiver.java | 12 ++++++++++ .../archiver/diags/TrackingArchiver.java | 12 ++++++++++ 6 files changed, 70 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 367dc4ff5..4a9dbed71 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ plexus-archiver - 4.6.4-SNAPSHOT + 4.7.0-SNAPSHOT Plexus Archiver Component diff --git a/src/main/java/org/codehaus/plexus/archiver/AbstractArchiver.java b/src/main/java/org/codehaus/plexus/archiver/AbstractArchiver.java index 207717fd9..8b4bdfa5f 100755 --- a/src/main/java/org/codehaus/plexus/archiver/AbstractArchiver.java +++ b/src/main/java/org/codehaus/plexus/archiver/AbstractArchiver.java @@ -89,6 +89,8 @@ protected Logger getLogger() private int defaultDirectoryMode = -1; // Optionally used if a value is needed + private int umask = -1; + private boolean forced = true; private List finalizers; @@ -440,7 +442,7 @@ private ArchiveEntry updateArchiveEntryAttributes( ArchiveEntry entry ) } protected ArchiveEntry asArchiveEntry( @Nonnull final PlexusIoResource resource, final String destFileName, - final int permissions, PlexusIoResourceCollection collection ) + int permissions, PlexusIoResourceCollection collection ) throws ArchiverException { if ( !resource.isExisting() ) @@ -448,6 +450,11 @@ protected ArchiveEntry asArchiveEntry( @Nonnull final PlexusIoResource resource, throw new ArchiverException( resource.getName() + " not found." ); } + if ( umask > 0 ) + { + permissions &= ~umask; + } + ArchiveEntry entry; if ( resource.isFile() ) { @@ -1264,6 +1271,18 @@ public String getOverrideGroupName() return overrideGroupName; } + @Override + public void setUmask( int umask ) + { + this.umask = umask; + } + + @Override + public int getUmask() + { + return umask; + } + /** * @deprecated Use {@link #configureReproducibleBuild(FileTime)} instead. */ @@ -1288,6 +1307,9 @@ public void configureReproducibleBuild( FileTime lastModifiedTime ) setOverrideUserName( "root" ); // is it possible to avoid this, like "tar --numeric-owner"? setOverrideGid( 0 ); setOverrideGroupName( "root" ); + + // 4. set umask to 022 to avoid environment umask value particularly on group write + setUmask( 0_022 ); } /** diff --git a/src/main/java/org/codehaus/plexus/archiver/Archiver.java b/src/main/java/org/codehaus/plexus/archiver/Archiver.java index ed0240516..19b29d8c2 100644 --- a/src/main/java/org/codehaus/plexus/archiver/Archiver.java +++ b/src/main/java/org/codehaus/plexus/archiver/Archiver.java @@ -470,6 +470,16 @@ ResourceIterator getResources() */ String getOverrideGroupName(); + /** + * @since 4.7.0 + */ + void setUmask( int umask ); + + /** + * @since 4.7.0 + */ + int getUmask(); + /** * This method is obsolete and will just call {@link #configureReproducibleBuild(FileTime)} * with the Date transformed into FileTime. diff --git a/src/main/java/org/codehaus/plexus/archiver/diags/DelgatingArchiver.java b/src/main/java/org/codehaus/plexus/archiver/diags/DelgatingArchiver.java index f51c1b4ff..bd419431b 100644 --- a/src/main/java/org/codehaus/plexus/archiver/diags/DelgatingArchiver.java +++ b/src/main/java/org/codehaus/plexus/archiver/diags/DelgatingArchiver.java @@ -420,6 +420,18 @@ public String getOverrideGroupName() return target.getOverrideGroupName(); } + @Override + public void setUmask( int umask ) + { + target.setUmask( umask ); + } + + @Override + public int getUmask() + { + return target.getUmask(); + } + /** * @deprecated Use {@link #configureReproducibleBuild(FileTime)} instead. */ diff --git a/src/main/java/org/codehaus/plexus/archiver/diags/NoOpArchiver.java b/src/main/java/org/codehaus/plexus/archiver/diags/NoOpArchiver.java index 35d2f8a64..9a9344032 100644 --- a/src/main/java/org/codehaus/plexus/archiver/diags/NoOpArchiver.java +++ b/src/main/java/org/codehaus/plexus/archiver/diags/NoOpArchiver.java @@ -435,6 +435,18 @@ public String getOverrideGroupName() return null; } + @Override + public void setUmask( int umask ) + { + + } + + @Override + public int getUmask() + { + return 0; + } + /** * @deprecated Use {@link #configureReproducibleBuild(FileTime)} instead. */ diff --git a/src/main/java/org/codehaus/plexus/archiver/diags/TrackingArchiver.java b/src/main/java/org/codehaus/plexus/archiver/diags/TrackingArchiver.java index 9b03beed5..d2a9159e6 100644 --- a/src/main/java/org/codehaus/plexus/archiver/diags/TrackingArchiver.java +++ b/src/main/java/org/codehaus/plexus/archiver/diags/TrackingArchiver.java @@ -496,6 +496,18 @@ public String getOverrideGroupName() return null; } + + @Override + public void setUmask( int umask ) + { + } + + @Override + public int getUmask() + { + return 0; + } + /** * @deprecated Use {@link #configureReproducibleBuild(FileTime)} instead. */