From 403d2bbd3357aa57e78745b52dcdad3490901bb3 Mon Sep 17 00:00:00 2001 From: yfzhou Date: Sat, 13 Jun 2026 13:17:48 +0800 Subject: [PATCH] fix: restore ScopedFs RealPath (#5986) --- files/file_test.go | 14 ++++++++++++++ files/scoped.go | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/files/file_test.go b/files/file_test.go index 1efda7f6..b5a8b37f 100644 --- a/files/file_test.go +++ b/files/file_test.go @@ -212,3 +212,17 @@ func TestReadListingSkipsInaccessibleChildren(t *testing.T) { t.Fatalf("expected one listed directory, got %d", got) } } + +func TestFileInfoRealPathUsesScopedFsRealPath(t *testing.T) { + root := t.TempDir() + file := &FileInfo{ + Fs: NewScopedFs(afero.NewOsFs(), root), + Path: "/root/downloads", + } + + got := file.RealPath() + want := filepath.Join(root, "root", "downloads") + if got != want { + t.Fatalf("got %q, want %q", got, want) + } +} diff --git a/files/scoped.go b/files/scoped.go index e6e18435..eef6378b 100644 --- a/files/scoped.go +++ b/files/scoped.go @@ -35,6 +35,13 @@ func NewScopedFs(source afero.Fs, path string) *ScopedFs { // Base returns the underlying *afero.BasePathFs. func (s *ScopedFs) Base() *afero.BasePathFs { return s.base } +// RealPath resolves a scoped path to the real on-disk path by delegating to +// the underlying BasePathFs. This is needed by callers that need the actual +// filesystem path (e.g. disk.UsageWithContext). +func (s *ScopedFs) RealPath(name string) (string, error) { + return s.base.RealPath(name) +} + // guard returns an error if name's on-disk target resolves outside the scope. func (s *ScopedFs) guard(name string) error { ok, err := s.within(name)