From f869ff95a12756de97827b4afd93763f9661f144 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Mon, 8 Jun 2026 14:19:11 +0900 Subject: all: apply modernisers Signed-off-by: Ophestra --- hst/fs.go | 13 +++++++------ hst/fs_test.go | 4 ++-- hst/fsephemeral.go | 7 +------ 3 files changed, 10 insertions(+), 14 deletions(-) (limited to 'hst') diff --git a/hst/fs.go b/hst/fs.go index 13645d1a..cb35f925 100644 --- a/hst/fs.go +++ b/hst/fs.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "reflect" + "strings" "hakurei.app/check" ) @@ -78,17 +79,17 @@ type FSImplError struct{ Value FilesystemConfig } func (f FSImplError) Error() string { implType := reflect.TypeOf(f.Value) - var name string - for implType != nil && implType.Kind() == reflect.Ptr { - name += "*" + var buf strings.Builder + for implType != nil && implType.Kind() == reflect.Pointer { + buf.WriteByte('*') implType = implType.Elem() } if implType != nil { - name += implType.Name() + buf.WriteString(implType.Name()) } else { - name += "nil" + buf.WriteString("nil") } - return fmt.Sprintf("implementation %s not supported", name) + return "implementation " + buf.String() + " not supported" } // FilesystemConfigJSON is the [json] adapter for [FilesystemConfig]. diff --git a/hst/fs_test.go b/hst/fs_test.go index 94d44078..a88970b7 100644 --- a/hst/fs_test.go +++ b/hst/fs_test.go @@ -103,7 +103,7 @@ func TestFilesystemConfigJSON(t *testing.T) { t.Run("marshal", func(t *testing.T) { t.Parallel() wantErr := tc.wantErr - if errors.As(wantErr, new(hst.FSTypeError)) { + if _, ok := errors.AsType[hst.FSTypeError](wantErr); ok { // for unsupported implementation tc wantErr = hst.FSImplError{Value: stubFS{"cat"}} } @@ -139,7 +139,7 @@ func TestFilesystemConfigJSON(t *testing.T) { t.Run("unmarshal", func(t *testing.T) { t.Parallel() if tc.data == "\x00" && tc.sData == "\x00" { - if errors.As(tc.wantErr, new(hst.FSImplError)) { + if _, ok := errors.AsType[hst.FSImplError](tc.wantErr); ok { // this error is only returned on marshal return } diff --git a/hst/fsephemeral.go b/hst/fsephemeral.go index 9da79003..d1c01bca 100644 --- a/hst/fsephemeral.go +++ b/hst/fsephemeral.go @@ -43,18 +43,13 @@ func (e *FSEphemeral) Apply(z *ApplyState) { return } - size := e.Size - if size < 0 { - size = 0 - } - perm := e.Perm if perm == 0 { perm = fsEphemeralDefaultPerm } if e.Write { - z.Tmpfs(e.Target, size, perm) + z.Tmpfs(e.Target, max(e.Size, 0), perm) } else { z.Readonly(e.Target, perm) } -- cgit v1.3.1