Complete filesystem simplification workstream
This commit is contained in:
@@ -12,13 +12,9 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ErrDirectorySyncUnsupported is used only by the retained directory-promotion
|
||||
// implementation. Single-file replacement does not perform directory syncing.
|
||||
var ErrDirectorySyncUnsupported = errors.New("directory sync is unsupported")
|
||||
|
||||
// ReplaceFileOptions describes the caller-owned parts of a byte-file
|
||||
// replacement. The destination parent must already exist. BeforeRename runs
|
||||
// after the temporary file is complete and durable, but before replacement is
|
||||
// after the temporary file is complete, but before replacement is
|
||||
// committed; callers can use it for cancellation or other commit checks.
|
||||
type ReplaceFileOptions struct {
|
||||
Mode os.FileMode
|
||||
@@ -32,7 +28,7 @@ func ReplaceFileAtomic(dst string, data []byte, options ReplaceFileOptions) erro
|
||||
}
|
||||
|
||||
// WriteFileAtomic creates the destination parent with workspace permissions
|
||||
// and durably replaces dst with data. Callers that own parent-directory policy
|
||||
// and atomically replaces dst with data. Callers that own parent-directory policy
|
||||
// or need a pre-commit check should use ReplaceFileAtomic directly.
|
||||
func WriteFileAtomic(dst string, data []byte, perm os.FileMode) error {
|
||||
if strings.TrimSpace(dst) == "" {
|
||||
@@ -44,13 +40,13 @@ func WriteFileAtomic(dst string, data []byte, perm os.FileMode) error {
|
||||
return ReplaceFileAtomic(dst, data, ReplaceFileOptions{Mode: perm})
|
||||
}
|
||||
|
||||
// CopyFileAtomic copies src to dst through the durable replacement sequence.
|
||||
// CopyFileAtomic copies src to dst through the replacement sequence.
|
||||
func CopyFileAtomic(src, dst string, perm os.FileMode) error {
|
||||
_, err := CopyFileAtomicWithChecksum(src, dst, perm)
|
||||
return err
|
||||
}
|
||||
|
||||
// CopyFileAtomicWithChecksum copies src to dst through the durable replacement
|
||||
// CopyFileAtomicWithChecksum copies src to dst through the replacement
|
||||
// sequence and returns the SHA-256 checksum of the copied bytes.
|
||||
func CopyFileAtomicWithChecksum(src, dst string, perm os.FileMode) (string, error) {
|
||||
if strings.TrimSpace(src) == "" || strings.TrimSpace(dst) == "" {
|
||||
@@ -66,7 +62,7 @@ func CopyFileAtomicWithChecksum(src, dst string, perm os.FileMode) (string, erro
|
||||
return WriteReaderAtomicWithChecksum(dst, in, perm)
|
||||
}
|
||||
|
||||
// WriteReaderAtomicWithChecksum streams src through the durable replacement
|
||||
// WriteReaderAtomicWithChecksum streams src through the replacement
|
||||
// sequence and returns the SHA-256 checksum of the installed bytes. The caller
|
||||
// retains ownership of src.
|
||||
func WriteReaderAtomicWithChecksum(dst string, src io.Reader, perm os.FileMode) (string, error) {
|
||||
|
||||
@@ -103,7 +103,7 @@ func TestAssetBuilderBuildsNamedAssetsAndChecksEmbeddedVersion(t *testing.T) {
|
||||
outputDir := filepath.Join(t.TempDir(), "assets")
|
||||
goLog := filepath.Join(t.TempDir(), "go.log")
|
||||
|
||||
command := exec.Command("sh", builder, "v1.2.3", outputDir)
|
||||
command := exec.Command("sh", builder, "v0.0.0-test", outputDir)
|
||||
command.Dir = t.TempDir()
|
||||
command.Env = append(os.Environ(),
|
||||
"PATH="+binDir+string(os.PathListSeparator)+os.Getenv("PATH"),
|
||||
@@ -124,23 +124,23 @@ func TestAssetBuilderBuildsNamedAssetsAndChecksEmbeddedVersion(t *testing.T) {
|
||||
}
|
||||
sort.Strings(got)
|
||||
want := []string{
|
||||
"narratio-v1.2.3-darwin-amd64",
|
||||
"narratio-v1.2.3-darwin-arm64",
|
||||
"narratio-v1.2.3-linux-amd64",
|
||||
"narratio-v1.2.3-linux-arm64",
|
||||
"narratio-v1.2.3-windows-amd64.exe",
|
||||
"narratio-v1.2.3-windows-arm64.exe",
|
||||
"narratio-v0.0.0-test-darwin-amd64",
|
||||
"narratio-v0.0.0-test-darwin-arm64",
|
||||
"narratio-v0.0.0-test-linux-amd64",
|
||||
"narratio-v0.0.0-test-linux-arm64",
|
||||
"narratio-v0.0.0-test-windows-amd64.exe",
|
||||
"narratio-v0.0.0-test-windows-arm64.exe",
|
||||
}
|
||||
if !slicesEqual(got, want) {
|
||||
t.Fatalf("asset names = %#v, want %#v", got, want)
|
||||
}
|
||||
version := exec.Command(filepath.Join(outputDir, "narratio-v1.2.3-linux-amd64"), "version")
|
||||
version := exec.Command(filepath.Join(outputDir, "narratio-v0.0.0-test-linux-amd64"), "version")
|
||||
var versionOutput bytes.Buffer
|
||||
version.Stdout = &versionOutput
|
||||
if err := version.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := versionOutput.String(); got != "narratio v1.2.3\n" {
|
||||
if got := versionOutput.String(); got != "narratio v0.0.0-test\n" {
|
||||
t.Fatalf("embedded version output = %q", got)
|
||||
}
|
||||
goCommands, err := os.ReadFile(goLog)
|
||||
|
||||
Reference in New Issue
Block a user