diff options
author | Simon Rettberg | 2020-12-10 13:51:12 +0100 |
---|---|---|
committer | Simon Rettberg | 2020-12-10 13:51:12 +0100 |
commit | d9d777cbb4a426e996fe7fa04e28561d6eaa0707 (patch) | |
tree | cc8b893f0762f5241a4262bcb3a5e72cda8b12b0 | |
parent | [ListArchive] Add more data to output (diff) | |
download | tmlite-bwlp-d9d777cbb4a426e996fe7fa04e28561d6eaa0707.tar.gz tmlite-bwlp-d9d777cbb4a426e996fe7fa04e28561d6eaa0707.tar.xz tmlite-bwlp-d9d777cbb4a426e996fe7fa04e28561d6eaa0707.zip |
[RecompressArchive] Add forceRoot flag to chown/chgrp to root
-rw-r--r-- | src/main/java/org/openslx/satserver/util/Archive.java | 21 | ||||
-rw-r--r-- | src/main/java/org/openslx/taskmanager/tasks/RecompressArchive.java | 5 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/main/java/org/openslx/satserver/util/Archive.java b/src/main/java/org/openslx/satserver/util/Archive.java index e52a5f6..86b9955 100644 --- a/src/main/java/org/openslx/satserver/util/Archive.java +++ b/src/main/java/org/openslx/satserver/util/Archive.java @@ -101,7 +101,8 @@ public class Archive } } - public static TarArchiveEntry createTarArchiveEntry( ArchiveEntry inEntry, int defaultUser, int defaultGroup, int defaultDirMode, int defaultFileMode ) + public static TarArchiveEntry createTarArchiveEntry( ArchiveEntry inEntry, + int defaultUser, int defaultGroup, int defaultDirMode, int defaultFileMode, boolean overrideUserGroup ) { String name = inEntry.getName(); if ( Util.isEmpty( name ) ) @@ -122,6 +123,18 @@ public class Archive ( (TarArchiveEntry)inEntry ).writeEntryHeader( buffer ); outEntry.parseTarHeader( buffer ); outEntry.setName( name ); // Reset, as this was overwritten + if ( overrideUserGroup ) { + // Always replace these + outEntry.setUserId( defaultUser ); + outEntry.setGroupId( defaultGroup ); + // TODO + if ( defaultUser == 0 ) { + outEntry.setUserName( "root" ); + } + if ( defaultGroup == 0 ) { + outEntry.setGroupName( "root" ); + } + } } else if ( inEntry instanceof ArArchiveEntry ) { // Source is ar - has most of the stuff tar supports; transform outEntry.setIds( ( (ArArchiveEntry)inEntry ).getUserId(), ( (ArArchiveEntry)inEntry ).getGroupId() ); @@ -162,6 +175,12 @@ public class Archive } return outEntry; } + + public static TarArchiveEntry createTarArchiveEntry( ArchiveEntry inEntry, + int defaultUser, int defaultGroup, int defaultDirMode, int defaultFileMode ) + { + return createTarArchiveEntry( inEntry, defaultUser, defaultGroup, defaultDirMode, defaultFileMode, false ); + } public static boolean tarAddFile( TarArchiveOutputStream tar, String inArchiveFileName, File sourceFile, int mode ) { diff --git a/src/main/java/org/openslx/taskmanager/tasks/RecompressArchive.java b/src/main/java/org/openslx/taskmanager/tasks/RecompressArchive.java index 1fc897d..04e7ed6 100644 --- a/src/main/java/org/openslx/taskmanager/tasks/RecompressArchive.java +++ b/src/main/java/org/openslx/taskmanager/tasks/RecompressArchive.java @@ -32,6 +32,9 @@ public class RecompressArchive extends AbstractTask @Expose private String outputFile; + + @Expose + private boolean forceRoot; /* * Own vars/constants not being deserialized @@ -110,7 +113,7 @@ public class RecompressArchive extends AbstractTask if ( inEntry.getName().equals( "/" ) || inEntry.getName().equals( "./" ) ) continue; // Construct TarArchiveEntry - we want unix stuff like uid/gid, links, file/dir mode, so try to get from source archive - TarArchiveEntry outEntry = Archive.createTarArchiveEntry( inEntry, 0, 0, 0755, 0644 ); + TarArchiveEntry outEntry = Archive.createTarArchiveEntry( inEntry, 0, 0, 0755, 0644, this.forceRoot ); if ( outEntry == null ) { status.addWarning( "Ignoring invalid entry " + inEntry.getName() + " in " + a.inputFile ); continue; |