Confine local file installation paths

This commit is contained in:
2026-08-10 17:59:29 +00:00
parent 59f3fe3d1d
commit 18ddf00d3d
20 changed files with 694 additions and 153 deletions

View File

@@ -3,10 +3,11 @@ package stage
import (
"context"
"fmt"
"os"
"io"
"path/filepath"
"sort"
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
@@ -56,33 +57,9 @@ func hydratePreviousSessionArtifacts(
return nil, fmt.Errorf("create previous-session path directory for %q: %w", record.LocalPath, err)
}
base := filepath.Base(record.LocalPath)
tmp, err := os.CreateTemp(filepath.Dir(record.LocalPath), "."+base+".prepare-previous-*.tmp")
if err != nil {
return nil, fmt.Errorf("create previous-session temp file for %q: %w", record.LocalPath, err)
}
tmpPath := tmp.Name()
if err := tmp.Close(); err != nil {
_ = os.Remove(tmpPath)
return nil, fmt.Errorf("close previous-session temp file for %q: %w", record.LocalPath, err)
}
if err := func() error {
removeTmp := true
defer func() {
if removeTmp {
_ = os.Remove(tmpPath)
}
}()
if err := env.ObjectStore.Download(ctx, record.RemoteKey, tmpPath); err != nil {
return fmt.Errorf("download previous-session object %q to temp file: %w", record.RemoteKey, err)
}
if err := fileops.InstallDownloadedTempFile(tmpPath, record.LocalPath, fileops.WorkspaceFileMode); err != nil {
return fmt.Errorf("install previous-session object %q at %q: %w", record.RemoteKey, record.LocalPath, err)
}
removeTmp = false
return nil
}(); err != nil {
if err := fileops.DownloadAndInstall(record.LocalPath, fileops.WorkspaceFileMode, func(destination io.Writer) error {
return storage.DownloadTo(ctx, env.ObjectStore, record.RemoteKey, destination)
}); err != nil {
return nil, err
}
if record.Kind == preparePreviousInputKindArtifact {

View File

@@ -3,6 +3,7 @@ package stage
import (
"context"
"encoding/json"
"io"
"os"
"path/filepath"
"strings"
@@ -391,6 +392,11 @@ func (s *preparePreviousCaptureStore) Download(ctx context.Context, key, localPa
return s.delegate.Download(ctx, key, localPath)
}
func (s *preparePreviousCaptureStore) DownloadTo(ctx context.Context, key string, destination io.Writer) error {
s.downloadKeys = append(s.downloadKeys, key)
return storage.DownloadTo(ctx, s.delegate, key, destination)
}
func (s *preparePreviousCaptureStore) Upload(ctx context.Context, localPath, key string, opts storage.UploadOptions) (storage.ObjectInfo, error) {
return s.delegate.Upload(ctx, localPath, key, opts)
}