Merge pull request #264 from LandonTClipp/memmapfs_lstatifpossible

Make MemMapFs implement Lstater
This commit is contained in:
Michail Kargakis 2020-09-14 20:42:22 +02:00 committed by GitHub
commit 277f220898
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View File

@ -317,6 +317,11 @@ func (m *MemMapFs) Rename(oldname, newname string) error {
return nil 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) { func (m *MemMapFs) Stat(name string) (os.FileInfo, error) {
f, err := m.Open(name) f, err := m.Open(name)
if err != nil { if err != nil {

View File

@ -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()) 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.")
}
}