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 <github@hollensbe.org>
This commit is contained in:
Erik Hollensbe 2016-11-14 05:37:08 -08:00
parent 9a5513b791
commit 7a767a1a7e
1 changed files with 5 additions and 2 deletions

View File

@ -20,6 +20,7 @@ type copyOptions struct {
source string source string
destination string destination string
followLink bool followLink bool
copyUIDGID bool
} }
type copyDirection int type copyDirection int
@ -66,6 +67,7 @@ func NewCopyCommand(dockerCli *command.DockerCli) *cobra.Command {
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.followLink, "follow-link", "L", false, "Always follow symbol link in SRC_PATH") 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 return cmd
} }
@ -92,7 +94,7 @@ func runCopy(dockerCli *command.DockerCli, opts copyOptions) error {
case fromContainer: case fromContainer:
return copyFromContainer(ctx, dockerCli, srcContainer, srcPath, dstPath, cpParam) return copyFromContainer(ctx, dockerCli, srcContainer, srcPath, dstPath, cpParam)
case toContainer: case toContainer:
return copyToContainer(ctx, dockerCli, srcPath, dstContainer, dstPath, cpParam) return copyToContainer(ctx, dockerCli, srcPath, dstContainer, dstPath, cpParam, opts.copyUIDGID)
case acrossContainers: case acrossContainers:
// Copying between containers isn't supported. // Copying between containers isn't supported.
return errors.New("copying between containers is not 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) 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 != "-" { if srcPath != "-" {
// Get an absolute source path. // Get an absolute source path.
srcPath, err = resolveLocalPath(srcPath) srcPath, err = resolveLocalPath(srcPath)
@ -265,6 +267,7 @@ func copyToContainer(ctx context.Context, dockerCli *command.DockerCli, srcPath,
options := types.CopyToContainerOptions{ options := types.CopyToContainerOptions{
AllowOverwriteDirWithFile: false, AllowOverwriteDirWithFile: false,
CopyUIDGID: copyUIDGID,
} }
return dockerCli.Client().CopyToContainer(ctx, dstContainer, resolvedDstPath, content, options) return dockerCli.Client().CopyToContainer(ctx, dstContainer, resolvedDstPath, content, options)