Support atomic directory promotion across platforms
This commit is contained in:
26
internal/fileops/rename_noreplace_supported_test.go
Normal file
26
internal/fileops/rename_noreplace_supported_test.go
Normal file
@@ -0,0 +1,26 @@
|
||||
//go:build linux || darwin || windows
|
||||
|
||||
package fileops
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRenameDirectoryNoReplacePreservesExistingDestination(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
src := filepath.Join(root, "source")
|
||||
dst := filepath.Join(root, "destination")
|
||||
mustWriteFile(t, filepath.Join(src, "value.txt"), []byte("source"), 0o644)
|
||||
mustWriteFile(t, filepath.Join(dst, "value.txt"), []byte("existing"), 0o644)
|
||||
|
||||
if err := renameDirectoryNoReplace(src, dst); err == nil {
|
||||
t.Fatal("renameDirectoryNoReplace() error = nil, want existing destination failure")
|
||||
}
|
||||
assertFileBytes(t, filepath.Join(src, "value.txt"), []byte("source"))
|
||||
assertFileBytes(t, filepath.Join(dst, "value.txt"), []byte("existing"))
|
||||
if info, err := os.Stat(src); err != nil || !info.IsDir() {
|
||||
t.Fatalf("source directory was not preserved: info=%v err=%v", info, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user