mirror of
https://github.com/tailscale/tailscale.git
synced 2026-05-07 13:16:32 +02:00
macOS doesn't like the test, in the setup where it creates a unix-domain socket: ``` atomicfile_test.go:27: listen unix /var/folders/_2/42v283xx1xgbjdbyvhlm13hc0000gp/T/TestDoesNotOverwriteIrregularFiles1507752327/001/special: bind: invalid argument ``` I think at this point we should assume the socket as written in the test only works on Linux. Updates #7658 Signed-off-by: Denton Gentry <dgentry@tailscale.com>
39 lines
965 B
Go
39 lines
965 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build linux
|
|
|
|
package atomicfile
|
|
|
|
import (
|
|
"net"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestDoesNotOverwriteIrregularFiles(t *testing.T) {
|
|
// Per tailscale/tailscale#7658 as one example, almost any imagined use of
|
|
// atomicfile.Write should likely not attempt to overwrite an irregular file
|
|
// such as a device node, socket, or named pipe.
|
|
|
|
d := t.TempDir()
|
|
special := filepath.Join(d, "special")
|
|
|
|
// The least troublesome thing to make that is not a file is a unix socket.
|
|
// Making a null device sadly requries root.
|
|
l, err := net.ListenUnix("unix", &net.UnixAddr{Name: special, Net: "unix"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer l.Close()
|
|
|
|
err = WriteFile(special, []byte("hello"), 0644)
|
|
if err == nil {
|
|
t.Fatal("expected error, got nil")
|
|
}
|
|
if !strings.Contains(err.Error(), "is not a regular file") {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
}
|