Stream changed local audio into the workspace
This commit is contained in:
@@ -332,6 +332,9 @@ known-size bounds. Restore's old execution-manifest semantics remain unchanged.
|
|||||||
|
|
||||||
## Stage 9: Stream changed local audio copies
|
## Stage 9: Stream changed local audio copies
|
||||||
|
|
||||||
|
**Complete:** Changed inputs use the existing atomic streaming copy with its
|
||||||
|
installed-byte checksum; tests cover reuse, replacement, and failed installation.
|
||||||
|
|
||||||
Read `audit/02-efficiency.md`, lines 20–48 (EF-01), and preparation's
|
Read `audit/02-efficiency.md`, lines 20–48 (EF-01), and preparation's
|
||||||
`copyFileIfChanged`, artifact-store copy operations, and streaming fileops helpers.
|
`copyFileIfChanged`, artifact-store copy operations, and streaming fileops helpers.
|
||||||
|
|
||||||
|
|||||||
@@ -652,14 +652,7 @@ func copyFileIfChanged(store artifacts.Store, src, dst string) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := os.ReadFile(src)
|
return fileops.CopyFileAtomicWithChecksum(src, dst, fileops.WorkspaceFileMode)
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if err := store.WriteFileAtomic(dst, data, fileops.WorkspaceFileMode); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return srcChecksum, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeBytesIfChanged(store artifacts.Store, dst string, data []byte) (string, error) {
|
func writeBytesIfChanged(store artifacts.Store, dst string, data []byte) (string, error) {
|
||||||
|
|||||||
73
internal/stage/prepare_copy_test.go
Normal file
73
internal/stage/prepare_copy_test.go
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package stage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
|
)
|
||||||
|
|
||||||
|
type disappearingInputStore struct {
|
||||||
|
artifacts.Store
|
||||||
|
source string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s disappearingInputStore) Checksum(path string) (string, error) {
|
||||||
|
sum, err := s.Store.Checksum(path)
|
||||||
|
if path == s.source && err == nil {
|
||||||
|
err = os.Remove(path)
|
||||||
|
}
|
||||||
|
return sum, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCopyFileIfChangedStreamsAndPreservesDestination(t *testing.T) {
|
||||||
|
root := t.TempDir()
|
||||||
|
src, dst := filepath.Join(root, "source.flac"), filepath.Join(root, "prepared", "source.flac")
|
||||||
|
if err := os.WriteFile(src, []byte("first recording"), 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
store := artifacts.NewLocalStore(root)
|
||||||
|
first, err := copyFileIfChanged(store, src, dst)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
info, err := os.Stat(dst)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
second, err := copyFileIfChanged(store, src, dst)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
same, err := os.Stat(dst)
|
||||||
|
if err != nil || !os.SameFile(info, same) || first != second {
|
||||||
|
t.Fatalf("unchanged copy: %v", err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(src, []byte("changed recording"), 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
changed, err := copyFileIfChanged(store, src, dst)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
data, err := os.ReadFile(dst)
|
||||||
|
if err != nil || string(data) != "changed recording" {
|
||||||
|
t.Fatalf("destination=%q error=%v", data, err)
|
||||||
|
}
|
||||||
|
checksum, err := artifacts.SHA256File(dst)
|
||||||
|
if err != nil || checksum != changed || changed == first {
|
||||||
|
t.Fatalf("checksum=%q changed=%q error=%v", checksum, changed, err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(src, []byte("replacement"), 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
_, err = copyFileIfChanged(disappearingInputStore{Store: store, source: src}, src, dst)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected missing source during replacement")
|
||||||
|
}
|
||||||
|
data, err = os.ReadFile(dst)
|
||||||
|
if err != nil || string(data) != "changed recording" {
|
||||||
|
t.Fatalf("destination after failure=%q error=%v", data, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user