added custom filter options
This commit is contained in:
parent
f6e1813d15
commit
a4c746c7e9
4 changed files with 70 additions and 3 deletions
|
|
@ -16,12 +16,13 @@ const writeFlag = os.O_RDWR | os.O_CREATE | os.O_TRUNC
|
|||
|
||||
// WriteOnlyOnceFileSystem is a file write only wrapper for a webdav.FileSystem
|
||||
type WriteOnlyOnceFileSystem struct {
|
||||
fs webdav.FileSystem
|
||||
Filters []Filter
|
||||
fs webdav.FileSystem
|
||||
}
|
||||
|
||||
// NewWriteOnlyOnceFileSystem returns a new WriteOnlyOnceFileSystem wrapping a webdav.FileSystem
|
||||
func NewWriteOnlyOnceFileSystem(fs webdav.FileSystem) *WriteOnlyOnceFileSystem {
|
||||
return &WriteOnlyOnceFileSystem{fs}
|
||||
return &WriteOnlyOnceFileSystem{fs: fs}
|
||||
}
|
||||
|
||||
// Mkdir is not permitted
|
||||
|
|
@ -38,6 +39,12 @@ func (fs *WriteOnlyOnceFileSystem) OpenFile(ctx context.Context, name string, fl
|
|||
return nil, ErrWonly
|
||||
}
|
||||
}
|
||||
for _, filter := range fs.Filters {
|
||||
err = filter.Filter(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
f, err := fs.fs.OpenFile(ctx, name, flag, perm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -45,8 +52,15 @@ func (fs *WriteOnlyOnceFileSystem) OpenFile(ctx context.Context, name string, fl
|
|||
return &File{f}, nil
|
||||
}
|
||||
|
||||
// RemoveAll is not permitted
|
||||
// RemoveAll only permits deleting empty files
|
||||
func (fs *WriteOnlyOnceFileSystem) RemoveAll(ctx context.Context, name string) error {
|
||||
fi, err := fs.fs.Stat(ctx, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if fi.Mode().IsRegular() && fi.Size() == 0 {
|
||||
return fs.fs.RemoveAll(ctx, name)
|
||||
}
|
||||
return ErrWonly
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue