Record the downloaded audio object generation
This commit is contained in:
@@ -29,6 +29,7 @@ type S3MaterializeResult struct {
|
||||
Checksum string
|
||||
Reused bool
|
||||
Downloaded bool
|
||||
Object storage.ObjectInfo
|
||||
}
|
||||
|
||||
// MaterializeS3Audio verifies the recorded prepared copy or installs a fresh download.
|
||||
@@ -61,18 +62,19 @@ func MaterializeS3Audio(ctx context.Context, req S3MaterializeRequest) (S3Materi
|
||||
if req.Reporter != nil {
|
||||
req.Reporter.Progress("reusing prepared audio", "audio", filepath.Base(req.DestPath))
|
||||
}
|
||||
return S3MaterializeResult{Checksum: checksum, Reused: true}, nil
|
||||
return S3MaterializeResult{Checksum: checksum, Reused: true, Object: req.Object}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := downloadObjectAtomic(ctx, req.Store, key, req.DestPath, req.Object.Size, req.Reporter); err != nil {
|
||||
observed, err := downloadObjectAtomic(ctx, req.Store, key, req.DestPath, req.Reporter)
|
||||
if err != nil {
|
||||
return S3MaterializeResult{}, fmt.Errorf("download s3 audio object %q: %w", key, err)
|
||||
}
|
||||
checksum, err := artifacts.SHA256File(req.DestPath)
|
||||
if err != nil {
|
||||
return S3MaterializeResult{}, fmt.Errorf("checksum downloaded audio: %w", err)
|
||||
}
|
||||
return S3MaterializeResult{Checksum: checksum, Downloaded: true}, nil
|
||||
return S3MaterializeResult{Checksum: checksum, Downloaded: true, Object: observed}, nil
|
||||
}
|
||||
|
||||
func validateLocalAudio(path string, expectedSize int64) error {
|
||||
@@ -92,30 +94,33 @@ func validateLocalAudio(path string, expectedSize int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func downloadObjectAtomic(ctx context.Context, store storage.ObjectStore, key, destPath string, expectedSize int64, reporter logging.Reporter) error {
|
||||
func downloadObjectAtomic(ctx context.Context, store storage.ObjectStore, key, destPath string, reporter logging.Reporter) (storage.ObjectInfo, error) {
|
||||
var observed storage.ObjectInfo
|
||||
temporaryPath, err := writeAudioTemp(destPath, func(destination io.Writer) error {
|
||||
if reporter != nil {
|
||||
reporter.Progress("downloading audio", "audio", filepath.Base(destPath))
|
||||
}
|
||||
return storage.DownloadTo(ctx, store, key, destination)
|
||||
var streamErr error
|
||||
observed, streamErr = storage.StreamObject(ctx, store, key, destination, nil)
|
||||
return streamErr
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
return observed, err
|
||||
}
|
||||
defer func() { _ = os.Remove(temporaryPath) }()
|
||||
if err := validateLocalAudio(temporaryPath, expectedSize); err != nil {
|
||||
return fmt.Errorf("validate downloaded audio: %w", err)
|
||||
if err := validateLocalAudio(temporaryPath, observed.Size); err != nil {
|
||||
return observed, fmt.Errorf("validate downloaded audio: %w", err)
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
return observed, err
|
||||
}
|
||||
if err := fileops.InstallSiblingTempFile(temporaryPath, destPath, fileops.WorkspaceFileMode); err != nil {
|
||||
return err
|
||||
return observed, err
|
||||
}
|
||||
if reporter != nil {
|
||||
reporter.Progress("audio downloaded", "audio", filepath.Base(destPath))
|
||||
}
|
||||
return nil
|
||||
return observed, nil
|
||||
}
|
||||
|
||||
func writeAudioTemp(destination string, write func(io.Writer) error) (string, error) {
|
||||
|
||||
Reference in New Issue
Block a user