Centralize path-safe root joins and atomic file operations

This commit is contained in:
2026-05-23 15:45:31 +00:00
parent 98649f4d81
commit 094b0d2532
11 changed files with 466 additions and 189 deletions

View File

@@ -309,11 +309,7 @@ func deriveManifestRelativePath(previousManifest *manifest.Manifest, localPath s
if !ok {
return "", false
}
rel, err := filepath.Rel(sessionRoot, trimmed)
if err != nil {
return "", false
}
normalized, err := pathsafe.NormalizeRelativeDestination(filepath.ToSlash(rel))
normalized, err := pathsafe.SlashRelativeFromRoot(sessionRoot, trimmed)
if err != nil {
return "", false
}
@@ -375,11 +371,7 @@ func relativeToSession(paths artifacts.SessionPaths, localPath string) (string,
if strings.TrimSpace(root) == "" {
return "", fmt.Errorf("session root is required")
}
rel, err := filepath.Rel(root, filepath.Clean(localPath))
if err != nil {
return "", fmt.Errorf("resolve previous-cache relative path: %w", err)
}
normalized, err := pathsafe.NormalizeRelativeDestination(filepath.ToSlash(rel))
normalized, err := pathsafe.SlashRelativeFromRoot(root, localPath)
if err != nil {
return "", fmt.Errorf("resolve previous-cache relative path: %w", err)
}