Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ private void recursiveTar(
}

final TarArchiveEntry tarEntry = new TarArchiveEntry(sourceFile, tarEntryFilename.replaceAll("^/", ""));
tarEntry.setUserId(0);
tarEntry.setGroupId(0);
tarEntry.setUserName("root");
tarEntry.setGroupName("root");

// TarArchiveEntry automatically sets the mode for file/directory, but we can update to ensure that the mode is set exactly (inc executable bits)
tarEntry.setMode(getUnixFileMode(itemPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Cleanup;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -32,6 +33,27 @@ void forClasspathResource() throws Exception {
performChecks(mountableFile);
}

@Test
void tarEntriesShouldUseRootOwnership() throws Exception {
final Path file = createTempFile("ownership-test.txt");
final MountableFile mountableFile = MountableFile.forHostPath(file);

@Cleanup
final TarArchiveInputStream tais = intoTarArchive(taos -> {
mountableFile.transferTo(taos, "/ownership-test.txt");
});

final TarArchiveEntry tarEntry = tais.getNextEntry();

assertThat(tarEntry).isNotNull();

System.out.println("UID = " + tarEntry.getLongUserId());
System.out.println("GID = " + tarEntry.getLongGroupId());

assertThat(tarEntry.getLongUserId()).isZero();
assertThat(tarEntry.getLongGroupId()).isZero();
}

@Test
void forClasspathResourceWithAbsolutePath() throws Exception {
final MountableFile mountableFile = MountableFile.forClasspathResource("/mappable-resource/test-resource.txt");
Expand Down