Skip to content

Commit 41d1b6a

Browse files
committed
Fix versionedHomesToKeep handling in watcher cleanup
1 parent 18c8b79 commit 41d1b6a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

internal/pkg/agent/application/upgrade/rollback.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,15 @@ func cleanup(log *logger.Logger, topDirPath string, removeMarker, keepLogs bool,
177177
log.Infof("versioned homes to keep: %v", versionedHomesToKeep)
178178

179179
var cumulativeError error
180-
relativeHomePaths := make([]string, len(versionedHomesToKeep))
181-
for i, h := range versionedHomesToKeep {
180+
relativeHomePaths := make([]string, 0, len(versionedHomesToKeep))
181+
for _, h := range versionedHomesToKeep {
182182
relHomePath, err := filepath.Rel(dataDirPath, filepath.Join(topDirPath, h))
183183
if err != nil {
184184
cumulativeError = goerrors.Join(cumulativeError, fmt.Errorf("extracting elastic-agent path relative to data directory from %s: %w", h, err))
185-
continue
185+
// best effort: try to use the entry as-is, without calculating the path relative to `data`
186+
relHomePath = h
186187
}
187-
relativeHomePaths[i] = relHomePath
188+
relativeHomePaths = append(relativeHomePaths, relHomePath)
188189
}
189190

190191
log.Infof("Starting cleanup of versioned homes. Keeping: %v", relativeHomePaths)

0 commit comments

Comments
 (0)