mirror of https://github.com/docker/docs.git
Cleaned up fs.LayerStore.AddLayer()
This commit is contained in:
parent
68e173ad50
commit
1b34630b8c
25
fs/layers.go
25
fs/layers.go
|
@ -4,7 +4,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/future"
|
"github.com/dotcloud/docker/future"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
@ -88,33 +87,13 @@ func (store *LayerStore) AddLayer(id string, archive Archive) (string, error) {
|
||||||
if _, err := os.Stat(store.layerPath(id)); err == nil {
|
if _, err := os.Stat(store.layerPath(id)); err == nil {
|
||||||
return "", fmt.Errorf("Layer already exists: %v", id)
|
return "", fmt.Errorf("Layer already exists: %v", id)
|
||||||
}
|
}
|
||||||
errors := make(chan error)
|
|
||||||
// Untar
|
|
||||||
tmp, err := store.Mktemp()
|
tmp, err := store.Mktemp()
|
||||||
defer os.RemoveAll(tmp)
|
defer os.RemoveAll(tmp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Mktemp failed: %s", err)
|
return "", fmt.Errorf("Mktemp failed: %s", err)
|
||||||
}
|
}
|
||||||
|
if err := Untar(archive, tmp); err != nil {
|
||||||
untarR, untarW := io.Pipe()
|
return "", nil
|
||||||
go func() {
|
|
||||||
errors <- Untar(untarR, tmp)
|
|
||||||
}()
|
|
||||||
_, err = io.Copy(untarW, archive)
|
|
||||||
untarW.Close()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
// Wait for goroutines
|
|
||||||
for i := 0; i < 1; i += 1 {
|
|
||||||
select {
|
|
||||||
case err := <-errors:
|
|
||||||
{
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
layer := store.layerPath(id)
|
layer := store.layerPath(id)
|
||||||
if !store.Exists(id) {
|
if !store.Exists(id) {
|
||||||
|
|
Loading…
Reference in New Issue