1
0
forked from rosa/hakurei

all: use filepath

This makes package check portable, and removes nonportable behaviour from package pkg, pipewire, and system. All other packages remain nonportable due to their nature. No latency increase was observed due to this change on amd64 and arm64 linux.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-03-30 18:15:56 +09:00
parent b5592633f5
commit a6600be34a
26 changed files with 94 additions and 95 deletions

View File

@@ -17,7 +17,7 @@ import (
"log"
"net"
"os"
"path"
"path/filepath"
"syscall"
)
@@ -54,7 +54,7 @@ func (t *T) MustCheckFile(wantFilePath string) {
}
func mustAbs(s string) string {
if !path.IsAbs(s) {
if !filepath.IsAbs(s) {
fatalf("[FAIL] %q is not absolute", s)
panic("unreachable")
}
@@ -68,7 +68,7 @@ func (t *T) MustCheck(want *TestCase) {
os.Getenv("XDG_RUNTIME_DIR"),
}
for _, a := range checkWritableDirPaths {
pathname := path.Join(mustAbs(a), ".hakurei-check")
pathname := filepath.Join(mustAbs(a), ".hakurei-check")
if err := os.WriteFile(pathname, make([]byte, 1<<8), 0600); err != nil {
fatalf("[FAIL] %s", err)
} else if err = os.Remove(pathname); err != nil {

View File

@@ -5,7 +5,7 @@ package sandbox
import (
"encoding/json"
"os"
"path"
"path/filepath"
"testing"
)
@@ -15,7 +15,7 @@ func SwapPrint(f F) (old F) { old = printfFunc; printfFunc = f; return }
func SwapFatal(f F) (old F) { old = fatalfFunc; fatalfFunc = f; return }
func MustWantFile(t *testing.T, v any) (wantFile string) {
wantFile = path.Join(t.TempDir(), "want.json")
wantFile = filepath.Join(t.TempDir(), "want.json")
if f, err := os.OpenFile(wantFile, os.O_CREATE|os.O_WRONLY, 0400); err != nil {
t.Fatalf("cannot create %q: %v", wantFile, err)
} else if err = json.NewEncoder(f).Encode(v); err != nil {

View File

@@ -6,7 +6,7 @@ import (
"errors"
"fmt"
"io/fs"
"path"
"path/filepath"
"strings"
)
@@ -68,7 +68,7 @@ func (s *FS) Compare(prefix string, e fs.FS) error {
printDir(prefix, dir)
return ErrFSInvalidEnt
} else {
name = path.Join(prefix, name)
name = filepath.Join(prefix, name)
if fi, err := got.Info(); err != nil {
return err

View File

@@ -4,7 +4,7 @@ package sandbox_test
import (
"os"
"path"
"path/filepath"
"testing"
"hakurei.app/test/internal/sandbox"
@@ -87,7 +87,7 @@ func TestMountinfo(t *testing.T) {
}
for _, tc := range testCases {
name := path.Join(t.TempDir(), "sample")
name := filepath.Join(t.TempDir(), "sample")
if err := os.WriteFile(name, []byte(tc.sample), 0400); err != nil {
t.Fatalf("cannot write sample: %v", err)
}