Skip to content

Commit

Permalink
Merge pull request #264 from LandonTClipp/memmapfs_lstatifpossible
Browse files Browse the repository at this point in the history
Make MemMapFs implement Lstater
  • Loading branch information
0xmichalis authored Sep 14, 2020
2 parents 27c9ee0 + bf960e8 commit 277f220
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions memmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 28 additions & 0 deletions memmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}

0 comments on commit 277f220

Please sign in to comment.