From 77ae9789d3e1cfb895de9eaf343866f984c92668 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 7 Nov 2013 20:30:56 +0000 Subject: [PATCH] Internal cleanup: use the mounted container filesystem instead of manipulating the aufs layers directly --- api_test.go | 12 +++--------- container.go | 11 +++++++---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/api_test.go b/api_test.go index 34c89f8294..864628a762 100644 --- a/api_test.go +++ b/api_test.go @@ -676,7 +676,7 @@ func TestPostContainersCreate(t *testing.T) { t.Fatal(err) } - if _, err := os.Stat(path.Join(container.rwPath(), "test")); err != nil { + if _, err := os.Stat(path.Join(container.RootfsPath(), "test")); err != nil { if os.IsNotExist(err) { utils.Debugf("Err: %s", err) t.Fatalf("The test file has not been created") @@ -1145,7 +1145,7 @@ func TestDeleteContainers(t *testing.T) { t.Fatalf("The container as not been deleted") } - if _, err := os.Stat(path.Join(container.rwPath(), "test")); err == nil { + if _, err := os.Stat(path.Join(container.RootfsPath(), "test")); err == nil { t.Fatalf("The test file has not been deleted") } } @@ -1276,13 +1276,7 @@ func TestDeleteImages(t *testing.T) { t.Errorf("Expected %d image, %d found", len(initialImages), len(images)) } - /* if c := runtime.Get(container.Id); c != nil { - t.Fatalf("The container as not been deleted") - } - - if _, err := os.Stat(path.Join(container.rwPath(), "test")); err == nil { - t.Fatalf("The test file has not been deleted") - } */ + // FIXME: check that container has been deleted, and its filesystem too } func TestJsonContentType(t *testing.T) { diff --git a/container.go b/container.go index 6994c3b460..f71c1db3fd 100644 --- a/container.go +++ b/container.go @@ -380,12 +380,11 @@ func (settings *NetworkSettings) PortMappingAPI() []APIPort { // Inject the io.Reader at the given path. Note: do not close the reader func (container *Container) Inject(file io.Reader, pth string) error { - // Make sure the directory exists - if err := os.MkdirAll(path.Join(container.rwPath(), path.Dir(pth)), 0755); err != nil { - return err + if err := container.EnsureMounted(); err != nil { + return fmt.Errorf("inject: error mounting container %s: %s", container.ID, err) } // FIXME: Handle permissions/already existing dest - dest, err := os.Create(path.Join(container.rwPath(), pth)) + dest, err := os.Create(path.Join(container.RootfsPath(), pth)) if err != nil { return err } @@ -1463,6 +1462,10 @@ func (container *Container) GetSize() (int64, int64) { return nil }) + if err := container.EnsureMounted(); err != nil { + utils.Errorf("Warning: failed to compute size of container rootfs %s: %s", container.ID, err) + return sizeRw, sizeRootfs + } _, err := os.Stat(container.RootfsPath()) if err == nil { filepath.Walk(container.RootfsPath(), func(path string, fileInfo os.FileInfo, err error) error {