{backup,snapshort}: Improve behaviour

This commit improves the behaviour of 'backup' and 'snapshot' by
treating symbolic links properly, as well as writes proper reports.
This commit is contained in:
Tom Wiesing 2022-09-13 11:44:32 +02:00
parent 94263174cf
commit a4f91ae7cf
No known key found for this signature in database
7 changed files with 298 additions and 91 deletions

View file

@ -31,7 +31,7 @@ func Package(dst, src string, onCopy func(rel string, src string)) (count int64,
defer tarHandle.Close()
// and walk through it!
err = filepath.Walk(src, func(path string, info fs.FileInfo, err error) error {
err = filepath.WalkDir(src, func(path string, entry fs.DirEntry, err error) error {
if err != nil {
return err
}
@ -43,10 +43,17 @@ func Package(dst, src string, onCopy func(rel string, src string)) (count int64,
return err
}
// call the oncopy!
if onCopy != nil {
onCopy(relpath, path)
}
// read mode etc
info, err := entry.Info()
if err != nil {
return err
}
// create a file info header!
tInfo, err := tar.FileInfoHeader(info, relpath)
if err != nil {
@ -60,7 +67,7 @@ func Package(dst, src string, onCopy func(rel string, src string)) (count int64,
}
// a directory => no more writing required
if info.IsDir() {
if entry.IsDir() {
return nil
}