mirror of
https://github.com/mudler/luet.git
synced 2025-07-14 23:54:30 +00:00
Fixup config protect
This commit is contained in:
parent
6ff22d923c
commit
52ad2b5cfa
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user