Skip to content

Commit

Permalink
daemon/archive.go: Fix copy routines to preserve UID.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Erik Hollensbe committed Apr 12, 2017
1 parent 9a5513b commit 7a767a1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions command/container/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type copyOptions struct {
source string
destination string
followLink bool
copyUIDGID bool
}

type copyDirection int
Expand Down Expand Up @@ -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
}
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7a767a1

Please sign in to comment.