Permit safe cross-run output declarations
This commit is contained in:
@@ -148,13 +148,9 @@ func buildCommittedRestoreActions(
|
||||
if current == nil || current.Commit == nil {
|
||||
return nil, fmt.Errorf("committed remote current state is required")
|
||||
}
|
||||
runPrefix := artifacts.S3RunPrefix(current.SessionPrefix, current.RunID)
|
||||
if runPrefix == "" {
|
||||
return nil, fmt.Errorf("committed run prefix is required")
|
||||
}
|
||||
actions := make([]RestoreAction, 0, len(current.Commit.Artifacts))
|
||||
for _, artifact := range current.Commit.Artifacts {
|
||||
rel, include, err := restoreLocalRelativePathForCommittedArtifact(runPrefix, artifact, opts.IncludeAudio)
|
||||
rel, include, err := restoreLocalRelativePathForCommittedArtifact(current.SessionPrefix, artifact, opts.IncludeAudio)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("map committed object %q: %w", artifact.DestinationKey, err)
|
||||
}
|
||||
@@ -179,18 +175,18 @@ func buildCommittedRestoreActions(
|
||||
return actions, nil
|
||||
}
|
||||
|
||||
func restoreLocalRelativePathForCommittedArtifact(runPrefix string, artifact artifacts.RemoteArtifact, includeAudio bool) (string, bool, error) {
|
||||
func restoreLocalRelativePathForCommittedArtifact(sessionPrefix string, artifact artifacts.RemoteArtifact, includeAudio bool) (string, bool, error) {
|
||||
if artifact.Type == artifacts.RemoteArtifactTypeSessionManifest {
|
||||
return config.PathManifestFile, true, nil
|
||||
}
|
||||
if artifact.Type != artifacts.RemoteArtifactTypePublishedOutput {
|
||||
return "", false, nil
|
||||
}
|
||||
key := normalizeRemoteKey(artifact.DestinationKey)
|
||||
if !strings.HasPrefix(key, runPrefix) {
|
||||
return "", false, fmt.Errorf("object is outside committed run prefix %q", runPrefix)
|
||||
identity, err := artifacts.ParseImmutableRunObjectKey(sessionPrefix, artifact.DestinationKey)
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
rel := strings.TrimPrefix(key, runPrefix)
|
||||
rel := strings.TrimPrefix(identity.RelativePath, "published/")
|
||||
cleanRel, err := pathsafe.NormalizeRelativeDestination(rel)
|
||||
if err != nil {
|
||||
return "", false, fmt.Errorf("committed destination is unsafe: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user