From 7a767a1a7e5413f37fdfbb2a1fed87e4718a79b5 Mon Sep 17 00:00:00 2001 From: Erik Hollensbe Date: Mon, 14 Nov 2016 05:37:08 -0800 Subject: [PATCH] daemon/archive.go: Fix copy routines to preserve UID. This changes the long-standing bug of copy operations not preserving the UID/GID information after the files arrive to the container. Signed-off-by: Erik Hollensbe --- command/container/cp.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/command/container/cp.go b/command/container/cp.go index a1d7110a61..a4165a18d2 100644 --- a/command/container/cp.go +++ b/command/container/cp.go @@ -20,6 +20,7 @@ type copyOptions struct { source string destination string followLink bool + copyUIDGID bool } type copyDirection int @@ -66,6 +67,7 @@ func NewCopyCommand(dockerCli *command.DockerCli) *cobra.Command { flags := cmd.Flags() flags.BoolVarP(&opts.followLink, "follow-link", "L", false, "Always follow symbol link in SRC_PATH") + flags.BoolVarP(&opts.copyUIDGID, "archive", "a", false, "Archive mode (copy all uid/gid information)") return cmd } @@ -92,7 +94,7 @@ func runCopy(dockerCli *command.DockerCli, opts copyOptions) error { case fromContainer: return copyFromContainer(ctx, dockerCli, srcContainer, srcPath, dstPath, cpParam) case toContainer: - return copyToContainer(ctx, dockerCli, srcPath, dstContainer, dstPath, cpParam) + return copyToContainer(ctx, dockerCli, srcPath, dstContainer, dstPath, cpParam, opts.copyUIDGID) case acrossContainers: // Copying between containers isn't supported. return errors.New("copying between containers is not supported") @@ -175,7 +177,7 @@ func copyFromContainer(ctx context.Context, dockerCli *command.DockerCli, srcCon return archive.CopyTo(preArchive, srcInfo, dstPath) } -func copyToContainer(ctx context.Context, dockerCli *command.DockerCli, srcPath, dstContainer, dstPath string, cpParam *cpConfig) (err error) { +func copyToContainer(ctx context.Context, dockerCli *command.DockerCli, srcPath, dstContainer, dstPath string, cpParam *cpConfig, copyUIDGID bool) (err error) { if srcPath != "-" { // Get an absolute source path. srcPath, err = resolveLocalPath(srcPath) @@ -265,6 +267,7 @@ func copyToContainer(ctx context.Context, dockerCli *command.DockerCli, srcPath, options := types.CopyToContainerOptions{ AllowOverwriteDirWithFile: false, + CopyUIDGID: copyUIDGID, } return dockerCli.Client().CopyToContainer(ctx, dstContainer, resolvedDstPath, content, options)