|
|
|
|
@@ -5,6 +5,7 @@ import (
|
|
|
|
|
"encoding/hex"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"regexp"
|
|
|
|
|
@@ -15,6 +16,7 @@ import (
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"codex-agent-manager/internal/codexhome"
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var ErrWriteConflict = errors.New("目标文件已在校验后发生变化")
|
|
|
|
|
@@ -23,22 +25,29 @@ var safeAgentID = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9_-]*$`)
|
|
|
|
|
|
|
|
|
|
var writebackMu sync.Mutex
|
|
|
|
|
var writebackTestHookBeforeBackup func()
|
|
|
|
|
var writebackTestHookAfterVerifyBeforeBackup func()
|
|
|
|
|
var writebackTestHookAfterBackup func()
|
|
|
|
|
|
|
|
|
|
type fileIdentity struct {
|
|
|
|
|
dev uint64
|
|
|
|
|
ino uint64
|
|
|
|
|
mode os.FileMode
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type writeTarget struct {
|
|
|
|
|
path string
|
|
|
|
|
base string
|
|
|
|
|
content []byte
|
|
|
|
|
mode os.FileMode
|
|
|
|
|
agentsIdentity fileIdentity
|
|
|
|
|
targetIdentity fileIdentity
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type agentsDirHandle struct {
|
|
|
|
|
fd int
|
|
|
|
|
path string
|
|
|
|
|
identity fileIdentity
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s Store) ValidateDraft(id string, content string) (DraftValidation, error) {
|
|
|
|
|
target, err := s.readWriteTarget(id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
@@ -83,10 +92,11 @@ func (s Store) WriteDraft(id string, content string, expectedHash string) (Write
|
|
|
|
|
return WriteResult{}, ErrWriteConflict
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
target, err := s.readWriteTarget(id)
|
|
|
|
|
target, dir, err := s.openWriteTarget(id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return WriteResult{}, err
|
|
|
|
|
}
|
|
|
|
|
defer dir.close()
|
|
|
|
|
if hashBytes(target.content) != expectedHash {
|
|
|
|
|
return WriteResult{}, ErrWriteConflict
|
|
|
|
|
}
|
|
|
|
|
@@ -94,18 +104,24 @@ func (s Store) WriteDraft(id string, content string, expectedHash string) (Write
|
|
|
|
|
if writebackTestHookBeforeBackup != nil {
|
|
|
|
|
writebackTestHookBeforeBackup()
|
|
|
|
|
}
|
|
|
|
|
if _, err := s.verifyWriteTarget(id, target, expectedHash); err != nil {
|
|
|
|
|
if _, err := s.verifyWriteTarget(dir, id, target, expectedHash); err != nil {
|
|
|
|
|
return WriteResult{}, err
|
|
|
|
|
}
|
|
|
|
|
backupPath, err := s.createBackup(target.path, target.content, target.mode)
|
|
|
|
|
if writebackTestHookAfterVerifyBeforeBackup != nil {
|
|
|
|
|
writebackTestHookAfterVerifyBeforeBackup()
|
|
|
|
|
}
|
|
|
|
|
if _, err := s.verifyWriteTarget(dir, id, target, expectedHash); err != nil {
|
|
|
|
|
return WriteResult{}, err
|
|
|
|
|
}
|
|
|
|
|
backupPath, err := s.createBackup(dir, target)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return WriteResult{}, err
|
|
|
|
|
}
|
|
|
|
|
if writebackTestHookAfterBackup != nil {
|
|
|
|
|
writebackTestHookAfterBackup()
|
|
|
|
|
}
|
|
|
|
|
if err := atomicWrite(target, []byte(content), func() error {
|
|
|
|
|
_, err := s.verifyWriteTarget(id, target, expectedHash)
|
|
|
|
|
if err := atomicWrite(dir, target, []byte(content), func() error {
|
|
|
|
|
_, err := s.verifyWriteTarget(dir, id, target, expectedHash)
|
|
|
|
|
return err
|
|
|
|
|
}); err != nil {
|
|
|
|
|
return WriteResult{}, err
|
|
|
|
|
@@ -120,56 +136,136 @@ func (s Store) WriteDraft(id string, content string, expectedHash string) (Write
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s Store) readWriteTarget(id string) (writeTarget, error) {
|
|
|
|
|
if !safeAgentID.MatchString(id) {
|
|
|
|
|
return writeTarget{}, codexhome.ErrForbiddenPath
|
|
|
|
|
}
|
|
|
|
|
agentsPath := filepath.Join(s.CodexHome, "agents")
|
|
|
|
|
agentsInfo, err := os.Lstat(agentsPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
} else if agentsInfo.Mode()&os.ModeSymlink != 0 || !agentsInfo.IsDir() {
|
|
|
|
|
return writeTarget{}, codexhome.ErrForbiddenPath
|
|
|
|
|
}
|
|
|
|
|
agentsIdentity, err := identityOf(agentsInfo)
|
|
|
|
|
target, dir, err := s.openWriteTarget(id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fileName := id + ".toml"
|
|
|
|
|
targetPath, err := codexhome.ResolveAgentTOML(s.CodexHome, fileName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
targetInfo, err := os.Lstat(targetPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
if targetInfo.Mode()&os.ModeSymlink != 0 || !targetInfo.Mode().IsRegular() {
|
|
|
|
|
return writeTarget{}, codexhome.ErrForbiddenPath
|
|
|
|
|
}
|
|
|
|
|
targetIdentity, err := identityOf(targetInfo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
data, err := os.ReadFile(targetPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
target := writeTarget{
|
|
|
|
|
path: targetPath,
|
|
|
|
|
content: data,
|
|
|
|
|
mode: targetInfo.Mode().Perm(),
|
|
|
|
|
agentsIdentity: agentsIdentity,
|
|
|
|
|
targetIdentity: targetIdentity,
|
|
|
|
|
}
|
|
|
|
|
if _, err := s.verifyWriteTarget(id, target, hashBytes(data)); err != nil {
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
defer dir.close()
|
|
|
|
|
return target, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s Store) verifyWriteTarget(id string, expected writeTarget, expectedHash string) (writeTarget, error) {
|
|
|
|
|
current, err := s.readWriteTargetUnchecked(id)
|
|
|
|
|
func (s Store) openWriteTarget(id string) (writeTarget, agentsDirHandle, error) {
|
|
|
|
|
if !safeAgentID.MatchString(id) {
|
|
|
|
|
return writeTarget{}, agentsDirHandle{}, codexhome.ErrForbiddenPath
|
|
|
|
|
}
|
|
|
|
|
dir, err := openAgentsDir(s.CodexHome)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return writeTarget{}, agentsDirHandle{}, err
|
|
|
|
|
}
|
|
|
|
|
target, err := s.readTargetFromDir(dir, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
dir.close()
|
|
|
|
|
return writeTarget{}, agentsDirHandle{}, err
|
|
|
|
|
}
|
|
|
|
|
if err := ensureAgentsPathStillMatches(dir); err != nil {
|
|
|
|
|
dir.close()
|
|
|
|
|
return writeTarget{}, agentsDirHandle{}, err
|
|
|
|
|
}
|
|
|
|
|
return target, dir, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func openAgentsDir(home string) (agentsDirHandle, error) {
|
|
|
|
|
path := filepath.Join(home, "agents")
|
|
|
|
|
fd, err := unix.Open(path, unix.O_RDONLY|unix.O_DIRECTORY|unix.O_CLOEXEC|unix.O_NOFOLLOW, 0)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if errors.Is(err, unix.ELOOP) || errors.Is(err, unix.ENOTDIR) {
|
|
|
|
|
return agentsDirHandle{}, codexhome.ErrForbiddenPath
|
|
|
|
|
}
|
|
|
|
|
return agentsDirHandle{}, err
|
|
|
|
|
}
|
|
|
|
|
var stat unix.Stat_t
|
|
|
|
|
if err := unix.Fstat(fd, &stat); err != nil {
|
|
|
|
|
_ = unix.Close(fd)
|
|
|
|
|
return agentsDirHandle{}, err
|
|
|
|
|
}
|
|
|
|
|
dir := agentsDirHandle{fd: fd, path: path, identity: identityOfUnix(stat)}
|
|
|
|
|
if err := ensureAgentsPathStillMatches(dir); err != nil {
|
|
|
|
|
_ = unix.Close(fd)
|
|
|
|
|
return agentsDirHandle{}, err
|
|
|
|
|
}
|
|
|
|
|
return dir, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d agentsDirHandle) close() {
|
|
|
|
|
if d.fd >= 0 {
|
|
|
|
|
_ = unix.Close(d.fd)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ensureAgentsPathStillMatches(dir agentsDirHandle) error {
|
|
|
|
|
info, err := os.Lstat(dir.path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
|
return ErrWriteConflict
|
|
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if info.Mode()&os.ModeSymlink != 0 || !info.IsDir() {
|
|
|
|
|
return ErrWriteConflict
|
|
|
|
|
}
|
|
|
|
|
identity, err := identityOf(info)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if identity != dir.identity {
|
|
|
|
|
return ErrWriteConflict
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s Store) readTargetFromDir(dir agentsDirHandle, id string) (writeTarget, error) {
|
|
|
|
|
if !safeAgentID.MatchString(id) {
|
|
|
|
|
return writeTarget{}, codexhome.ErrForbiddenPath
|
|
|
|
|
}
|
|
|
|
|
base := id + ".toml"
|
|
|
|
|
if _, err := codexhome.ResolveAgentTOML(s.CodexHome, base); err != nil {
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
fd, err := unix.Openat(dir.fd, base, unix.O_RDONLY|unix.O_CLOEXEC|unix.O_NOFOLLOW, 0)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if errors.Is(err, unix.ELOOP) {
|
|
|
|
|
return writeTarget{}, codexhome.ErrForbiddenPath
|
|
|
|
|
}
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
var stat unix.Stat_t
|
|
|
|
|
if err := unix.Fstat(fd, &stat); err != nil {
|
|
|
|
|
_ = unix.Close(fd)
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
if stat.Mode&unix.S_IFMT != unix.S_IFREG {
|
|
|
|
|
_ = unix.Close(fd)
|
|
|
|
|
return writeTarget{}, codexhome.ErrForbiddenPath
|
|
|
|
|
}
|
|
|
|
|
data, err := readAllFromFD(fd, base)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
return writeTarget{
|
|
|
|
|
path: filepath.Join(dir.path, base),
|
|
|
|
|
base: base,
|
|
|
|
|
content: data,
|
|
|
|
|
mode: os.FileMode(stat.Mode & 0o777),
|
|
|
|
|
agentsIdentity: dir.identity,
|
|
|
|
|
targetIdentity: identityOfUnix(stat),
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func readAllFromFD(fd int, name string) ([]byte, error) {
|
|
|
|
|
file := os.NewFile(uintptr(fd), name)
|
|
|
|
|
if file == nil {
|
|
|
|
|
_ = unix.Close(fd)
|
|
|
|
|
return nil, errors.New("无法打开目标文件")
|
|
|
|
|
}
|
|
|
|
|
defer file.Close()
|
|
|
|
|
return io.ReadAll(file)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s Store) verifyWriteTarget(dir agentsDirHandle, id string, expected writeTarget, expectedHash string) (writeTarget, error) {
|
|
|
|
|
if err := ensureAgentsPathStillMatches(dir); err != nil {
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
current, err := s.readTargetFromDir(dir, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
|
return writeTarget{}, ErrWriteConflict
|
|
|
|
|
@@ -177,6 +273,7 @@ func (s Store) verifyWriteTarget(id string, expected writeTarget, expectedHash s
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
if current.path != expected.path ||
|
|
|
|
|
current.base != expected.base ||
|
|
|
|
|
current.agentsIdentity != expected.agentsIdentity ||
|
|
|
|
|
current.targetIdentity != expected.targetIdentity {
|
|
|
|
|
return writeTarget{}, ErrWriteConflict
|
|
|
|
|
@@ -187,101 +284,79 @@ func (s Store) verifyWriteTarget(id string, expected writeTarget, expectedHash s
|
|
|
|
|
return current, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s Store) readWriteTargetUnchecked(id string) (writeTarget, error) {
|
|
|
|
|
if !safeAgentID.MatchString(id) {
|
|
|
|
|
return writeTarget{}, codexhome.ErrForbiddenPath
|
|
|
|
|
}
|
|
|
|
|
agentsPath := filepath.Join(s.CodexHome, "agents")
|
|
|
|
|
agentsInfo, err := os.Lstat(agentsPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
if agentsInfo.Mode()&os.ModeSymlink != 0 || !agentsInfo.IsDir() {
|
|
|
|
|
return writeTarget{}, codexhome.ErrForbiddenPath
|
|
|
|
|
}
|
|
|
|
|
agentsIdentity, err := identityOf(agentsInfo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
targetPath, err := codexhome.ResolveAgentTOML(s.CodexHome, id+".toml")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
targetInfo, err := os.Lstat(targetPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
if targetInfo.Mode()&os.ModeSymlink != 0 || !targetInfo.Mode().IsRegular() {
|
|
|
|
|
return writeTarget{}, codexhome.ErrForbiddenPath
|
|
|
|
|
}
|
|
|
|
|
targetIdentity, err := identityOf(targetInfo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
data, err := os.ReadFile(targetPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return writeTarget{}, err
|
|
|
|
|
}
|
|
|
|
|
return writeTarget{
|
|
|
|
|
path: targetPath,
|
|
|
|
|
content: data,
|
|
|
|
|
mode: targetInfo.Mode().Perm(),
|
|
|
|
|
agentsIdentity: agentsIdentity,
|
|
|
|
|
targetIdentity: targetIdentity,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func identityOf(info os.FileInfo) (fileIdentity, error) {
|
|
|
|
|
stat, ok := info.Sys().(*syscall.Stat_t)
|
|
|
|
|
if !ok {
|
|
|
|
|
return fileIdentity{}, errors.New("无法确认文件身份")
|
|
|
|
|
}
|
|
|
|
|
switch stat := info.Sys().(type) {
|
|
|
|
|
case *unix.Stat_t:
|
|
|
|
|
return identityOfUnix(*stat), nil
|
|
|
|
|
case *syscall.Stat_t:
|
|
|
|
|
return fileIdentity{
|
|
|
|
|
dev: uint64(stat.Dev),
|
|
|
|
|
ino: uint64(stat.Ino),
|
|
|
|
|
mode: info.Mode(),
|
|
|
|
|
}, nil
|
|
|
|
|
default:
|
|
|
|
|
return fileIdentity{}, errors.New("无法确认文件身份")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s Store) createBackup(targetPath string, content []byte, mode os.FileMode) (string, error) {
|
|
|
|
|
backupPath := fmt.Sprintf("%s.bak-%s", targetPath, time.Now().UTC().Format("20060102T150405.000000000Z"))
|
|
|
|
|
file, err := os.OpenFile(backupPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, mode)
|
|
|
|
|
func identityOfUnix(stat unix.Stat_t) fileIdentity {
|
|
|
|
|
return fileIdentity{
|
|
|
|
|
dev: uint64(stat.Dev),
|
|
|
|
|
ino: uint64(stat.Ino),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s Store) createBackup(dir agentsDirHandle, target writeTarget) (string, error) {
|
|
|
|
|
if err := ensureAgentsPathStillMatches(dir); err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
backupName := fmt.Sprintf("%s.bak-%s", target.base, time.Now().UTC().Format("20060102T150405.000000000Z"))
|
|
|
|
|
fd, err := unix.Openat(dir.fd, backupName, unix.O_WRONLY|unix.O_CREAT|unix.O_EXCL|unix.O_CLOEXEC|unix.O_NOFOLLOW, uint32(target.mode))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
if _, err := file.Write(content); err != nil {
|
|
|
|
|
|
|
|
|
|
file := os.NewFile(uintptr(fd), backupName)
|
|
|
|
|
if file == nil {
|
|
|
|
|
_ = unix.Close(fd)
|
|
|
|
|
_ = unix.Unlinkat(dir.fd, backupName, 0)
|
|
|
|
|
return "", errors.New("无法创建备份")
|
|
|
|
|
}
|
|
|
|
|
if _, err := file.Write(target.content); err != nil {
|
|
|
|
|
_ = file.Close()
|
|
|
|
|
_ = os.Remove(backupPath)
|
|
|
|
|
_ = unix.Unlinkat(dir.fd, backupName, 0)
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
if err := file.Close(); err != nil {
|
|
|
|
|
_ = os.Remove(backupPath)
|
|
|
|
|
_ = unix.Unlinkat(dir.fd, backupName, 0)
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
return backupPath, nil
|
|
|
|
|
return filepath.Join(dir.path, backupName), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func atomicWrite(target writeTarget, content []byte, beforeRename func() error) error {
|
|
|
|
|
dir := filepath.Dir(target.path)
|
|
|
|
|
base := filepath.Base(target.path)
|
|
|
|
|
tmp, err := os.CreateTemp(dir, "."+base+".tmp-*")
|
|
|
|
|
func atomicWrite(dir agentsDirHandle, target writeTarget, content []byte, beforeRename func() error) error {
|
|
|
|
|
tmpName := fmt.Sprintf(".%s.tmp-%d-%d", target.base, os.Getpid(), time.Now().UnixNano())
|
|
|
|
|
fd, err := unix.Openat(dir.fd, tmpName, unix.O_WRONLY|unix.O_CREAT|unix.O_EXCL|unix.O_CLOEXEC|unix.O_NOFOLLOW, uint32(target.mode))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
tmpPath := tmp.Name()
|
|
|
|
|
defer func() {
|
|
|
|
|
_ = os.Remove(tmpPath)
|
|
|
|
|
_ = unix.Unlinkat(dir.fd, tmpName, 0)
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
if err := tmp.Chmod(target.mode); err != nil {
|
|
|
|
|
_ = tmp.Close()
|
|
|
|
|
if err := unix.Fchmod(fd, uint32(target.mode)); err != nil {
|
|
|
|
|
_ = unix.Close(fd)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if _, err := tmp.Write(content); err != nil {
|
|
|
|
|
_ = tmp.Close()
|
|
|
|
|
file := os.NewFile(uintptr(fd), tmpName)
|
|
|
|
|
if file == nil {
|
|
|
|
|
_ = unix.Close(fd)
|
|
|
|
|
return errors.New("无法创建临时文件")
|
|
|
|
|
}
|
|
|
|
|
if _, err := file.Write(content); err != nil {
|
|
|
|
|
_ = file.Close()
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if err := tmp.Close(); err != nil {
|
|
|
|
|
if err := file.Close(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if beforeRename != nil {
|
|
|
|
|
@@ -289,7 +364,7 @@ func atomicWrite(target writeTarget, content []byte, beforeRename func() error)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return os.Rename(tmpPath, target.path)
|
|
|
|
|
return unix.Renameat(dir.fd, tmpName, dir.fd, target.base)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func hashBytes(data []byte) string {
|
|
|
|
|
|