Add safe immutable directory promotion
This commit is contained in:
35
internal/fileops/directory_special_unix_test.go
Normal file
35
internal/fileops/directory_special_unix_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
//go:build !windows
|
||||
|
||||
package fileops
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPromoteDirectoryRejectsNamedPipe(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
src := filepath.Join(root, "source")
|
||||
dst := filepath.Join(root, "destination")
|
||||
if err := os.Mkdir(src, 0o755); err != nil {
|
||||
t.Fatalf("Mkdir(source) error = %v", err)
|
||||
}
|
||||
pipe := filepath.Join(src, "events.pipe")
|
||||
if err := syscall.Mkfifo(pipe, 0o600); err != nil {
|
||||
t.Skipf("Mkfifo() unavailable: %v", err)
|
||||
}
|
||||
|
||||
if err := PromoteDirectory(src, dst); err == nil {
|
||||
t.Fatal("PromoteDirectory() error = nil, want named pipe rejection")
|
||||
}
|
||||
info, err := os.Lstat(pipe)
|
||||
if err != nil || info.Mode()&os.ModeNamedPipe == 0 {
|
||||
t.Fatalf("source named pipe was not preserved: info=%v err=%v", info, err)
|
||||
}
|
||||
if _, err := os.Lstat(dst); !os.IsNotExist(err) {
|
||||
t.Fatalf("Lstat(destination) error = %v, want not exist", err)
|
||||
}
|
||||
assertNoMatchingTempDirectories(t, root, ".destination.tmp-")
|
||||
}
|
||||
Reference in New Issue
Block a user