Skip to content

Commit

Permalink
add umask support and use 022 in RB mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed May 5, 2023
1 parent 53f6d2a commit e3b02db
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>

<artifactId>plexus-archiver</artifactId>
<version>4.6.4-SNAPSHOT</version>
<version>4.7.0-SNAPSHOT</version>
<name>Plexus Archiver Component</name>

<scm>
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/org/codehaus/plexus/archiver/AbstractArchiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArchiveFinalizer> finalizers;
Expand Down Expand Up @@ -440,14 +442,19 @@ 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() )
{
throw new ArchiverException( resource.getName() + " not found." );
}

if ( umask > 0 )
{
permissions &= ~umask;
}

ArchiveEntry entry;
if ( resource.isFile() )
{
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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 );
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/codehaus/plexus/archiver/Archiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/codehaus/plexus/archiver/diags/NoOpArchiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit e3b02db

Please sign in to comment.