Merge branch 'development' into container-info2

This commit is contained in:
Christian Goll
2022-10-13 10:43:50 +02:00
73 changed files with 4237 additions and 420 deletions

View File

@@ -27,7 +27,7 @@ func CopyFile(src string, dst string) error {
return err
}
dstFD, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE, srcInfo.Mode())
dstFD, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, srcInfo.Mode())
if err != nil {
wwlog.Error("Could not create destination file %s: %s\n", dst, err)
return err

View File

@@ -260,34 +260,17 @@ func FindFilterFiles(
defer func() {
err = FirstError(err, os.Chdir(cwd))
}()
err = os.Chdir(path)
if err != nil {
return ofiles, errors.Wrapf(err, "Failed to change path: %s", path)
}
files := []string{}
for _, pattern := range include {
_files, err := filepath.Glob(pattern)
if err != nil {
return ofiles, errors.Wrapf(err, "Failed to apply pattern: %s", pattern)
}
wwlog.Debug("Including pattern: %s -> %d matches", pattern, len(_files))
files = append(files, _files...)
}
for i, pattern := range(ignore) {
if strings.HasPrefix(pattern, "./") {
ignore[i] = pattern[2:]
}
for i := range(ignore) {
ignore[i] = strings.TrimLeft(ignore[i], "/")
ignore[i] = strings.TrimPrefix(ignore[i], "./")
wwlog.Debug("Ignore pattern (%d): %s", i, ignore[i])
}
if ignore_xdev {
wwlog.Debug("Ignoring cross-device (xdev) files")
}
@@ -299,66 +282,72 @@ func FindFilterFiles(
dev := path_stat.Sys().(*syscall.Stat_t).Dev
for _, ifile := range files {
stat, err := os.Stat(ifile)
includeDirs := []string{}
ignoreDirs := []string{}
err = filepath.Walk(".", func(location string, info os.FileInfo, err error) error {
if err != nil {
return ofiles, err
return err
}
if stat.IsDir() {
// recursivly include from the matched directory
if location == "." {
return nil
}
num_init := len(ofiles)
err = filepath.Walk(ifile, func(location string, info os.FileInfo, err error) error {
var file string
var file string
if info.IsDir() {
file = location + "/"
} else {
file = location
}
if err != nil {
return err
}
if location == "." {
return nil
}
if info.IsDir() {
file = location + "/"
} else {
file = location
}
if ignore_xdev && info.Sys().(*syscall.Stat_t).Dev != dev {
wwlog.Debug("Ignored (cross-device): %s", file)
return nil
}
for i, pattern := range(ignore) {
m, err := filepath.Match(pattern, location)
if err != nil {
return err
}
if m {
wwlog.Debug("Ignored (%d): %s", i, file)
return nil
}
}
ofiles = append(ofiles, file)
if ignore_xdev && info.Sys().(*syscall.Stat_t).Dev != dev {
wwlog.Debug("Ignored (cross-device): %s", file)
return nil
}
for _, ignoreDir := range(ignoreDirs) {
if strings.HasPrefix(location, ignoreDir) {
wwlog.Debug("Ignored (dir): %s", file)
return nil
})
num_final := len(ofiles)
wwlog.Debug("Included: %s -> %d files", ifile, num_final-num_init)
if err != nil {
return ofiles, err
}
}else{
wwlog.Debug("Included: %s", ifile)
ofiles = append(ofiles, ifile)
}
}
for i, pattern := range(ignore) {
m, err := filepath.Match(pattern, location)
if err != nil {
return err
} else if m {
wwlog.Debug("Ignored (%d): %s", i, file)
if info.IsDir() {
ignoreDirs = append(ignoreDirs, file)
}
return nil
}
}
for _, includeDir := range(includeDirs) {
if strings.HasPrefix(location, includeDir) {
wwlog.Debug("Included (dir): %s", file)
ofiles = append(ofiles, location)
return nil
}
}
for i, pattern := range(include) {
m, err := filepath.Match(pattern, location)
if err != nil {
return err
} else if m {
wwlog.Debug("Included (%d): %s", i, file)
ofiles = append(ofiles, location)
if info.IsDir() {
includeDirs = append(includeDirs, file)
}
return nil
}
}
return nil
})
return ofiles, err
}