Commit 1fa5a003 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Hide ReadOnlyFile to reduce API clutter.

parent eb033a6d
...@@ -220,37 +220,41 @@ func (f *loopbackFile) Utimens(a *time.Time, m *time.Time) Status { ...@@ -220,37 +220,41 @@ func (f *loopbackFile) Utimens(a *time.Time, m *time.Time) Status {
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// ReadOnlyFile is a wrapper that denies writable operations func NewReadOnlyFile(f File) File {
type ReadOnlyFile struct { return &readOnlyFile{File: f}
}
// readOnlyFile is a wrapper that denies writable operations
type readOnlyFile struct {
File File
} }
var _ = (File)((*ReadOnlyFile)(nil)) var _ = (File)((*readOnlyFile)(nil))
func (f *ReadOnlyFile) String() string { func (f *readOnlyFile) String() string {
return fmt.Sprintf("ReadOnlyFile(%s)", f.File.String()) return fmt.Sprintf("readOnlyFile(%s)", f.File.String())
} }
func (f *ReadOnlyFile) Write(data []byte, off int64) (uint32, Status) { func (f *readOnlyFile) Write(data []byte, off int64) (uint32, Status) {
return 0, EPERM return 0, EPERM
} }
func (f *ReadOnlyFile) Fsync(flag int) (code Status) { func (f *readOnlyFile) Fsync(flag int) (code Status) {
return OK return OK
} }
func (f *ReadOnlyFile) Truncate(size uint64) Status { func (f *readOnlyFile) Truncate(size uint64) Status {
return EPERM return EPERM
} }
func (f *ReadOnlyFile) Chmod(mode uint32) Status { func (f *readOnlyFile) Chmod(mode uint32) Status {
return EPERM return EPERM
} }
func (f *ReadOnlyFile) Chown(uid uint32, gid uint32) Status { func (f *readOnlyFile) Chown(uid uint32, gid uint32) Status {
return EPERM return EPERM
} }
func (f *ReadOnlyFile) Allocate(off uint64, sz uint64, mode uint32) Status { func (f *readOnlyFile) Allocate(off uint64, sz uint64, mode uint32) Status {
return EPERM return EPERM
} }
...@@ -73,7 +73,7 @@ func (fs *readonlyFileSystem) Open(name string, flags uint32, context *fuse.Cont ...@@ -73,7 +73,7 @@ func (fs *readonlyFileSystem) Open(name string, flags uint32, context *fuse.Cont
return nil, fuse.EPERM return nil, fuse.EPERM
} }
file, code = fs.FileSystem.Open(name, flags, context) file, code = fs.FileSystem.Open(name, flags, context)
return &fuse.ReadOnlyFile{file}, code return fuse.NewReadOnlyFile(file), code
} }
func (fs *readonlyFileSystem) OpenDir(name string, context *fuse.Context) (stream []fuse.DirEntry, status fuse.Status) { func (fs *readonlyFileSystem) OpenDir(name string, context *fuse.Context) (stream []fuse.DirEntry, status fuse.Status) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment