36 lines
971 B
Go
36 lines
971 B
Go
//go:build linux || darwin
|
|
|
|
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-")
|
|
}
|