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

@@ -5,7 +5,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"path" "path/filepath"
"slices" "slices"
"strings" "strings"
"syscall" "syscall"
@@ -61,7 +61,7 @@ func (a *Absolute) Is(v *Absolute) bool {
// NewAbs checks pathname and returns a new [Absolute] if pathname is absolute. // NewAbs checks pathname and returns a new [Absolute] if pathname is absolute.
func NewAbs(pathname string) (*Absolute, error) { func NewAbs(pathname string) (*Absolute, error) {
if !path.IsAbs(pathname) { if !filepath.IsAbs(pathname) {
return nil, AbsoluteError(pathname) return nil, AbsoluteError(pathname)
} }
return unsafeAbs(pathname), nil return unsafeAbs(pathname), nil
@@ -76,13 +76,13 @@ func MustAbs(pathname string) *Absolute {
} }
} }
// Append calls [path.Join] with [Absolute] as the first element. // Append calls [filepath.Join] with [Absolute] as the first element.
func (a *Absolute) Append(elem ...string) *Absolute { func (a *Absolute) Append(elem ...string) *Absolute {
return unsafeAbs(path.Join(append([]string{a.String()}, elem...)...)) return unsafeAbs(filepath.Join(append([]string{a.String()}, elem...)...))
} }
// Dir calls [path.Dir] with [Absolute] as its argument. // Dir calls [filepath.Dir] with [Absolute] as its argument.
func (a *Absolute) Dir() *Absolute { return unsafeAbs(path.Dir(a.String())) } func (a *Absolute) Dir() *Absolute { return unsafeAbs(filepath.Dir(a.String())) }
// GobEncode returns the checked pathname. // GobEncode returns the checked pathname.
func (a *Absolute) GobEncode() ([]byte, error) { func (a *Absolute) GobEncode() ([]byte, error) {
@@ -92,7 +92,7 @@ func (a *Absolute) GobEncode() ([]byte, error) {
// GobDecode stores data if it represents an absolute pathname. // GobDecode stores data if it represents an absolute pathname.
func (a *Absolute) GobDecode(data []byte) error { func (a *Absolute) GobDecode(data []byte) error {
pathname := string(data) pathname := string(data)
if !path.IsAbs(pathname) { if !filepath.IsAbs(pathname) {
return AbsoluteError(pathname) return AbsoluteError(pathname)
} }
a.pathname = unique.Make(pathname) a.pathname = unique.Make(pathname)
@@ -110,7 +110,7 @@ func (a *Absolute) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &pathname); err != nil { if err := json.Unmarshal(data, &pathname); err != nil {
return err return err
} }
if !path.IsAbs(pathname) { if !filepath.IsAbs(pathname) {
return AbsoluteError(pathname) return AbsoluteError(pathname)
} }
a.pathname = unique.Make(pathname) a.pathname = unique.Make(pathname)

View File

@@ -58,7 +58,7 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"path" "path/filepath"
"runtime" "runtime"
"slices" "slices"
"strconv" "strconv"
@@ -102,13 +102,13 @@ func main() {
log.Fatal("this program must not be started by root") log.Fatal("this program must not be started by root")
} }
if !path.IsAbs(hakureiPath) { if !filepath.IsAbs(hakureiPath) {
log.Fatal("this program is compiled incorrectly") log.Fatal("this program is compiled incorrectly")
return return
} }
var toolPath string var toolPath string
pexe := path.Join("/proc", strconv.Itoa(os.Getppid()), "exe") pexe := filepath.Join("/proc", strconv.Itoa(os.Getppid()), "exe")
if p, err := os.Readlink(pexe); err != nil { if p, err := os.Readlink(pexe); err != nil {
log.Fatalf("cannot read parent executable path: %v", err) log.Fatalf("cannot read parent executable path: %v", err)
} else if strings.HasSuffix(p, " (deleted)") { } else if strings.HasSuffix(p, " (deleted)") {

View File

@@ -24,7 +24,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"os/signal" "os/signal"
"path" "path/filepath"
"runtime" "runtime"
"runtime/cgo" "runtime/cgo"
"strconv" "strconv"
@@ -145,9 +145,9 @@ func sharefs_destroy(private_data unsafe.Pointer) {
func showHelp(args *fuseArgs) { func showHelp(args *fuseArgs) {
executableName := sharefsName executableName := sharefsName
if args.argc > 0 { if args.argc > 0 {
executableName = path.Base(C.GoString(*args.argv)) executableName = filepath.Base(C.GoString(*args.argv))
} else if name, err := os.Executable(); err == nil { } else if name, err := os.Executable(); err == nil {
executableName = path.Base(name) executableName = filepath.Base(name)
} }
fmt.Printf("usage: %s [options] <mountpoint>\n\n", executableName) fmt.Printf("usage: %s [options] <mountpoint>\n\n", executableName)

View File

@@ -8,7 +8,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"os/signal" "os/signal"
"path" "path/filepath"
"slices" "slices"
"strconv" "strconv"
"sync" "sync"
@@ -569,7 +569,7 @@ func TryArgv0(msg message.Msg) {
msg = message.New(log.Default()) msg = message.New(log.Default())
} }
if len(os.Args) > 0 && path.Base(os.Args[0]) == initName { if len(os.Args) > 0 && filepath.Base(os.Args[0]) == initName {
Init(msg) Init(msg)
msg.BeforeExit() msg.BeforeExit()
os.Exit(0) os.Exit(0)

View File

@@ -3,7 +3,7 @@ package container
import ( import (
"encoding/gob" "encoding/gob"
"fmt" "fmt"
"path" "path/filepath"
. "syscall" . "syscall"
"hakurei.app/check" "hakurei.app/check"
@@ -46,7 +46,7 @@ func (d *MountDevOp) apply(state *setupState, k syscallDispatcher) error {
} }
for _, name := range []string{"null", "zero", "full", "random", "urandom", "tty"} { for _, name := range []string{"null", "zero", "full", "random", "urandom", "tty"} {
targetPath := path.Join(target, name) targetPath := filepath.Join(target, name)
if err := k.ensureFile(targetPath, 0444, state.ParentPerm); err != nil { if err := k.ensureFile(targetPath, 0444, state.ParentPerm); err != nil {
return err return err
} }
@@ -62,7 +62,7 @@ func (d *MountDevOp) apply(state *setupState, k syscallDispatcher) error {
for i, name := range []string{"stdin", "stdout", "stderr"} { for i, name := range []string{"stdin", "stdout", "stderr"} {
if err := k.symlink( if err := k.symlink(
fhs.Proc+"self/fd/"+string(rune(i+'0')), fhs.Proc+"self/fd/"+string(rune(i+'0')),
path.Join(target, name), filepath.Join(target, name),
); err != nil { ); err != nil {
return err return err
} }
@@ -72,13 +72,13 @@ func (d *MountDevOp) apply(state *setupState, k syscallDispatcher) error {
{fhs.Proc + "kcore", "core"}, {fhs.Proc + "kcore", "core"},
{"pts/ptmx", "ptmx"}, {"pts/ptmx", "ptmx"},
} { } {
if err := k.symlink(pair[0], path.Join(target, pair[1])); err != nil { if err := k.symlink(pair[0], filepath.Join(target, pair[1])); err != nil {
return err return err
} }
} }
devShmPath := path.Join(target, "shm") devShmPath := filepath.Join(target, "shm")
devPtsPath := path.Join(target, "pts") devPtsPath := filepath.Join(target, "pts")
for _, name := range []string{devShmPath, devPtsPath} { for _, name := range []string{devShmPath, devPtsPath} {
if err := k.mkdir(name, state.ParentPerm); err != nil { if err := k.mkdir(name, state.ParentPerm); err != nil {
return err return err
@@ -92,7 +92,7 @@ func (d *MountDevOp) apply(state *setupState, k syscallDispatcher) error {
if state.RetainSession { if state.RetainSession {
if k.isatty(Stdout) { if k.isatty(Stdout) {
consolePath := path.Join(target, "console") consolePath := filepath.Join(target, "console")
if err := k.ensureFile(consolePath, 0444, state.ParentPerm); err != nil { if err := k.ensureFile(consolePath, 0444, state.ParentPerm); err != nil {
return err return err
} }
@@ -110,7 +110,7 @@ func (d *MountDevOp) apply(state *setupState, k syscallDispatcher) error {
} }
if d.Mqueue { if d.Mqueue {
mqueueTarget := path.Join(target, "mqueue") mqueueTarget := filepath.Join(target, "mqueue")
if err := k.mkdir(mqueueTarget, state.ParentPerm); err != nil { if err := k.mkdir(mqueueTarget, state.ParentPerm); err != nil {
return err return err
} }

View File

@@ -3,7 +3,7 @@ package container
import ( import (
"encoding/gob" "encoding/gob"
"fmt" "fmt"
"path" "path/filepath"
"hakurei.app/check" "hakurei.app/check"
) )
@@ -30,7 +30,7 @@ func (l *SymlinkOp) Valid() bool { return l != nil && l.Target != nil && l.LinkN
func (l *SymlinkOp) early(_ *setupState, k syscallDispatcher) error { func (l *SymlinkOp) early(_ *setupState, k syscallDispatcher) error {
if l.Dereference { if l.Dereference {
if !path.IsAbs(l.LinkName) { if !filepath.IsAbs(l.LinkName) {
return check.AbsoluteError(l.LinkName) return check.AbsoluteError(l.LinkName)
} }
if name, err := k.readlink(l.LinkName); err != nil { if name, err := k.readlink(l.LinkName); err != nil {
@@ -44,7 +44,7 @@ func (l *SymlinkOp) early(_ *setupState, k syscallDispatcher) error {
func (l *SymlinkOp) apply(state *setupState, k syscallDispatcher) error { func (l *SymlinkOp) apply(state *setupState, k syscallDispatcher) error {
target := toSysroot(l.Target.String()) target := toSysroot(l.Target.String())
if err := k.mkdirAll(path.Dir(target), state.ParentPerm); err != nil { if err := k.mkdirAll(filepath.Dir(target), state.ParentPerm); err != nil {
return err return err
} }
return k.symlink(l.LinkName, target) return k.symlink(l.LinkName, target)

View File

@@ -4,7 +4,7 @@ import (
"errors" "errors"
"io/fs" "io/fs"
"os" "os"
"path" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"syscall" "syscall"
@@ -29,16 +29,16 @@ const (
func toSysroot(name string) string { func toSysroot(name string) string {
name = strings.TrimLeftFunc(name, func(r rune) bool { return r == '/' }) name = strings.TrimLeftFunc(name, func(r rune) bool { return r == '/' })
return path.Join(sysrootPath, name) return filepath.Join(sysrootPath, name)
} }
func toHost(name string) string { func toHost(name string) string {
name = strings.TrimLeftFunc(name, func(r rune) bool { return r == '/' }) name = strings.TrimLeftFunc(name, func(r rune) bool { return r == '/' })
return path.Join(hostPath, name) return filepath.Join(hostPath, name)
} }
func createFile(name string, perm, pperm os.FileMode, content []byte) error { func createFile(name string, perm, pperm os.FileMode, content []byte) error {
if err := os.MkdirAll(path.Dir(name), pperm); err != nil { if err := os.MkdirAll(filepath.Dir(name), pperm); err != nil {
return err return err
} }
f, err := os.OpenFile(name, syscall.O_CREAT|syscall.O_EXCL|syscall.O_WRONLY, perm) f, err := os.OpenFile(name, syscall.O_CREAT|syscall.O_EXCL|syscall.O_WRONLY, perm)

View File

@@ -4,7 +4,7 @@ import (
"io" "io"
"math" "math"
"os" "os"
"path" "path/filepath"
"reflect" "reflect"
"syscall" "syscall"
"testing" "testing"
@@ -61,7 +61,7 @@ func TestCreateFile(t *testing.T) {
Path: "/proc/nonexistent", Path: "/proc/nonexistent",
Err: syscall.ENOENT, Err: syscall.ENOENT,
} }
if err := createFile(path.Join(Nonexistent, ":3"), 0644, 0755, nil); !reflect.DeepEqual(err, wantErr) { if err := createFile(filepath.Join(Nonexistent, ":3"), 0644, 0755, nil); !reflect.DeepEqual(err, wantErr) {
t.Errorf("createFile: error = %#v, want %#v", err, wantErr) t.Errorf("createFile: error = %#v, want %#v", err, wantErr)
} }
}) })
@@ -72,7 +72,7 @@ func TestCreateFile(t *testing.T) {
Path: "/proc/nonexistent", Path: "/proc/nonexistent",
Err: syscall.ENOENT, Err: syscall.ENOENT,
} }
if err := createFile(path.Join(Nonexistent), 0644, 0755, nil); !reflect.DeepEqual(err, wantErr) { if err := createFile(filepath.Join(Nonexistent), 0644, 0755, nil); !reflect.DeepEqual(err, wantErr) {
t.Errorf("createFile: error = %#v, want %#v", err, wantErr) t.Errorf("createFile: error = %#v, want %#v", err, wantErr)
} }
}) })
@@ -80,7 +80,7 @@ func TestCreateFile(t *testing.T) {
t.Run("touch", func(t *testing.T) { t.Run("touch", func(t *testing.T) {
tempDir := t.TempDir() tempDir := t.TempDir()
pathname := path.Join(tempDir, "empty") pathname := filepath.Join(tempDir, "empty")
if err := createFile(pathname, 0644, 0755, nil); err != nil { if err := createFile(pathname, 0644, 0755, nil); err != nil {
t.Fatalf("createFile: error = %v", err) t.Fatalf("createFile: error = %v", err)
} }
@@ -93,7 +93,7 @@ func TestCreateFile(t *testing.T) {
t.Run("write", func(t *testing.T) { t.Run("write", func(t *testing.T) {
tempDir := t.TempDir() tempDir := t.TempDir()
pathname := path.Join(tempDir, "zero") pathname := filepath.Join(tempDir, "zero")
if err := createFile(pathname, 0644, 0755, []byte{0}); err != nil { if err := createFile(pathname, 0644, 0755, []byte{0}); err != nil {
t.Fatalf("createFile: error = %v", err) t.Fatalf("createFile: error = %v", err)
} }
@@ -107,7 +107,7 @@ func TestCreateFile(t *testing.T) {
func TestEnsureFile(t *testing.T) { func TestEnsureFile(t *testing.T) {
t.Run("create", func(t *testing.T) { t.Run("create", func(t *testing.T) {
if err := ensureFile(path.Join(t.TempDir(), "ensure"), 0644, 0755); err != nil { if err := ensureFile(filepath.Join(t.TempDir(), "ensure"), 0644, 0755); err != nil {
t.Errorf("ensureFile: error = %v", err) t.Errorf("ensureFile: error = %v", err)
} }
}) })
@@ -115,7 +115,7 @@ func TestEnsureFile(t *testing.T) {
t.Run("stat", func(t *testing.T) { t.Run("stat", func(t *testing.T) {
t.Run("inaccessible", func(t *testing.T) { t.Run("inaccessible", func(t *testing.T) {
tempDir := t.TempDir() tempDir := t.TempDir()
pathname := path.Join(tempDir, "inaccessible") pathname := filepath.Join(tempDir, "inaccessible")
if f, err := os.Create(pathname); err != nil { if f, err := os.Create(pathname); err != nil {
t.Fatalf("Create: error = %v", err) t.Fatalf("Create: error = %v", err)
} else { } else {
@@ -150,7 +150,7 @@ func TestEnsureFile(t *testing.T) {
t.Run("ensure", func(t *testing.T) { t.Run("ensure", func(t *testing.T) {
tempDir := t.TempDir() tempDir := t.TempDir()
pathname := path.Join(tempDir, "ensure") pathname := filepath.Join(tempDir, "ensure")
if f, err := os.Create(pathname); err != nil { if f, err := os.Create(pathname); err != nil {
t.Fatalf("Create: error = %v", err) t.Fatalf("Create: error = %v", err)
} else { } else {
@@ -195,12 +195,12 @@ func TestProcPaths(t *testing.T) {
t.Run("sample", func(t *testing.T) { t.Run("sample", func(t *testing.T) {
tempDir := t.TempDir() tempDir := t.TempDir()
if err := os.MkdirAll(path.Join(tempDir, "proc/self"), 0755); err != nil { if err := os.MkdirAll(filepath.Join(tempDir, "proc/self"), 0755); err != nil {
t.Fatalf("MkdirAll: error = %v", err) t.Fatalf("MkdirAll: error = %v", err)
} }
t.Run("clean", func(t *testing.T) { t.Run("clean", func(t *testing.T) {
if err := os.WriteFile(path.Join(tempDir, "proc/self/mountinfo"), []byte(`15 20 0:3 / /proc rw,relatime - proc /proc rw if err := os.WriteFile(filepath.Join(tempDir, "proc/self/mountinfo"), []byte(`15 20 0:3 / /proc rw,relatime - proc /proc rw
16 20 0:15 / /sys rw,relatime - sysfs /sys rw 16 20 0:15 / /sys rw,relatime - sysfs /sys rw
17 20 0:5 / /dev rw,relatime - devtmpfs udev rw,size=1983516k,nr_inodes=495879,mode=755`), 0644); err != nil { 17 20 0:5 / /dev rw,relatime - devtmpfs udev rw,size=1983516k,nr_inodes=495879,mode=755`), 0644); err != nil {
t.Fatalf("WriteFile: error = %v", err) t.Fatalf("WriteFile: error = %v", err)
@@ -243,8 +243,8 @@ func TestProcPaths(t *testing.T) {
}) })
t.Run("malformed", func(t *testing.T) { t.Run("malformed", func(t *testing.T) {
path.Join(tempDir, "proc/self/mountinfo") filepath.Join(tempDir, "proc/self/mountinfo")
if err := os.WriteFile(path.Join(tempDir, "proc/self/mountinfo"), []byte{0}, 0644); err != nil { if err := os.WriteFile(filepath.Join(tempDir, "proc/self/mountinfo"), []byte{0}, 0644); err != nil {
t.Fatalf("WriteFile: error = %v", err) t.Fatalf("WriteFile: error = %v", err)
} }

View File

@@ -2,7 +2,7 @@ package hst
import ( import (
"encoding/gob" "encoding/gob"
"path" "path/filepath"
"hakurei.app/check" "hakurei.app/check"
) )
@@ -28,7 +28,7 @@ func (l *FSLink) Valid() bool {
if l == nil || l.Target == nil || l.Linkname == "" { if l == nil || l.Target == nil || l.Linkname == "" {
return false return false
} }
return !l.Dereference || path.IsAbs(l.Linkname) return !l.Dereference || filepath.IsAbs(l.Linkname)
} }
func (l *FSLink) Path() *check.Absolute { func (l *FSLink) Path() *check.Absolute {

View File

@@ -8,7 +8,7 @@ import (
"io" "io"
"os" "os"
"os/exec" "os/exec"
"path" "path/filepath"
"reflect" "reflect"
"strconv" "strconv"
"testing" "testing"
@@ -28,7 +28,7 @@ func TestUpdate(t *testing.T) {
t.Skip("acl test skipped") t.Skip("acl test skipped")
} }
testFilePath := path.Join(t.TempDir(), testFileName) testFilePath := filepath.Join(t.TempDir(), testFileName)
if f, err := os.Create(testFilePath); err != nil { if f, err := os.Create(testFilePath); err != nil {
t.Fatalf("Create: error = %v", err) t.Fatalf("Create: error = %v", err)

View File

@@ -5,7 +5,7 @@ import (
"errors" "errors"
"io/fs" "io/fs"
"os" "os"
"path" "path/filepath"
"slices" "slices"
"strconv" "strconv"
"syscall" "syscall"
@@ -165,9 +165,9 @@ func (s *spFilesystemOp) toSystem(state *outcomeStateSys) error {
} }
for _, pair := range entry.Values { for _, pair := range entry.Values {
if pair[0] == "path" { if pair[0] == "path" {
if path.IsAbs(pair[1]) { if filepath.IsAbs(pair[1]) {
// get parent dir of socket // get parent dir of socket
dir := path.Dir(pair[1]) dir := filepath.Dir(pair[1])
if dir == "." || dir == fhs.Root { if dir == "." || dir == fhs.Root {
state.msg.Verbosef("dbus socket %q is in an unusual location", pair[1]) state.msg.Verbosef("dbus socket %q is in an unusual location", pair[1])
} }

View File

@@ -20,7 +20,7 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"path" "path/filepath"
"runtime" "runtime"
"slices" "slices"
"strconv" "strconv"
@@ -973,23 +973,23 @@ func connectName(name string, manager bool) (conn Conn, err error) {
return connectName(name+"-manager", false) return connectName(name+"-manager", false)
} }
if path.IsAbs(name) || (len(name) > 0 && name[0] == '@') { if filepath.IsAbs(name) || (len(name) > 0 && name[0] == '@') {
return Dial(name) return Dial(name)
} else { } else {
runtimeDir, ok := os.LookupEnv("PIPEWIRE_RUNTIME_DIR") runtimeDir, ok := os.LookupEnv("PIPEWIRE_RUNTIME_DIR")
if !ok || !path.IsAbs(runtimeDir) { if !ok || !filepath.IsAbs(runtimeDir) {
runtimeDir, ok = os.LookupEnv("XDG_RUNTIME_DIR") runtimeDir, ok = os.LookupEnv("XDG_RUNTIME_DIR")
} }
if !ok || !path.IsAbs(runtimeDir) { if !ok || !filepath.IsAbs(runtimeDir) {
// this is cargo culted from windows stuff and has no effect normally; // this is cargo culted from windows stuff and has no effect normally;
// keeping it to maintain compatibility in case someone sets this // keeping it to maintain compatibility in case someone sets this
runtimeDir, ok = os.LookupEnv("USERPROFILE") runtimeDir, ok = os.LookupEnv("USERPROFILE")
} }
if !ok || !path.IsAbs(runtimeDir) { if !ok || !filepath.IsAbs(runtimeDir) {
runtimeDir = DEFAULT_SYSTEM_RUNTIME_DIR runtimeDir = DEFAULT_SYSTEM_RUNTIME_DIR
} }
return Dial(path.Join(runtimeDir, name)) return Dial(filepath.Join(runtimeDir, name))
} }
} }

View File

@@ -8,7 +8,7 @@ import (
"io" "io"
"os" "os"
"os/exec" "os/exec"
"path" "path/filepath"
"slices" "slices"
"strconv" "strconv"
"syscall" "syscall"
@@ -189,7 +189,7 @@ func NewExec(
paths ...ExecPath, paths ...ExecPath,
) Artifact { ) Artifact {
if name == "" { if name == "" {
name = "exec-" + path.Base(pathname.String()) name = "exec-" + filepath.Base(pathname.String())
} }
if timeout <= 0 { if timeout <= 0 {
timeout = ExecTimeoutDefault timeout = ExecTimeoutDefault

View File

@@ -16,7 +16,6 @@ import (
"iter" "iter"
"maps" "maps"
"os" "os"
"path"
"path/filepath" "path/filepath"
"runtime" "runtime"
"slices" "slices"
@@ -894,7 +893,7 @@ func (c *Cache) Scrub(checks int) error {
se.DanglingIdentifiers = append(se.DanglingIdentifiers, *want) se.DanglingIdentifiers = append(se.DanglingIdentifiers, *want)
seMu.Unlock() seMu.Unlock()
return false return false
} else if err = Decode(got, path.Base(linkname)); err != nil { } else if err = Decode(got, filepath.Base(linkname)); err != nil {
seMu.Lock() seMu.Lock()
lnp := dir.Append(linkname) lnp := dir.Append(linkname)
se.Errs[lnp.Handle()] = append(se.Errs[lnp.Handle()], err) se.Errs[lnp.Handle()] = append(se.Errs[lnp.Handle()], err)
@@ -1488,7 +1487,7 @@ func (c *Cache) cure(a Artifact, curesExempt bool) (
return return
} }
buf := c.getIdentBuf() buf := c.getIdentBuf()
err = Decode((*Checksum)(buf[:]), path.Base(name)) err = Decode((*Checksum)(buf[:]), filepath.Base(name))
if err == nil { if err == nil {
checksum = unique.Make(Checksum(buf[:])) checksum = unique.Make(Checksum(buf[:]))
} }

View File

@@ -10,7 +10,7 @@ import (
"io/fs" "io/fs"
"net/http" "net/http"
"os" "os"
"path" "path/filepath"
) )
const ( const (
@@ -169,7 +169,7 @@ func (a *tarArtifact) Cure(t *TContext) (err error) {
} }
if typeflag >= '0' && typeflag <= '9' && typeflag != tar.TypeDir { if typeflag >= '0' && typeflag <= '9' && typeflag != tar.TypeDir {
if err = root.MkdirAll(path.Dir(header.Name), 0700); err != nil { if err = root.MkdirAll(filepath.Dir(header.Name), 0700); err != nil {
return return
} }
} }

View File

@@ -7,7 +7,7 @@ import (
"log" "log"
"net" "net"
"os" "os"
"path" "path/filepath"
"reflect" "reflect"
"slices" "slices"
"strings" "strings"
@@ -68,7 +68,7 @@ func main() {
if got, err := os.Executable(); err != nil { if got, err := os.Executable(); err != nil {
log.Fatalf("Executable: error = %v", err) log.Fatalf("Executable: error = %v", err)
} else { } else {
iftPath = path.Join(path.Dir(path.Dir(got)), "ift") iftPath = filepath.Join(filepath.Dir(filepath.Dir(got)), "ift")
if got != wantExec { if got != wantExec {
switch got { switch got {
@@ -161,7 +161,7 @@ func main() {
} }
} }
if !layers { if !layers {
if path.Base(lowerdir) != checksumEmptyDir { if filepath.Base(lowerdir) != checksumEmptyDir {
log.Fatal("unexpected artifact checksum") log.Fatal("unexpected artifact checksum")
} }
} else { } else {
@@ -187,8 +187,8 @@ func main() {
} }
if len(lowerdirs) != 2 || if len(lowerdirs) != 2 ||
path.Base(lowerdirs[0]) != "MGWmEfjut2QE2xPJwTsmUzpff4BN_FEnQ7T0j7gvUCCiugJQNwqt9m151fm9D1yU" || filepath.Base(lowerdirs[0]) != "MGWmEfjut2QE2xPJwTsmUzpff4BN_FEnQ7T0j7gvUCCiugJQNwqt9m151fm9D1yU" ||
path.Base(lowerdirs[1]) != "nY_CUdiaUM1OL4cPr5TS92FCJ3rCRV7Hm5oVTzAvMXwC03_QnTRfQ5PPs7mOU9fK" { filepath.Base(lowerdirs[1]) != "nY_CUdiaUM1OL4cPr5TS92FCJ3rCRV7Hm5oVTzAvMXwC03_QnTRfQ5PPs7mOU9fK" {
log.Fatalf("unexpected lowerdirs %s", strings.Join(lowerdirs, ", ")) log.Fatalf("unexpected lowerdirs %s", strings.Join(lowerdirs, ", "))
} }
} }
@@ -202,12 +202,12 @@ func main() {
} }
next() next()
if path.Base(m.Root) != "OLBgp1GsljhM2TJ-sbHjaiH9txEUvgdDTAzHv2P24donTt6_529l-9Ua0vFImLlb" { if filepath.Base(m.Root) != "OLBgp1GsljhM2TJ-sbHjaiH9txEUvgdDTAzHv2P24donTt6_529l-9Ua0vFImLlb" {
log.Fatal("unexpected file artifact checksum") log.Fatal("unexpected file artifact checksum")
} }
next() next()
if path.Base(m.Root) != checksumEmptyDir { if filepath.Base(m.Root) != checksumEmptyDir {
log.Fatal("unexpected artifact checksum") log.Fatal("unexpected artifact checksum")
} }
} }
@@ -226,13 +226,13 @@ func main() {
log.Fatal("unexpected work mount entry") log.Fatal("unexpected work mount entry")
} }
} else { } else {
if path.Base(m.Root) != ident || m.Target != "/work" { if filepath.Base(m.Root) != ident || m.Target != "/work" {
log.Fatal("unexpected work mount entry") log.Fatal("unexpected work mount entry")
} }
} }
next() next()
if path.Base(m.Root) != ident || m.Target != "/tmp" { if filepath.Base(m.Root) != ident || m.Target != "/tmp" {
log.Fatal("unexpected temp mount entry") log.Fatal("unexpected temp mount entry")
} }

View File

@@ -1,7 +1,7 @@
package rosa package rosa
import ( import (
"path" "path/filepath"
"slices" "slices"
"strings" "strings"
@@ -200,7 +200,7 @@ cmake -G ` + generate + ` \
} }
}), " \\\n\t") + ` \ }), " \\\n\t") + ` \
-DCMAKE_INSTALL_PREFIX=/system \ -DCMAKE_INSTALL_PREFIX=/system \
'/usr/src/` + name + `/` + path.Join(attr.Append...) + `' '/usr/src/` + name + `/` + filepath.Join(attr.Append...) + `'
cmake --build .` + jobs + ` cmake --build .` + jobs + `
cmake --install . --prefix=/work/system cmake --install . --prefix=/work/system
` + attr.Script ` + attr.Script

View File

@@ -3,7 +3,7 @@ package rosa_test
import ( import (
"errors" "errors"
"os" "os"
"path" "path/filepath"
"syscall" "syscall"
"testing" "testing"
"unique" "unique"
@@ -13,7 +13,7 @@ import (
) )
func TestReportZeroLength(t *testing.T) { func TestReportZeroLength(t *testing.T) {
report := path.Join(t.TempDir(), "report") report := filepath.Join(t.TempDir(), "report")
if err := os.WriteFile(report, nil, 0400); err != nil { if err := os.WriteFile(report, nil, 0400); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -24,7 +24,7 @@ func TestReportZeroLength(t *testing.T) {
} }
func TestReportSIGSEGV(t *testing.T) { func TestReportSIGSEGV(t *testing.T) {
report := path.Join(t.TempDir(), "report") report := filepath.Join(t.TempDir(), "report")
if err := os.WriteFile(report, make([]byte, 64), 0400); err != nil { if err := os.WriteFile(report, make([]byte, 64), 0400); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@@ -3,7 +3,7 @@ package system
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"syscall" "syscall"
"testing" "testing"
"time" "time"
@@ -18,7 +18,7 @@ func TestPipeWireOp(t *testing.T) {
checkOpBehaviour(t, checkNoParallel, []opBehaviourTestCase{ checkOpBehaviour(t, checkNoParallel, []opBehaviourTestCase{
{"success", 0xbeef, 0xff, &pipewireOp{nil, {"success", 0xbeef, 0xff, &pipewireOp{nil,
m(path.Join(t.TempDir(), "pipewire")), m(filepath.Join(t.TempDir(), "pipewire")),
"org.chromium.Chromium", "org.chromium.Chromium",
"ebf083d1b175911782d413369b64ce7c", "ebf083d1b175911782d413369b64ce7c",
}, []stub.Call{ }, []stub.Call{

View File

@@ -3,7 +3,7 @@ package wayland
import ( import (
"errors" "errors"
"os" "os"
"path" "path/filepath"
"reflect" "reflect"
"syscall" "syscall"
"testing" "testing"
@@ -19,7 +19,7 @@ func TestSecurityContextClose(t *testing.T) {
} }
var ctx SecurityContext var ctx SecurityContext
if f, err := os.Create(path.Join(t.TempDir(), "remove")); err != nil { if f, err := os.Create(filepath.Join(t.TempDir(), "remove")); err != nil {
t.Fatal(err) t.Fatal(err)
} else { } else {
ctx.bindPath = check.MustAbs(f.Name()) ctx.bindPath = check.MustAbs(f.Name())

View File

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

View File

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

View File

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

View File

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

View File

@@ -5,7 +5,7 @@ import (
"errors" "errors"
"iter" "iter"
"os" "os"
"path" "path/filepath"
"reflect" "reflect"
"slices" "slices"
"strconv" "strconv"
@@ -394,7 +394,7 @@ func mn(
}, },
FirstChild: firstChild, FirstChild: firstChild,
NextSibling: nextSibling, NextSibling: nextSibling,
Clean: path.Clean(target), Clean: filepath.Clean(target),
Covered: covered, Covered: covered,
} }
} }

View File

@@ -2,7 +2,7 @@ package vfs
import ( import (
"iter" "iter"
"path" "path/filepath"
"strings" "strings"
) )
@@ -43,7 +43,7 @@ func (n *MountInfoNode) visit(yield func(*MountInfoNode) bool) bool {
// Unfold unfolds the mount hierarchy and resolves covered paths. // Unfold unfolds the mount hierarchy and resolves covered paths.
func (d *MountInfoDecoder) Unfold(target string) (*MountInfoNode, error) { func (d *MountInfoDecoder) Unfold(target string) (*MountInfoNode, error) {
targetClean := path.Clean(target) targetClean := filepath.Clean(target)
var mountinfoSize int var mountinfoSize int
for range d.Entries() { for range d.Entries() {
@@ -61,7 +61,7 @@ func (d *MountInfoDecoder) Unfold(target string) (*MountInfoNode, error) {
{ {
i := 0 i := 0
for ent := range d.Entries() { for ent := range d.Entries() {
mountinfo[i] = &MountInfoNode{Clean: path.Clean(ent.Target), MountInfoEntry: ent} mountinfo[i] = &MountInfoNode{Clean: filepath.Clean(ent.Target), MountInfoEntry: ent}
idIndex[ent.ID] = i idIndex[ent.ID] = i
if mountinfo[i].Clean == targetClean { if mountinfo[i].Clean == targetClean {
targetIndex = i targetIndex = i