Skip to content

Commit 2db1959

Browse files
author
Alan Clucas
committed
When localDir is relative cleanup doesn't work correctly
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.
1 parent d0a1ad8 commit 2db1959

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

pkg/recorder/recorder.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type logger interface {
2626
Errorf(format string, args ...interface{})
2727
}
2828

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

134134
func (w *Listener) relativePath(file string) string {
135-
root := filepath.Clean(w.localDir)
136-
return strings.Replace(file, root+"/", "", 1)
135+
root, err := filepath.Abs(w.localDir)
136+
if err != nil {
137+
// Fallback to something
138+
root = filepath.Clean(w.localDir)
139+
}
140+
return strings.Replace(file, filepath.Clean(root+"/"), "", 1)
137141
}
138142

139143
func (w *Listener) save(file string, data []byte) error {
@@ -185,9 +189,12 @@ func (w *Listener) save(file string, data []byte) error {
185189
func (w *Listener) deleteObsoleteFiles() {
186190
w.activesLock.RLock()
187191
defer w.activesLock.RUnlock()
188-
root := filepath.Clean(w.localDir)
192+
root, err := filepath.Abs(w.localDir)
193+
if err != nil {
194+
w.logger.Errorf("failed to absolute path to %s", w.localDir)
195+
}
189196

190-
err := afero.Walk(appFs, root, func(path string, info os.FileInfo, err error) error {
197+
err = afero.Walk(appFs, root, func(path string, info os.FileInfo, err error) error {
191198
if info == nil {
192199
return fmt.Errorf("can't stat %s", path)
193200
}

0 commit comments

Comments
 (0)