diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/command/CopyArchiveToContainerCmd.java b/docker-java-api/src/main/java/com/github/dockerjava/api/command/CopyArchiveToContainerCmd.java index a4dfb5c03..19b3c3843 100644 --- a/docker-java-api/src/main/java/com/github/dockerjava/api/command/CopyArchiveToContainerCmd.java +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/command/CopyArchiveToContainerCmd.java @@ -16,6 +16,7 @@ public interface CopyArchiveToContainerCmd extends SyncDockerCmd { boolean isDirChildrenOnly(); + boolean isCopyUIDGID(); /** * Set container's id * @@ -49,6 +50,14 @@ public interface CopyArchiveToContainerCmd extends SyncDockerCmd { */ CopyArchiveToContainerCmd withNoOverwriteDirNonDir(boolean noOverwriteDirNonDir); + /** + * If set to true then ownership is set to the user and primary group at the destination + * + * @param copyUIDGID + * flag to know if ownership should be set to the user and primary group at the destination + */ + CopyArchiveToContainerCmd withCopyUIDGID(boolean copyUIDGID); + /** * If this flag is set to true, all children of the local directory will be copied to the remote without the root directory. For ex: if * I have root/titi and root/tata and the remote path is /var/data. dirChildrenOnly = true will create /var/data/titi and /var/data/tata diff --git a/docker-java-core/src/main/java/com/github/dockerjava/core/command/CopyArchiveToContainerCmdImpl.java b/docker-java-core/src/main/java/com/github/dockerjava/core/command/CopyArchiveToContainerCmdImpl.java index cac15fadf..a915a3b02 100644 --- a/docker-java-core/src/main/java/com/github/dockerjava/core/command/CopyArchiveToContainerCmdImpl.java +++ b/docker-java-core/src/main/java/com/github/dockerjava/core/command/CopyArchiveToContainerCmdImpl.java @@ -31,6 +31,8 @@ public class CopyArchiveToContainerCmdImpl extends AbstrDockerCmd unixSystemClazz = Class.forName("com.sun.security.auth.module.UnixSystem"); + Object unixSystem = unixSystemClazz.newInstance(); + Object uid = unixSystemClazz.getMethod("getUid").invoke(unixSystem); + if (uid == null) { + return null; + } + + return uid instanceof Long ? (Long) uid : Long.parseLong(uid.toString()); + } catch (Exception e) { + return null; + } + } }