Skip to content

Commit

Permalink
Merge pull request #240 from buildpacks/fix/239-delete-app-dir-error
Browse files Browse the repository at this point in the history
exporter no longer tries to delete app dir
  • Loading branch information
ekcasey committed Jan 29, 2020
2 parents d9736bd + 243f026 commit d930835
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (e *Exporter) Export(
}

// creating app layers (slices + app dir)
appSlices, err := e.createAppSliceLayers(workingImage, &layer{path: appDir, identifier: "app"}, buildMD.Slices)
appSlices, err := e.createAppSliceLayers(appDir, buildMD.Slices)
if err != nil {
return errors.Wrap(err, "creating app layers")
}
Expand Down Expand Up @@ -292,20 +292,20 @@ func (e *Exporter) addOrReuseCacheLayer(cache Cache, layer identifiableLayer, pr
return sha, cache.AddLayerFile(sha, tarPath)
}

func (e *Exporter) createAppSliceLayers(image imgutil.Image, appLayer identifiableLayer, slices []Slice) ([]SliceLayer, error) {
func (e *Exporter) createAppSliceLayers(appDir string, slices []Slice) ([]SliceLayer, error) {
var appSlices []SliceLayer

for index, slice := range slices {
var allGlobMatches []string
for _, path := range slice.Paths {
globMatches, err := filepath.Glob(e.toAbs(appLayer.Path(), path))
globMatches, err := filepath.Glob(e.toAbs(appDir, path))
if err != nil {
return nil, errors.Wrap(err, "bad pattern for glob path")
}
allGlobMatches = append(allGlobMatches, globMatches...)
}
sliceLayerID := fmt.Sprintf("slice-%d", index+1)
sliceLayer, err := e.createSliceLayer(image, sliceLayerID, allGlobMatches)
sliceLayer, err := e.createSliceLayer(appDir, sliceLayerID, allGlobMatches)
if err != nil {
return nil, errors.Wrap(err, "creating slice layer")
}
Expand All @@ -322,20 +322,20 @@ func (e *Exporter) createAppSliceLayers(image imgutil.Image, appLayer identifiab
// -------------
// | app dir |
// -------------
tarPath := filepath.Join(e.ArtifactsDir, escapeID(appLayer.Identifier())+".tar")
sha, err := archive.WriteTarFile(appLayer.Path(), tarPath, e.UID, e.GID)
tarPath := filepath.Join(e.ArtifactsDir, "app.tar")
sha, err := archive.WriteTarFile(appDir, tarPath, e.UID, e.GID)
if err != nil {
return nil, errors.Wrapf(err, "exporting layer '%s'", appLayer.Identifier())
return nil, errors.Wrapf(err, "exporting layer 'app'")
}

return append(appSlices, SliceLayer{
ID: appLayer.Identifier(),
ID: "app",
SHA: sha,
TarPath: tarPath,
}), nil
}

func (e *Exporter) createSliceLayer(image imgutil.Image, layerID string, files []string) (SliceLayer, error) {
func (e *Exporter) createSliceLayer(appDir, layerID string, files []string) (SliceLayer, error) {
tarPath := filepath.Join(e.ArtifactsDir, escapeID(layerID)+".tar")
sha, fileSet, err := archive.WriteFilesToTar(tarPath, e.UID, e.GID, files...)
if err != nil {
Expand All @@ -353,6 +353,9 @@ func (e *Exporter) createSliceLayer(image imgutil.Image, layerID string, files [
e.Logger.Errorf("failed to delete file %v", err)
}
} else {
if file == appDir {
continue
}
dirs = append(dirs, file)
}
}
Expand Down

0 comments on commit d930835

Please sign in to comment.