Skip to content

Commit

Permalink
fix: deb: do not create multiple entries for the same folder
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Feb 25, 2018
1 parent 4ece050 commit 1ae64d6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions deb/deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ func createDataTarGz(info nfpm.Info) (dataTarGz, md5sums []byte, instSize int64,
defer out.Close() // nolint: errcheck
defer compress.Close() // nolint: errcheck

var created = map[string]bool{}

var md5buf bytes.Buffer
for _, files := range []map[string]string{
info.Files,
info.ConfigFiles,
} {
for src, dst := range files {
if err := createTree(out, dst); err != nil {
if err := createTree(out, dst, created); err != nil {
return nil, nil, 0, err
}
size, err := copyToTarAndDigest(out, &md5buf, src, dst)
Expand All @@ -109,8 +111,13 @@ func createDataTarGz(info nfpm.Info) (dataTarGz, md5sums []byte, instSize int64,

// this is needed because the data.tar.gz file should have the empty folders
// as well, so we walk through the dst and create all subfolders.
func createTree(tarw *tar.Writer, dst string) error {
func createTree(tarw *tar.Writer, dst string, created map[string]bool) error {
for _, path := range pathsToCreate(dst) {
if created[path] {
// skipping dir that was previously created inside the archive
// (eg: usr/)
continue
}
if err := tarw.WriteHeader(&tar.Header{
Name: path + "/",
Mode: 0755,
Expand All @@ -120,6 +127,7 @@ func createTree(tarw *tar.Writer, dst string) error {
}); err != nil {
return errors.Wrap(err, "failed to create folder")
}
created[path] = true
}
return nil
}
Expand Down Expand Up @@ -155,6 +163,7 @@ func copyToTarAndDigest(tarw *tar.Writer, md5w io.Writer, src, dst string) (int6
return 0, err
}
if info.IsDir() {
// TODO: this should probably return an error
return 0, nil
}
var header = tar.Header{
Expand Down

0 comments on commit 1ae64d6

Please sign in to comment.