-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include symlinks when packing buildpacks
Symlinks were not previous managed correctly when packing buildpacks using `jam`. This meant that for buildpacks that use the single-binary pattern for their executables, those buildpacks were packaging 3 binaries (`bin/build`, `bin/detect`, and `bin/run`). This lead to larger buildpack tarballs instead of smaller ones. This fix handles that symlinking correctly so that buildpacks can benefit from the reduced number of executables included in the tarball.
- Loading branch information
1 parent
9900e31
commit 7632cd4
Showing
11 changed files
with
116 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,13 @@ | ||
package cargo | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
) | ||
import "github.com/paketo-buildpacks/packit/fs" | ||
|
||
type DirectoryDuplicator struct{} | ||
|
||
func NewDirectoryDuplicator() DirectoryDuplicator { | ||
return DirectoryDuplicator{} | ||
} | ||
|
||
func (d DirectoryDuplicator) Duplicate(source, sink string) error { | ||
return filepath.Walk(source, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return fmt.Errorf("source dir does not exist: %s", err) | ||
} | ||
|
||
relPath, err := filepath.Rel(source, path) | ||
if err != nil { | ||
return fmt.Errorf("failed to get relative path: %s", err) | ||
} | ||
|
||
destPath := filepath.Join(sink, relPath) | ||
if info.IsDir() { | ||
err := os.MkdirAll(destPath, info.Mode()) | ||
if err != nil { | ||
return fmt.Errorf("duplicate error creating dir: %s", err) | ||
} | ||
} else if os.ModeType&info.Mode() == 0 { | ||
src, err := os.Open(path) | ||
if err != nil { | ||
return fmt.Errorf("opening source file failed: %s", err) | ||
} | ||
defer src.Close() | ||
|
||
srcInfo, err := src.Stat() | ||
if err != nil { | ||
return fmt.Errorf("unable to stat source file: %s", err) | ||
} | ||
|
||
dst, err := os.OpenFile(destPath, os.O_CREATE|os.O_TRUNC|os.O_RDWR, srcInfo.Mode()) | ||
if err != nil { | ||
return fmt.Errorf("duplicate error creating file: %s", err) | ||
} | ||
defer dst.Close() | ||
|
||
_, err = io.Copy(dst, src) | ||
if err != nil { | ||
return fmt.Errorf("copy dst to src failed: %s", err) | ||
} | ||
|
||
} | ||
return nil | ||
}) | ||
func (d DirectoryDuplicator) Duplicate(source, destination string) error { | ||
return fs.Copy(source, destination) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
./build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.