diff --git a/image/archive.go b/image/archive.go deleted file mode 100644 index 501d549cc8..0000000000 --- a/image/archive.go +++ /dev/null @@ -1,73 +0,0 @@ -package image - -import ( - "errors" - "io" - "io/ioutil" - "os/exec" -) - -type Compression uint32 - -const ( - Uncompressed Compression = iota - Bzip2 - Gzip -) - -func (compression *Compression) Flag() string { - switch *compression { - case Bzip2: - return "j" - case Gzip: - return "z" - } - return "" -} - -func Tar(path string, compression Compression) (io.Reader, error) { - cmd := exec.Command("bsdtar", "-f", "-", "-C", path, "-c"+compression.Flag(), ".") - return CmdStream(cmd) -} - -func Untar(archive io.Reader, path string) error { - cmd := exec.Command("bsdtar", "-f", "-", "-C", path, "-x") - cmd.Stdin = archive - output, err := cmd.CombinedOutput() - if err != nil { - return errors.New(err.Error() + ": " + string(output)) - } - return nil -} - -func CmdStream(cmd *exec.Cmd) (io.Reader, error) { - stdout, err := cmd.StdoutPipe() - if err != nil { - return nil, err - } - stderr, err := cmd.StderrPipe() - if err != nil { - return nil, err - } - pipeR, pipeW := io.Pipe() - go func() { - _, err := io.Copy(pipeW, stdout) - if err != nil { - pipeW.CloseWithError(err) - } - errText, e := ioutil.ReadAll(stderr) - if e != nil { - errText = []byte("(...couldn't fetch stderr: " + e.Error() + ")") - } - if err := cmd.Wait(); err != nil { - // FIXME: can this block if stderr outputs more than the size of StderrPipe()'s buffer? - pipeW.CloseWithError(errors.New(err.Error() + ": " + string(errText))) - } else { - pipeW.Close() - } - }() - if err := cmd.Start(); err != nil { - return nil, err - } - return pipeR, nil -} diff --git a/image/archive_test.go b/image/archive_test.go deleted file mode 100644 index 4271849797..0000000000 --- a/image/archive_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package image - -import ( - "io/ioutil" - "os" - "os/exec" - "testing" -) - -func TestCmdStreamBad(t *testing.T) { - badCmd := exec.Command("/bin/sh", "-c", "echo hello; echo >&2 error couldn\\'t reverse the phase pulser; exit 1") - out, err := CmdStream(badCmd) - if err != nil { - t.Fatalf("Failed to start command: " + err.Error()) - } - if output, err := ioutil.ReadAll(out); err == nil { - t.Fatalf("Command should have failed") - } else if err.Error() != "exit status 1: error couldn't reverse the phase pulser\n" { - t.Fatalf("Wrong error value (%s)", err.Error()) - } else if s := string(output); s != "hello\n" { - t.Fatalf("Command output should be '%s', not '%s'", "hello\\n", output) - } -} - -func TestCmdStreamGood(t *testing.T) { - cmd := exec.Command("/bin/sh", "-c", "echo hello; exit 0") - out, err := CmdStream(cmd) - if err != nil { - t.Fatal(err) - } - if output, err := ioutil.ReadAll(out); err != nil { - t.Fatalf("Command should not have failed (err=%s)", err) - } else if s := string(output); s != "hello\n" { - t.Fatalf("Command output should be '%s', not '%s'", "hello\\n", output) - } -} - -func TestTarUntar(t *testing.T) { - archive, err := Tar(".", Uncompressed) - if err != nil { - t.Fatal(err) - } - tmp, err := ioutil.TempDir("", "docker-test-untar") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) - if err := Untar(archive, tmp); err != nil { - t.Fatal(err) - } - if _, err := os.Stat(tmp); err != nil { - t.Fatalf("Error stating %s: %s", tmp, err.Error()) - } -} diff --git a/image/layers_test.go b/image/layers_test.go deleted file mode 100644 index eec59ab3d0..0000000000 --- a/image/layers_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package image - -import ( - "bytes" - "github.com/dotcloud/docker/fake" - "github.com/dotcloud/docker/future" - "io/ioutil" - "os" - "testing" -) - -func TestAddLayer(t *testing.T) { - tmp, err := ioutil.TempDir("", "docker-test-image") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) - store, err := NewLayerStore(tmp) - if err != nil { - t.Fatal(err) - } - archive, err := fake.FakeTar() - if err != nil { - t.Fatal(err) - } - layer, err := store.AddLayer(archive) - if err != nil { - t.Fatal(err) - } - if _, err := os.Stat(layer); err != nil { - t.Fatalf("Error testing for existence of layer: %s\n", err.Error()) - } -} - -func TestComputeId(t *testing.T) { - id1, err := future.ComputeId(bytes.NewBufferString("hello world\n")) - if err != nil { - t.Fatal(err) - } - id2, err := future.ComputeId(bytes.NewBufferString("foo bar\n")) - if err != nil { - t.Fatal(err) - } - if id1 == id2 { - t.Fatalf("Identical checksums for difference content (%s == %s)", id1, id2) - } -}