forked from mirror/afero
Make MemMapFs implement Lstater
This commit is contained in:
parent
27c9ee0498
commit
cb8b6bc2ff
1
go.mod
1
go.mod
|
@ -2,6 +2,7 @@ module github.com/spf13/afero
|
|||
|
||||
require (
|
||||
github.com/pkg/sftp v1.10.1
|
||||
github.com/stretchr/testify v1.4.0
|
||||
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586
|
||||
golang.org/x/text v0.3.3
|
||||
)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -8,6 +8,9 @@ import (
|
|||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNormalizePath(t *testing.T) {
|
||||
|
@ -650,3 +653,23 @@ 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)
|
||||
require.True(t, ok, "The filesytem does not implement Lstater")
|
||||
|
||||
file, err := fs.OpenFile("/a.txt", os.O_CREATE, 0o644)
|
||||
require.NoError(t, err)
|
||||
defer file.Close()
|
||||
|
||||
_, lstatCalled, err := fsAsserted.LstatIfPossible("/a.txt")
|
||||
assert.NoError(t, err)
|
||||
assert.False(t, lstatCalled)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue