Revert "Remove JNR (#5979)" (#6299)

This reverts commit 899d9fb584.
This commit is contained in:
Basil Crow authored and GitHub committed 2022-02-21 23:00:19 -08:00
1 parent 899d9fb584
commit dbb6e2a76f
6 files changed
+70

No files matched your search

@@ -40,6 +40,7 @@ import static org.mockito.Mockito.when;
import hudson.FilePath.TarCompression;
import hudson.model.TaskListener;
import hudson.os.PosixAPI;
import hudson.os.WindowsUtil;
import hudson.remoting.VirtualChannel;
import hudson.slaves.WorkspaceList;
@@ -478,6 +479,25 @@ public class FilePathTest {
}
}
@Test public void copyToWithPermissionSpecialPermissions() throws IOException, InterruptedException {
assumeFalse(Functions.isWindows() || Platform.isDarwin());
File tmp = temp.getRoot();
File original = new File(tmp, "original");
FilePath originalP = new FilePath(channels.french, original.getPath());
originalP.touch(0);
PosixAPI.jnr().chmod(original.getAbsolutePath(), 02777); // Read/write/execute for everyone and setuid.
File sameChannelCopy = new File(tmp, "sameChannelCopy");
FilePath sameChannelCopyP = new FilePath(channels.french, sameChannelCopy.getPath());
originalP.copyToWithPermission(sameChannelCopyP);
assertEquals("Special permissions should be copied on the same machine", 02777, PosixAPI.jnr().stat(sameChannelCopy.getAbsolutePath()).mode() & 07777);
File diffChannelCopy = new File(tmp, "diffChannelCopy");
FilePath diffChannelCopyP = new FilePath(channels.british, diffChannelCopy.getPath());
originalP.copyToWithPermission(diffChannelCopyP);
assertEquals("Special permissions should not be copied across machines", 00777, PosixAPI.jnr().stat(diffChannelCopy.getAbsolutePath()).mode() & 07777);
}
@Test public void symlinkInTar() throws Exception {
assumeFalse(Functions.isWindows());