Signed-off-by: Tibor Vass <teabee89@gmail.com>
Conflicts:
graph/load.go
fixed conflict in imports
| ... | ... |
@@ -11,6 +11,7 @@ import ( |
| 11 | 11 |
"github.com/docker/docker/engine" |
| 12 | 12 |
"github.com/docker/docker/image" |
| 13 | 13 |
"github.com/docker/docker/pkg/archive" |
| 14 |
+ "github.com/docker/docker/pkg/chrootarchive" |
|
| 14 | 15 |
) |
| 15 | 16 |
|
| 16 | 17 |
// Loads a set of images into the repository. This is the complementary of ImageExport. |
| ... | ... |
@@ -53,7 +54,7 @@ func (s *TagStore) CmdLoad(job *engine.Job) engine.Status {
|
| 53 | 53 |
excludes[i] = k |
| 54 | 54 |
i++ |
| 55 | 55 |
} |
| 56 |
- if err := archive.Untar(repoFile, repoDir, &archive.TarOptions{Excludes: excludes}); err != nil {
|
|
| 56 |
+ if err := chrootarchive.Untar(repoFile, repoDir, &archive.TarOptions{Excludes: excludes}); err != nil {
|
|
| 57 | 57 |
return job.Error(err) |
| 58 | 58 |
} |
| 59 | 59 |
|
| ... | ... |
@@ -1,11 +1,14 @@ |
| 1 | 1 |
package chrootarchive |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "bytes" |
|
| 5 |
+ "encoding/json" |
|
| 4 | 6 |
"flag" |
| 5 | 7 |
"fmt" |
| 6 | 8 |
"io" |
| 7 | 9 |
"os" |
| 8 | 10 |
"runtime" |
| 11 |
+ "strings" |
|
| 9 | 12 |
"syscall" |
| 10 | 13 |
|
| 11 | 14 |
"github.com/docker/docker/pkg/archive" |
| ... | ... |
@@ -22,7 +25,12 @@ func untar() {
|
| 22 | 22 |
if err := syscall.Chdir("/"); err != nil {
|
| 23 | 23 |
fatal(err) |
| 24 | 24 |
} |
| 25 |
- if err := archive.Untar(os.Stdin, "/", nil); err != nil {
|
|
| 25 |
+ options := new(archive.TarOptions) |
|
| 26 |
+ dec := json.NewDecoder(strings.NewReader(flag.Arg(1))) |
|
| 27 |
+ if err := dec.Decode(options); err != nil {
|
|
| 28 |
+ fatal(err) |
|
| 29 |
+ } |
|
| 30 |
+ if err := archive.Untar(os.Stdin, "/", options); err != nil {
|
|
| 26 | 31 |
fatal(err) |
| 27 | 32 |
} |
| 28 | 33 |
os.Exit(0) |
| ... | ... |
@@ -33,12 +41,18 @@ var ( |
| 33 | 33 |
) |
| 34 | 34 |
|
| 35 | 35 |
func Untar(archive io.Reader, dest string, options *archive.TarOptions) error {
|
| 36 |
+ var buf bytes.Buffer |
|
| 37 |
+ enc := json.NewEncoder(&buf) |
|
| 38 |
+ if err := enc.Encode(options); err != nil {
|
|
| 39 |
+ return fmt.Errorf("Untar json encode: %v", err)
|
|
| 40 |
+ } |
|
| 36 | 41 |
if _, err := os.Stat(dest); os.IsNotExist(err) {
|
| 37 | 42 |
if err := os.MkdirAll(dest, 0777); err != nil {
|
| 38 | 43 |
return err |
| 39 | 44 |
} |
| 40 | 45 |
} |
| 41 |
- cmd := reexec.Command("docker-untar", dest)
|
|
| 46 |
+ |
|
| 47 |
+ cmd := reexec.Command("docker-untar", dest, buf.String())
|
|
| 42 | 48 |
cmd.Stdin = archive |
| 43 | 49 |
out, err := cmd.CombinedOutput() |
| 44 | 50 |
if err != nil {
|
| 45 | 51 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,39 @@ |
| 0 |
+package chrootarchive |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "io/ioutil" |
|
| 4 |
+ "os" |
|
| 5 |
+ "path/filepath" |
|
| 6 |
+ "testing" |
|
| 7 |
+ |
|
| 8 |
+ "github.com/docker/docker/pkg/archive" |
|
| 9 |
+) |
|
| 10 |
+ |
|
| 11 |
+func TestChrootTarUntar(t *testing.T) {
|
|
| 12 |
+ tmpdir, err := ioutil.TempDir("", "docker-TestChrootTarUntar")
|
|
| 13 |
+ if err != nil {
|
|
| 14 |
+ t.Fatal(err) |
|
| 15 |
+ } |
|
| 16 |
+ defer os.RemoveAll(tmpdir) |
|
| 17 |
+ src := filepath.Join(tmpdir, "src") |
|
| 18 |
+ if err := os.MkdirAll(src, 0700); err != nil {
|
|
| 19 |
+ t.Fatal(err) |
|
| 20 |
+ } |
|
| 21 |
+ if err := ioutil.WriteFile(filepath.Join(src, "toto"), []byte("hello toto"), 0644); err != nil {
|
|
| 22 |
+ t.Fatal(err) |
|
| 23 |
+ } |
|
| 24 |
+ if err := ioutil.WriteFile(filepath.Join(src, "lolo"), []byte("hello lolo"), 0644); err != nil {
|
|
| 25 |
+ t.Fatal(err) |
|
| 26 |
+ } |
|
| 27 |
+ stream, err := archive.Tar(src, archive.Uncompressed) |
|
| 28 |
+ if err != nil {
|
|
| 29 |
+ t.Fatal(err) |
|
| 30 |
+ } |
|
| 31 |
+ dest := filepath.Join(tmpdir, "src") |
|
| 32 |
+ if err := os.MkdirAll(dest, 0700); err != nil {
|
|
| 33 |
+ t.Fatal(err) |
|
| 34 |
+ } |
|
| 35 |
+ if err := Untar(stream, dest, &archive.TarOptions{Excludes: []string{"lolo"}}); err != nil {
|
|
| 36 |
+ t.Fatal(err) |
|
| 37 |
+ } |
|
| 38 |
+} |