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) {
|
||||
|
||||
Reference in New Issue
Block a user