53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package fs
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"golang.org/x/net/webdav"
|
|
)
|
|
|
|
type WebDavFile struct {
|
|
*File
|
|
}
|
|
|
|
func (*WebDavFile) Write(_ []byte) (int, error) {
|
|
return 0, os.ErrPermission
|
|
}
|
|
|
|
type WebDavFS struct {
|
|
fs *FS
|
|
}
|
|
|
|
func NewWebDavFS(fs *FS) *WebDavFS {
|
|
return &WebDavFS{fs}
|
|
}
|
|
|
|
func (*WebDavFS) Mkdir(_ context.Context, _ string, _ os.FileMode) error {
|
|
return os.ErrPermission
|
|
}
|
|
func (*WebDavFS) RemoveAll(_ context.Context, _ string) error {
|
|
return os.ErrPermission
|
|
}
|
|
func (*WebDavFS) Rename(_ context.Context, _, _ string) error {
|
|
return os.ErrPermission
|
|
}
|
|
|
|
func (w *WebDavFS) OpenFile(_ context.Context, name string, flags int, _ os.FileMode) (webdav.File, error) {
|
|
//O_WRONLY int = syscall.O_WRONLY // open the file write-only.
|
|
//O_RDWR int = syscall.O_RDWR // open the file read-write.
|
|
//O_APPEND int = syscall.O_APPEND // append data to the file when writing.
|
|
//O_CREATE int = syscall.O_CREAT // create a new file if none exists.
|
|
//O_EXCL int = syscall.O_EXCL // used with O_CREATE, file must not exist.
|
|
if flags&os.O_RDWR == os.O_RDWR ||
|
|
flags&os.O_CREATE == os.O_CREATE ||
|
|
flags&os.O_TRUNC == os.O_TRUNC {
|
|
return nil, os.ErrPermission
|
|
}
|
|
f, err := w.fs.OpenFile(name)
|
|
return &WebDavFile{f}, err
|
|
}
|
|
|
|
func (w *WebDavFS) Stat(_ context.Context, name string) (os.FileInfo, error) {
|
|
return w.fs.Stat(name)
|
|
}
|