afero
afero copied to clipboard
[MemMapFs] Will MemMapFs support creating read-only files?
When conducting tests, there are times when I want to create a read-only file, But i found that there is no option available to create a read-only file. I know there is ReadOnlyFs already, but new a fs seems unnecessary to me.
I found func Create in memmap.go
func (m *MemMapFs) Create(name string) (File, error) {
name = normalizePath(name)
m.mu.Lock()
file := mem.CreateFile(name)
m.getData()[name] = file
m.registerWithParent(file, 0)
m.mu.Unlock()
return mem.NewFileHandle(file), nil
}
and NewReadOnlyFileHandle in file.go
func NewReadOnlyFileHandle(data *FileData) *File {
return &File{fileData: data, readOnly: true}
}
Will it possible to support create read-only file with adding an additional parameter to the Create function like
func (m *MemMapFs) Create(name string, readOnly bool) (File, error)
......
if readOnly {
return NewReadOnlyFileHandle(file), nil
}
......
Or there might already be a way to create a read-only file.
I have tried func (m *MemMapFs) Chmod
, but it seems useless.
If there are any better methods, i would appreciate to learn it.