forked from mirror/afero
Merge pull request #264 from LandonTClipp/memmapfs_lstatifpossible
Make MemMapFs implement Lstater
This commit is contained in:
commit
277f220898
|
@ -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 {
|
||||||
|
|
|
@ -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.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue