diff --git a/memmap.go b/memmap.go index bbcc238..0fa9592 100644 --- a/memmap.go +++ b/memmap.go @@ -317,6 +317,11 @@ func (m *MemMapFs) Rename(oldname, newname string) error { return nil } +func (m *MemMapFs) LstatIfPossible(name string) (os.FileInfo, bool, error) { + fileInfo, err := m.Stat(name) + return fileInfo, false, err +} + func (m *MemMapFs) Stat(name string) (os.FileInfo, error) { f, err := m.Open(name) if err != nil { diff --git a/memmap_test.go b/memmap_test.go index 6ce742c..476909d 100644 --- a/memmap_test.go +++ b/memmap_test.go @@ -650,3 +650,31 @@ func TestMemFsOpenFileModeIllegal(t *testing.T) { t.Fatalf("should not be able to use OpenFile to set illegal mode: %s", info.Mode().String()) } } + +// LstatIfPossible should always return false, since MemMapFs does not +// support symlinks. +func TestMemFsLstatIfPossible(t *testing.T) { + t.Parallel() + + fs := NewMemMapFs() + + // We assert that fs implements Lstater + fsAsserted, ok := fs.(Lstater) + if !ok { + t.Fatalf("The filesytem does not implement Lstater") + } + + file, err := fs.OpenFile("/a.txt", os.O_CREATE, 0o644) + if err != nil { + t.Fatalf("Error when opening file: %v", err) + } + defer file.Close() + + _, lstatCalled, err := fsAsserted.LstatIfPossible("/a.txt") + if err != nil { + t.Fatalf("Function returned err: %v", err) + } + if lstatCalled { + t.Fatalf("Function indicated lstat was called. This should never be true.") + } +}