tarModifierWrapperFunc: Fix config protect filename

This commit is contained in:
Daniele Rondina
2020-06-05 23:12:19 +02:00
parent 8f0c528c08
commit 16f717f04b

View File

@@ -291,6 +291,9 @@ func tarModifierWrapperFunc(dst, path string, header *tar.Header, content io.Rea
} }
} }
// If file is not present on archive but is defined on mods
// I receive the callback. Prevent nil exception.
if header != nil {
switch header.Typeflag { switch header.Typeflag {
case tar.TypeReg: case tar.TypeReg:
destPath = filepath.Join(dst, path) destPath = filepath.Join(dst, path)
@@ -302,11 +305,17 @@ func tarModifierWrapperFunc(dst, path string, header *tar.Header, content io.Rea
// Check if exists // Check if exists
if helpers.Exists(destPath) { if helpers.Exists(destPath) {
for i := 1; i < 1000; i++ { for i := 1; i < 1000; i++ {
name := filepath.Join(dst, filepath.Join(filepath.Dir(path), fmt.Sprintf("_cfg%04d_%s", i, filepath.Base(path)))) name := filepath.Join(dst, filepath.Join(filepath.Dir(path), fmt.Sprintf("._cfg%04d_%s", i, filepath.Base(path))))
if helpers.Exists(name) { if helpers.Exists(name) {
continue continue
} }
return &tar.Header{Mode: header.Mode, Typeflag: header.Typeflag, Name: name}, buffer.Bytes(), nil return &tar.Header{
Mode: header.Mode,
Typeflag: header.Typeflag,
PAXRecords: header.PAXRecords,
Name: name,
}, buffer.Bytes(), nil
}
} }
} }