Browse code

ignore lchown error on docker cp

Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)

Victor Vieux authored on 2014/05/21 09:10:35
Showing 4 changed files
... ...
@@ -2058,7 +2058,7 @@ func (cli *DockerCli) CmdCp(args ...string) error {
2058 2058
 	}
2059 2059
 
2060 2060
 	if statusCode == 200 {
2061
-		if err := archive.Untar(stream, copyData.Get("HostPath"), nil); err != nil {
2061
+		if err := archive.Untar(stream, copyData.Get("HostPath"), &archive.TarOptions{NoLchown: true}); err != nil {
2062 2062
 			return err
2063 2063
 		}
2064 2064
 	}
... ...
@@ -28,6 +28,7 @@ type (
28 28
 	TarOptions    struct {
29 29
 		Includes    []string
30 30
 		Compression Compression
31
+		NoLchown    bool
31 32
 	}
32 33
 )
33 34
 
... ...
@@ -179,7 +180,7 @@ func addTarFile(path, name string, tw *tar.Writer) error {
179 179
 	return nil
180 180
 }
181 181
 
182
-func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader) error {
182
+func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, Lchown bool) error {
183 183
 	// hdr.Mode is in linux format, which we can use for sycalls,
184 184
 	// but for os.Foo() calls we need the mode converted to os.FileMode,
185 185
 	// so use hdrInfo.Mode() (they differ for e.g. setuid bits)
... ...
@@ -240,7 +241,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader) e
240 240
 		return fmt.Errorf("Unhandled tar header type %d\n", hdr.Typeflag)
241 241
 	}
242 242
 
243
-	if err := os.Lchown(path, hdr.Uid, hdr.Gid); err != nil {
243
+	if err := os.Lchown(path, hdr.Uid, hdr.Gid); err != nil && Lchown {
244 244
 		return err
245 245
 	}
246 246
 
... ...
@@ -415,8 +416,7 @@ func Untar(archive io.Reader, dest string, options *TarOptions) error {
415 415
 				}
416 416
 			}
417 417
 		}
418
-
419
-		if err := createTarFile(path, dest, hdr, tr); err != nil {
418
+		if err := createTarFile(path, dest, hdr, tr, options == nil || !options.NoLchown); err != nil {
420 419
 			return err
421 420
 		}
422 421
 
... ...
@@ -3,7 +3,6 @@ package archive
3 3
 import (
4 4
 	"bytes"
5 5
 	"fmt"
6
-	"github.com/dotcloud/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
7 6
 	"io"
8 7
 	"io/ioutil"
9 8
 	"os"
... ...
@@ -11,6 +10,8 @@ import (
11 11
 	"path"
12 12
 	"testing"
13 13
 	"time"
14
+
15
+	"github.com/dotcloud/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
14 16
 )
15 17
 
16 18
 func TestCmdStreamLargeStderr(t *testing.T) {
... ...
@@ -132,7 +133,7 @@ func TestTarUntar(t *testing.T) {
132 132
 // Failing prevents the archives from being uncompressed during ADD
133 133
 func TestTypeXGlobalHeaderDoesNotFail(t *testing.T) {
134 134
 	hdr := tar.Header{Typeflag: tar.TypeXGlobalHeader}
135
-	err := createTarFile("pax_global_header", "some_dir", &hdr, nil)
135
+	err := createTarFile("pax_global_header", "some_dir", &hdr, nil, true)
136 136
 	if err != nil {
137 137
 		t.Fatal(err)
138 138
 	}
... ...
@@ -2,13 +2,14 @@ package archive
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"github.com/dotcloud/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
6 5
 	"io"
7 6
 	"io/ioutil"
8 7
 	"os"
9 8
 	"path/filepath"
10 9
 	"strings"
11 10
 	"syscall"
11
+
12
+	"github.com/dotcloud/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
12 13
 )
13 14
 
14 15
 // Linux device nodes are a bit weird due to backwards compat with 16 bit device nodes.
... ...
@@ -79,7 +80,7 @@ func ApplyLayer(dest string, layer ArchiveReader) error {
79 79
 					}
80 80
 					defer os.RemoveAll(aufsTempdir)
81 81
 				}
82
-				if err := createTarFile(filepath.Join(aufsTempdir, basename), dest, hdr, tr); err != nil {
82
+				if err := createTarFile(filepath.Join(aufsTempdir, basename), dest, hdr, tr, true); err != nil {
83 83
 					return err
84 84
 				}
85 85
 			}
... ...
@@ -126,7 +127,7 @@ func ApplyLayer(dest string, layer ArchiveReader) error {
126 126
 				srcData = tmpFile
127 127
 			}
128 128
 
129
-			if err := createTarFile(path, dest, srcHdr, srcData); err != nil {
129
+			if err := createTarFile(path, dest, srcHdr, srcData, true); err != nil {
130 130
 				return err
131 131
 			}
132 132