Skip to content

Commit

Permalink
When localDir is relative cleanup doesn't work correctly
Browse files Browse the repository at this point in the history
localDir defaults to a relative directory, and when it is then
recorder's system breaks down as part of it is relative and part
absolute, so it ends up deleting things it should be keeping in the
background gc cleanup.

This change makes everything work off the absolute paths.
  • Loading branch information
Alan Clucas committed Aug 25, 2020
1 parent d0a1ad8 commit 2db1959
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pkg/recorder/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type logger interface {
Errorf(format string, args ...interface{})
}

// activeFiles will contain a list of active (present in cluster) objets; we'll
// activeFiles will contain a list of active (present in cluster) objects; we'll
// use that to periodically find and garbage collect stale objets in the git repos
// (ie. if some objects were delete from cluster while katafygio was not running),
// and to skip already existing and unchanged files.
Expand Down Expand Up @@ -132,8 +132,12 @@ func (w *Listener) remove(file string) error {
}

func (w *Listener) relativePath(file string) string {
root := filepath.Clean(w.localDir)
return strings.Replace(file, root+"/", "", 1)
root, err := filepath.Abs(w.localDir)
if err != nil {
// Fallback to something
root = filepath.Clean(w.localDir)
}
return strings.Replace(file, filepath.Clean(root+"/"), "", 1)
}

func (w *Listener) save(file string, data []byte) error {
Expand Down Expand Up @@ -185,9 +189,12 @@ func (w *Listener) save(file string, data []byte) error {
func (w *Listener) deleteObsoleteFiles() {
w.activesLock.RLock()
defer w.activesLock.RUnlock()
root := filepath.Clean(w.localDir)
root, err := filepath.Abs(w.localDir)
if err != nil {
w.logger.Errorf("failed to absolute path to %s", w.localDir)
}

err := afero.Walk(appFs, root, func(path string, info os.FileInfo, err error) error {
err = afero.Walk(appFs, root, func(path string, info os.FileInfo, err error) error {
if info == nil {
return fmt.Errorf("can't stat %s", path)
}
Expand Down

0 comments on commit 2db1959

Please sign in to comment.