Move document_records duty-slot writes into docgov, project ledger heads through docgov/freedoc ports, and workspace deliverable I/O through DeliverableStore so arch-check baseline drops to sql_write:1 path:13.
38 lines
946 B
Go
38 lines
946 B
Go
package workspace
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// DirDeliverable reads and writes the canonical deliverable under an absolute work dir.
|
|
// It is the path owner for DeliverableKey; callers must not embed the literal themselves.
|
|
type DirDeliverable struct{}
|
|
|
|
func (DirDeliverable) Read(absWorkDir string) ([]byte, error) {
|
|
if absWorkDir == "" {
|
|
return nil, fmt.Errorf("workspace: empty work dir")
|
|
}
|
|
return os.ReadFile(filepath.Join(absWorkDir, DeliverableKey))
|
|
}
|
|
|
|
func (DirDeliverable) Write(absWorkDir string, body []byte) error {
|
|
if absWorkDir == "" {
|
|
return fmt.Errorf("workspace: empty work dir")
|
|
}
|
|
path := filepath.Join(absWorkDir, DeliverableKey)
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
|
return err
|
|
}
|
|
tmp := path + ".tmp"
|
|
if err := os.WriteFile(tmp, body, 0o644); err != nil {
|
|
return err
|
|
}
|
|
if err := os.Rename(tmp, path); err != nil {
|
|
_ = os.Remove(tmp)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|