Browse code

Use archive.CopyWithTar in vfs.Create

The vfs storage driver currently shells out to the `cp` binary on the host
system to perform an 'archive' copy of the base image to a new directory.
The archive option preserves the modified time of the files which are created
but there was an issue where it was unable to preserve the modified time of
copied symbolic links on some host systems with an outdated version of `cp`.

This change no longer relies on the host system implementation and instead
utilizes the `CopyWithTar` function found in `pkg/archive` which is used
to copy from source to destination directory using a Tar archive, which
should correctly preserve file attributes.

Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)

Josh Hawn authored on 2014/10/28 03:38:22
Showing 1 changed files
... ...
@@ -8,6 +8,7 @@ import (
8 8
 	"path"
9 9
 
10 10
 	"github.com/docker/docker/daemon/graphdriver"
11
+	"github.com/docker/docker/pkg/archive"
11 12
 	"github.com/docker/libcontainer/label"
12 13
 )
13 14
 
... ...
@@ -46,21 +47,6 @@ func isGNUcoreutils() bool {
46 46
 	return false
47 47
 }
48 48
 
49
-func copyDir(src, dst string) error {
50
-	argv := make([]string, 0, 4)
51
-
52
-	if isGNUcoreutils() {
53
-		argv = append(argv, "-aT", "--reflink=auto", src, dst)
54
-	} else {
55
-		argv = append(argv, "-a", src+"/.", dst+"/.")
56
-	}
57
-
58
-	if output, err := exec.Command("cp", argv...).CombinedOutput(); err != nil {
59
-		return fmt.Errorf("Error VFS copying directory: %s (%s)", err, output)
60
-	}
61
-	return nil
62
-}
63
-
64 49
 func (d *Driver) Create(id, parent string) error {
65 50
 	dir := d.dir(id)
66 51
 	if err := os.MkdirAll(path.Dir(dir), 0700); err != nil {
... ...
@@ -80,7 +66,7 @@ func (d *Driver) Create(id, parent string) error {
80 80
 	if err != nil {
81 81
 		return fmt.Errorf("%s: %s", parent, err)
82 82
 	}
83
-	if err := copyDir(parentDir, dir); err != nil {
83
+	if err := archive.CopyWithTar(parentDir, dir); err != nil {
84 84
 		return err
85 85
 	}
86 86
 	return nil