From b1e43e1a852f56969c0c5f039723f1303be93e54 Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Wed, 10 Apr 2024 12:03:01 +0200 Subject: [PATCH 1/4] Less noisy content clean --- pkg/content/content.go | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/pkg/content/content.go b/pkg/content/content.go index 344fb59e..f192c738 100644 --- a/pkg/content/content.go +++ b/pkg/content/content.go @@ -76,6 +76,10 @@ func (c Manager) AfterPullFile(path string) error { } func (c Manager) CleanDir(root string) error { + if !pathx.Exists(root) { + return fmt.Errorf("cannot clean directory as it does not exist: %s", root) + } + log.Infof("cleaning directory %s", root) if err := c.cleanDotContents(root); err != nil { return err } @@ -88,13 +92,15 @@ func (c Manager) CleanDir(root string) error { if err := deleteEmptyDirs(root); err != nil { return err } + log.Infof("cleaned %s directory", root) return nil } func (c Manager) CleanFile(path string) error { if !pathx.Exists(path) { - return fmt.Errorf("file does not exist: %s", path) + return fmt.Errorf("cannot clean file as it does not exist: %s", path) } + log.Infof("cleaning file %s", path) if err := c.cleanDotContentFile(path); err != nil { return err } @@ -104,6 +110,7 @@ func (c Manager) CleanFile(path string) error { if err := deleteEmptyDirs(filepath.Dir(path)); err != nil { return err } + log.Infof("cleaned %s file", path) return nil } @@ -142,7 +149,7 @@ func (c Manager) cleanDotContentFile(path string) error { return nil } - log.Infof("cleaning file %s", path) + log.Debugf("cleaning dot content file %s", path) inputLines, err := readLines(path) if err != nil { return err @@ -241,9 +248,9 @@ func (c Manager) flattenFile(path string) error { dest := filepath.Dir(path) + ".xml" if pathx.Exists(dest) { - log.Infof("flattening file (override): %s", path) + log.Debugf("flattening file (override): %s", path) } else { - log.Infof("flattening file: %s", path) + log.Debugf("flattening file: %s", path) } return os.Rename(path, dest) } @@ -272,7 +279,7 @@ func deleteDir(dir string) error { if !pathx.Exists(dir) { return nil } - log.Infof("deleting dir %s", dir) + log.Debugf("deleting dir %s", dir) return os.RemoveAll(dir) } @@ -280,7 +287,7 @@ func deleteFile(path string, allowedFunc func() bool) error { if !pathx.Exists(path) || allowedFunc != nil && !allowedFunc() { return nil } - log.Infof("deleting file %s", path) + log.Debugf("deleting file %s", path) return os.Remove(path) } @@ -301,11 +308,10 @@ func deleteEmptyDirs(root string) error { return err } if len(entries) == 0 { + log.Debugf("deleting empty directory %s", root) if err = os.Remove(root); err != nil { return err } - log.Infof("deleting empty directory %s", root) - } return nil } @@ -314,7 +320,8 @@ func (c Manager) doParentsBackup(root string) error { return eachParentFiles(root, func(parent string) error { return eachFilesInDir(parent, func(path string) error { if !strings.HasSuffix(path, ParentsBackupSuffix) { - if err := c.backupFile(path, "doing backup of parent file: %s"); err != nil { + log.Debugf("doing backup of parent file: %s", path) + if err := c.backupFile(path); err != nil { return err } } @@ -327,7 +334,8 @@ func (c Manager) doSiblingsBackup(file string) error { dir := filepath.Dir(file) return eachFilesInDir(dir, func(path string) error { if path != file && !strings.HasSuffix(path, ParentsBackupSuffix) { - if err := c.backupFile(path, "doing backup of file: %s"); err != nil { + log.Debugf("doing backup of file: %s", path) + if err := c.backupFile(path); err != nil { return err } } @@ -359,7 +367,7 @@ func (c Manager) undoParentsBackup(root string) error { return eachFilesInDir(parent, func(path string) error { if strings.HasSuffix(path, ParentsBackupSuffix) { origin := strings.TrimSuffix(path, ParentsBackupSuffix) - log.Infof("undoing backup of parent file: %s", path) + log.Debugf("undoing backup of parent file: %s", path) return os.Rename(path, origin) } return nil @@ -372,7 +380,7 @@ func (c Manager) undoSiblingBackup(path string) error { return eachFilesInDir(dir, func(path string) error { if strings.HasSuffix(path, ParentsBackupSuffix) { origin := strings.TrimSuffix(path, ParentsBackupSuffix) - log.Infof("undoing backup of file: %s", path) + log.Debugf("undoing backup of file: %s", path) return os.Rename(path, origin) } else if strings.HasSuffix(path, ParentsBackupDirIndicator) { return deleteFile(path, nil) @@ -433,7 +441,7 @@ func writeLines(path string, lines []string) error { return err } -func (c Manager) backupFile(path string, format string) error { +func (c Manager) backupFile(path string) error { dir := filepath.Dir(path) indicator, err := os.Create(filepath.Join(dir, ParentsBackupDirIndicator)) if err != nil { @@ -457,7 +465,6 @@ func (c Manager) backupFile(path string, format string) error { if err != nil { return err } - log.Infof(format, path) return nil } From b93f36c178a896a775ad173a7f1371927723ec42 Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Wed, 10 Apr 2024 12:11:02 +0200 Subject: [PATCH 2/4] Minors --- pkg/content/content.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/content/content.go b/pkg/content/content.go index f192c738..55f39b83 100644 --- a/pkg/content/content.go +++ b/pkg/content/content.go @@ -77,9 +77,9 @@ func (c Manager) AfterPullFile(path string) error { func (c Manager) CleanDir(root string) error { if !pathx.Exists(root) { - return fmt.Errorf("cannot clean directory as it does not exist: %s", root) + return fmt.Errorf("cannot clean directory as it does not exist '%s'", root) } - log.Infof("cleaning directory %s", root) + log.Infof("cleaning directory '%s'", root) if err := c.cleanDotContents(root); err != nil { return err } @@ -92,7 +92,7 @@ func (c Manager) CleanDir(root string) error { if err := deleteEmptyDirs(root); err != nil { return err } - log.Infof("cleaned %s directory", root) + log.Infof("cleaned directory '%s'", root) return nil } @@ -100,7 +100,7 @@ func (c Manager) CleanFile(path string) error { if !pathx.Exists(path) { return fmt.Errorf("cannot clean file as it does not exist: %s", path) } - log.Infof("cleaning file %s", path) + log.Infof("cleaning file '%s'", path) if err := c.cleanDotContentFile(path); err != nil { return err } @@ -110,7 +110,7 @@ func (c Manager) CleanFile(path string) error { if err := deleteEmptyDirs(filepath.Dir(path)); err != nil { return err } - log.Infof("cleaned %s file", path) + log.Infof("cleaned file '%s'", path) return nil } @@ -149,7 +149,7 @@ func (c Manager) cleanDotContentFile(path string) error { return nil } - log.Debugf("cleaning dot content file %s", path) + log.Infof("cleaning dot content file '%s'", path) inputLines, err := readLines(path) if err != nil { return err @@ -248,9 +248,9 @@ func (c Manager) flattenFile(path string) error { dest := filepath.Dir(path) + ".xml" if pathx.Exists(dest) { - log.Debugf("flattening file (override): %s", path) + log.Infof("flattening file (override) '%s'", path) } else { - log.Debugf("flattening file: %s", path) + log.Infof("flattening file '%s'", path) } return os.Rename(path, dest) } @@ -279,7 +279,7 @@ func deleteDir(dir string) error { if !pathx.Exists(dir) { return nil } - log.Debugf("deleting dir %s", dir) + log.Infof("deleting dir '%s'", dir) return os.RemoveAll(dir) } @@ -287,7 +287,7 @@ func deleteFile(path string, allowedFunc func() bool) error { if !pathx.Exists(path) || allowedFunc != nil && !allowedFunc() { return nil } - log.Debugf("deleting file %s", path) + log.Infof("deleting file '%s'", path) return os.Remove(path) } @@ -308,7 +308,7 @@ func deleteEmptyDirs(root string) error { return err } if len(entries) == 0 { - log.Debugf("deleting empty directory %s", root) + log.Infof("deleting empty directory '%s'", root) if err = os.Remove(root); err != nil { return err } @@ -320,7 +320,7 @@ func (c Manager) doParentsBackup(root string) error { return eachParentFiles(root, func(parent string) error { return eachFilesInDir(parent, func(path string) error { if !strings.HasSuffix(path, ParentsBackupSuffix) { - log.Debugf("doing backup of parent file: %s", path) + log.Infof("doing backup of parent file '%s'", path) if err := c.backupFile(path); err != nil { return err } @@ -334,7 +334,7 @@ func (c Manager) doSiblingsBackup(file string) error { dir := filepath.Dir(file) return eachFilesInDir(dir, func(path string) error { if path != file && !strings.HasSuffix(path, ParentsBackupSuffix) { - log.Debugf("doing backup of file: %s", path) + log.Infof("doing backup of file '%s'", path) if err := c.backupFile(path); err != nil { return err } @@ -367,7 +367,7 @@ func (c Manager) undoParentsBackup(root string) error { return eachFilesInDir(parent, func(path string) error { if strings.HasSuffix(path, ParentsBackupSuffix) { origin := strings.TrimSuffix(path, ParentsBackupSuffix) - log.Debugf("undoing backup of parent file: %s", path) + log.Infof("undoing backup of parent file '%s'", path) return os.Rename(path, origin) } return nil @@ -380,7 +380,7 @@ func (c Manager) undoSiblingBackup(path string) error { return eachFilesInDir(dir, func(path string) error { if strings.HasSuffix(path, ParentsBackupSuffix) { origin := strings.TrimSuffix(path, ParentsBackupSuffix) - log.Debugf("undoing backup of file: %s", path) + log.Infof("undoing backup of file '%s'", path) return os.Rename(path, origin) } else if strings.HasSuffix(path, ParentsBackupDirIndicator) { return deleteFile(path, nil) From 59fc25cc0759a9ef3fabe5a434887e811b8fb24e Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Wed, 10 Apr 2024 12:11:50 +0200 Subject: [PATCH 3/4] Minors --- pkg/content/content.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/content/content.go b/pkg/content/content.go index 55f39b83..ff499a50 100644 --- a/pkg/content/content.go +++ b/pkg/content/content.go @@ -98,7 +98,7 @@ func (c Manager) CleanDir(root string) error { func (c Manager) CleanFile(path string) error { if !pathx.Exists(path) { - return fmt.Errorf("cannot clean file as it does not exist: %s", path) + return fmt.Errorf("cannot clean file as it does not exist '%s'", path) } log.Infof("cleaning file '%s'", path) if err := c.cleanDotContentFile(path); err != nil { From 8dddfaac6d5245aded9ca7e9387d2fd9ca7d509c Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Wed, 10 Apr 2024 12:12:57 +0200 Subject: [PATCH 4/4] Minors --- pkg/content/content.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/content/content.go b/pkg/content/content.go index ff499a50..47bea09e 100644 --- a/pkg/content/content.go +++ b/pkg/content/content.go @@ -367,7 +367,7 @@ func (c Manager) undoParentsBackup(root string) error { return eachFilesInDir(parent, func(path string) error { if strings.HasSuffix(path, ParentsBackupSuffix) { origin := strings.TrimSuffix(path, ParentsBackupSuffix) - log.Infof("undoing backup of parent file '%s'", path) + log.Infof("undoing backup of parent file '%s'", path) return os.Rename(path, origin) } return nil