diff --git a/cache/image_cache.go b/cache/image_cache.go index 461a4446..7023b784 100644 --- a/cache/image_cache.go +++ b/cache/image_cache.go @@ -119,7 +119,7 @@ func (c *ImageCache) RetrieveLayer(diffID string) (io.ReadCloser, error) { if IsLayerNotFound(err) { return nil, NewReadErr(fmt.Sprintf("failed to find cache layer with SHA '%s'", diffID)) } - return nil, NewReadErr(fmt.Sprintf("unknown error retrieving layer with SHA '%s'", diffID)) + return nil, fmt.Errorf("failed to get cache layer with SHA '%s'", diffID) } return closer, nil } @@ -143,28 +143,3 @@ func (c *ImageCache) Commit() error { return nil } - -// LayerExists checks if a layer exists in the cache -func (c *ImageCache) LayerExists(diffID string) (bool, error) { - layers, err := c.origImage.UnderlyingImage().Layers() - if err != nil { - return false, errors.Wrap(err, "getting image layers") - } - - for _, layer := range layers { - d, err := layer.DiffID() - if err != nil { - return false, errors.Wrap(err, "getting layer diffID") - } - - if d.String() == diffID { - return true, nil - } - } - return false, nil -} - -// Destroy deletes the cache image -func (c *ImageCache) Destroy() { - c.imageDeleter.DeleteImage(c.origImage) -} diff --git a/cache/image_cache_test.go b/cache/image_cache_test.go index 67e370bf..3a92c45e 100644 --- a/cache/image_cache_test.go +++ b/cache/image_cache_test.go @@ -146,7 +146,7 @@ func testImageCache(t *testing.T, when spec.G, it spec.S) { when("layer does not exist", func() { it("returns an error", func() { _, err := subject.RetrieveLayer("some_nonexistent_sha") - h.AssertError(t, err, "unknown error retrieving layer with SHA 'some_nonexistent_sha'") + h.AssertError(t, err, "failed to get cache layer with SHA 'some_nonexistent_sha'") }) }) }) @@ -236,7 +236,7 @@ func testImageCache(t *testing.T, when spec.G, it spec.S) { h.AssertNil(t, subject.AddLayerFile(testLayerTarPath, testLayerSHA)) _, err := subject.RetrieveLayer(testLayerSHA) - h.AssertError(t, err, fmt.Sprintf("unknown error retrieving layer with SHA '%s'", testLayerSHA)) + h.AssertError(t, err, fmt.Sprintf("failed to get cache layer with SHA '%s'", testLayerSHA)) }) }) }) diff --git a/cache/volume_cache.go b/cache/volume_cache.go index 27da502d..ce1a5ee2 100644 --- a/cache/volume_cache.go +++ b/cache/volume_cache.go @@ -168,7 +168,7 @@ func (c *VolumeCache) RetrieveLayer(diffID string) (io.ReadCloser, error) { if os.IsPermission(err) { return nil, NewReadErr(fmt.Sprintf("failed to read cache layer with SHA '%s' due to insufficient permissions", diffID)) } - return nil, NewReadErr(fmt.Sprintf("unknown error retrieving layer with SHA '%s'", diffID)) + return nil, fmt.Errorf("failed to get cache layer with SHA '%s'", diffID) } return file, nil } @@ -228,22 +228,3 @@ func (c *VolumeCache) setupStagingDir() error { } return os.MkdirAll(c.stagingDir, 0777) } - -// LayerExists returns true if the layer with the given diffID exists in the cache -func (c *VolumeCache) LayerExists(diffID string) (bool, error) { - path := diffIDPath(c.committedDir, diffID) - if _, err := os.Stat(path); err != nil { - if os.IsNotExist(err) { - return false, nil - } - return false, errors.Wrapf(err, "retrieving layer with SHA '%s'", diffID) - } - return true, nil -} - -// Destroy removes the cache directory and all its contents -func (c *VolumeCache) Destroy() { - if err := os.RemoveAll(c.dir); err != nil { - c.logger.Warnf("Unable to delete cache directory: %v", err.Error()) - } -} diff --git a/cache/volume_cache_test.go b/cache/volume_cache_test.go index 161d72e2..fe14f529 100644 --- a/cache/volume_cache_test.go +++ b/cache/volume_cache_test.go @@ -211,7 +211,7 @@ func testVolumeCache(t *testing.T, when spec.G, it spec.S) { when("layer does not exist", func() { it("returns an error", func() { _, err := subject.RetrieveLayer("some_nonexistent_sha") - h.AssertError(t, err, "Layer with SHA 'some_nonexistent_sha' not found") + h.AssertError(t, err, "failed to find cache layer with SHA 'some_nonexistent_sha'") }) }) }) @@ -235,7 +235,7 @@ func testVolumeCache(t *testing.T, when spec.G, it spec.S) { when("layer does not exist", func() { it("returns an error", func() { _, err := subject.RetrieveLayerFile("some_nonexistent_sha") - h.AssertError(t, err, "Layer with SHA 'some_nonexistent_sha' not found") + h.AssertError(t, err, "failed to find cache layer with SHA 'some_nonexistent_sha'") }) }) }) @@ -345,7 +345,7 @@ func testVolumeCache(t *testing.T, when spec.G, it spec.S) { h.AssertNil(t, subject.AddLayerFile(tarPath, "some_sha")) _, err := subject.RetrieveLayer("some_sha") - h.AssertError(t, err, "Layer with SHA 'some_sha' not found") + h.AssertError(t, err, "failed to find cache layer with SHA 'some_sha'") }) }) @@ -420,7 +420,7 @@ func testVolumeCache(t *testing.T, when spec.G, it spec.S) { h.AssertNil(t, subject.AddLayer(layerReader, layerSha)) _, err := subject.RetrieveLayer(layerSha) - h.AssertError(t, err, fmt.Sprintf("Layer with SHA '%s' not found", layerSha)) + h.AssertError(t, err, fmt.Sprintf("failed to find cache layer with SHA '%s'", layerSha)) }) }) diff --git a/phase/exporter.go b/phase/exporter.go index a6bce1dd..4808e857 100644 --- a/phase/exporter.go +++ b/phase/exporter.go @@ -34,9 +34,7 @@ type Cache interface { AddLayerFile(tarPath string, sha string) error ReuseLayer(sha string) error RetrieveLayer(sha string) (io.ReadCloser, error) - LayerExists(sha string) (bool, error) Commit() error - Destroy() } type Exporter struct {