Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MemMapFs] Will MemMapFs support creating read-only files? #401

Open
kizuna-lek opened this issue Aug 30, 2023 · 0 comments
Open

[MemMapFs] Will MemMapFs support creating read-only files? #401

kizuna-lek opened this issue Aug 30, 2023 · 0 comments

Comments

@kizuna-lek
Copy link

kizuna-lek commented Aug 30, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant