diff --git a/pkg/api/core/config/config_protect.go b/pkg/api/core/config/config_protect.go index 008658c0..30f09909 100644 --- a/pkg/api/core/config/config_protect.go +++ b/pkg/api/core/config/config_protect.go @@ -53,7 +53,7 @@ func NewConfigProtect(annotationDir string) *ConfigProtect { } return &ConfigProtect{ AnnotationDir: annotationDir, - MapProtected: make(map[string]bool, 0), + MapProtected: make(map[string]bool), } } @@ -97,7 +97,7 @@ func (c *ConfigProtect) Protected(file string) bool { func (c *ConfigProtect) GetProtectFiles(withSlash bool) []string { ans := []string{} - for key, _ := range c.MapProtected { + for key := range c.MapProtected { if withSlash { ans = append(ans, key) } else { diff --git a/pkg/api/core/image/extract.go b/pkg/api/core/image/extract.go index 31d99f28..843d698b 100644 --- a/pkg/api/core/image/extract.go +++ b/pkg/api/core/image/extract.go @@ -47,16 +47,21 @@ func ExtractDeltaFiles( excludeRegexp := compileRegexes(excludes) return func(h *tar.Header) (bool, error) { + fileName := filepath.Join(string(os.PathSeparator), h.Name) + ctx.Debug("Includes", includes) + ctx.Debug("Excludes", excludes) + ctx.Debug("Additions", d.Additions) switch { case len(includes) == 0 && len(excludes) != 0: for _, a := range d.Additions { if h.Name == a.Name { for _, i := range excludeRegexp { - if i.MatchString(a.Name) && h.Name == a.Name { + if i.MatchString(filepath.Join(string(os.PathSeparator), a.Name)) && + fileName == filepath.Join(string(os.PathSeparator), a.Name) { return false, nil } } - ctx.Debug("Adding name", h.Name) + ctx.Debug("Adding name", fileName) return true, nil } @@ -65,8 +70,8 @@ func ExtractDeltaFiles( case len(includes) > 0 && len(excludes) == 0: for _, a := range d.Additions { for _, i := range includeRegexp { - if i.MatchString(a.Name) && h.Name == a.Name { - ctx.Debug("Adding name", h.Name) + if i.MatchString(filepath.Join(string(os.PathSeparator), a.Name)) && fileName == filepath.Join(string(os.PathSeparator), a.Name) { + ctx.Debug("Adding name", fileName) return true, nil } @@ -76,13 +81,13 @@ func ExtractDeltaFiles( case len(includes) != 0 && len(excludes) != 0: for _, a := range d.Additions { for _, i := range includeRegexp { - if i.MatchString(a.Name) && h.Name == a.Name { + if i.MatchString(filepath.Join(string(os.PathSeparator), a.Name)) && fileName == filepath.Join(string(os.PathSeparator), a.Name) { for _, e := range excludeRegexp { - if e.MatchString(a.Name) { + if e.MatchString(fileName) { return false, nil } } - ctx.Debug("Adding name", h.Name) + ctx.Debug("Adding name", fileName) return true, nil } @@ -91,8 +96,8 @@ func ExtractDeltaFiles( return false, nil default: for _, a := range d.Additions { - if h.Name == a.Name { - ctx.Debug("Adding name", h.Name) + if fileName == filepath.Join(string(os.PathSeparator), a.Name) { + ctx.Debug("Adding name", fileName) return true, nil } diff --git a/pkg/api/core/types/artifact/artifact.go b/pkg/api/core/types/artifact/artifact.go index b2190c5a..c57522d5 100644 --- a/pkg/api/core/types/artifact/artifact.go +++ b/pkg/api/core/types/artifact/artifact.go @@ -419,7 +419,7 @@ func replaceFileTarWrapper(dst string, inputTarStream io.ReadCloser, mods []stri } return nil } - var remaining []string + // var remaining []string var err error var originalHeader *tar.Header for { @@ -432,7 +432,7 @@ func replaceFileTarWrapper(dst string, inputTarStream io.ReadCloser, mods []stri return } - if helpers.Contains(mods, originalHeader.Name) { + if !helpers.Contains(mods, originalHeader.Name) { // No modifiers for this file, copy the header and data if err := tarWriter.WriteHeader(originalHeader); err != nil { pipeWriter.CloseWithError(err) @@ -442,7 +442,6 @@ func replaceFileTarWrapper(dst string, inputTarStream io.ReadCloser, mods []stri pipeWriter.CloseWithError(err) return } - remaining = append(remaining, originalHeader.Name) continue } @@ -453,12 +452,6 @@ func replaceFileTarWrapper(dst string, inputTarStream io.ReadCloser, mods []stri } // Apply the modifiers that haven't matched any files in the archive - for _, name := range remaining { - if err := modify(name, nil, nil); err != nil { - pipeWriter.CloseWithError(err) - return - } - } pipeWriter.Close() @@ -501,11 +494,15 @@ func tarModifierWrapperFunc(ctx *types.Context) func(dst, path string, header *t } } - ctx.Debug("Existing file hash: ", existingHash, "Tar file hashsum: ", tarHash) + ctx.Debug(destPath, "- existing file hash: ", existingHash, "Tar file hashsum: ", tarHash) + if fileHelper.Exists(destPath) { + ctx.Debug(destPath, "already exists") + } // We want to protect file only if the hash of the files are differing OR the file size are differs := (existingHash != "" && existingHash != tarHash) || (err != nil && f != nil && header.Size != f.Size()) // Check if exists if fileHelper.Exists(destPath) && differs { + ctx.Debug(destPath, "already exists and differs") for i := 1; i < 1000; i++ { name := filepath.Join(filepath.Join(filepath.Dir(path), fmt.Sprintf("._cfg%04d_%s", i, filepath.Base(path)))) @@ -577,10 +574,8 @@ func (a *PackageArtifact) Unpack(ctx *types.Context, dst string, keepPerms bool) if err != nil { return errors.Wrap(err, "Cannot open "+a.Path) } - defer decompressed.Close() replacerArchive := replaceFileTarWrapper(dst, decompressed, protectedFiles, mod) - defer replacerArchive.Close() // or with filter? // func(header *tar.Header) (bool, error) { diff --git a/pkg/installer/repository.go b/pkg/installer/repository.go index 45565764..8e00177b 100644 --- a/pkg/installer/repository.go +++ b/pkg/installer/repository.go @@ -812,6 +812,10 @@ func (r *LuetSystemRepository) SyncBuildMetadata(ctx *types.Context, path string defer os.RemoveAll(a.Path) + if !fileHelper.Exists(filepath.Join(path, "tree")) { + os.MkdirAll(filepath.Join(path, "tree"), 0600) + } + if err := a.Unpack(ctx, filepath.Join(path, "tree"), false); err != nil { return errors.Wrapf(err, "while unpacking: %s", REPOFILE_COMPILER_TREE_KEY) }