From 22188f777e52cf58e5c05761f44328457420402c Mon Sep 17 00:00:00 2001 From: Tim Ramlot <42113979+inteon@users.noreply.github.com> Date: Mon, 12 Jan 2026 15:42:55 +0100 Subject: [PATCH] Adds String functions to filesystem implementations. In error messages, filesystems are often printed (eg. 'fmt.Errorf("could not open repositories file in %s", a.fs)'). Without String function, this resulted in unreadable error messages. Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com> --- pkg/apk/fs/memfs.go | 4 ++++ pkg/apk/fs/rwosfs.go | 4 ++++ pkg/apk/fs/sub.go | 5 +++++ pkg/tarfs/fs.go | 4 ++++ 4 files changed, 17 insertions(+) diff --git a/pkg/apk/fs/memfs.go b/pkg/apk/fs/memfs.go index e542636f5..a580eb64f 100644 --- a/pkg/apk/fs/memfs.go +++ b/pkg/apk/fs/memfs.go @@ -54,6 +54,10 @@ func NewMemFS() FullFS { } } +func (m *memFS) String() string { + return "memfs" +} + // getNode returns the node for the given path. If the path is not found, it // returns an error. func (m *memFS) getNode(path string) (*node, error) { diff --git a/pkg/apk/fs/rwosfs.go b/pkg/apk/fs/rwosfs.go index 6b0e797a4..a9ed92929 100644 --- a/pkg/apk/fs/rwosfs.go +++ b/pkg/apk/fs/rwosfs.go @@ -207,6 +207,10 @@ type dirFS struct { caseMapMutex sync.Mutex } +func (f *dirFS) String() string { + return fmt.Sprintf("dirfs:%s", f.base) +} + func (f *dirFS) Readlink(name string) (string, error) { // The underlying filesystem might not support symlinks, and it might be case-insensitive, so just // use the one in memory. diff --git a/pkg/apk/fs/sub.go b/pkg/apk/fs/sub.go index 7a1485268..4ff3e80dc 100644 --- a/pkg/apk/fs/sub.go +++ b/pkg/apk/fs/sub.go @@ -2,6 +2,7 @@ package fs import ( "errors" + "fmt" "io/fs" "path/filepath" "time" @@ -12,6 +13,10 @@ type SubFS struct { Root string } +func (s *SubFS) String() string { + return fmt.Sprintf("%s:%s", s.FS, s.Root) +} + func (s *SubFS) Open(path string) (fs.File, error) { if !fs.ValidPath(path) { return nil, &fs.PathError{Op: "open", Path: path, Err: fs.ErrInvalid} diff --git a/pkg/tarfs/fs.go b/pkg/tarfs/fs.go index c37756b54..2c6fb8f2e 100644 --- a/pkg/tarfs/fs.go +++ b/pkg/tarfs/fs.go @@ -104,6 +104,10 @@ func checksumFromHeader(header *tar.Header) ([]byte, error) { return checksum, nil } +func (m *memFS) String() string { + return "tarfs" +} + func (m *memFS) WriteHeader(hdr tar.Header, tfs fs.FS, pkg *apk.Package) (bool, error) { switch hdr.Typeflag { case tar.TypeDir: