2015-12-13 16:56:00 +03:00
|
|
|
package afero
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ReadOnlyFilter struct {
|
2015-12-20 13:47:14 +03:00
|
|
|
source Fs
|
2015-12-13 16:56:00 +03:00
|
|
|
}
|
|
|
|
|
2015-12-20 13:47:14 +03:00
|
|
|
func NewReadonlyFilter() FilterFs {
|
2015-12-13 16:56:00 +03:00
|
|
|
return &ReadOnlyFilter{}
|
|
|
|
}
|
|
|
|
|
2015-12-20 13:47:14 +03:00
|
|
|
func (r *ReadOnlyFilter) SetSource(fs Fs) {
|
|
|
|
r.source = fs
|
|
|
|
}
|
|
|
|
|
|
|
|
// prepend a filter in the filter chain
|
|
|
|
func (r *ReadOnlyFilter) AddFilter(fs FilterFs) {
|
|
|
|
fs.SetSource(r.source)
|
|
|
|
r.source = fs
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFilter) ReadDir(name string) ([]os.FileInfo, error) {
|
|
|
|
return ReadDir(r.source, name)
|
|
|
|
}
|
|
|
|
|
2015-12-13 16:56:00 +03:00
|
|
|
func (r *ReadOnlyFilter) Chtimes(n string, a, m time.Time) error {
|
|
|
|
return syscall.EPERM
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFilter) Chmod(n string, m os.FileMode) error {
|
|
|
|
return syscall.EPERM
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFilter) Name() string {
|
2015-12-20 13:47:14 +03:00
|
|
|
return "ReadOnlyFilter"
|
2015-12-13 16:56:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFilter) Stat(name string) (os.FileInfo, error) {
|
2015-12-20 13:47:14 +03:00
|
|
|
return r.source.Stat(name)
|
2015-12-13 16:56:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFilter) Rename(o, n string) error {
|
|
|
|
return syscall.EPERM
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFilter) RemoveAll(p string) error {
|
|
|
|
return syscall.EPERM
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFilter) Remove(n string) error {
|
|
|
|
return syscall.EPERM
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFilter) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
|
2015-12-13 20:12:18 +03:00
|
|
|
if flag&(os.O_WRONLY|syscall.O_RDWR|os.O_APPEND|os.O_CREATE|os.O_TRUNC) != 0 {
|
|
|
|
return nil, syscall.EPERM
|
2015-12-13 16:56:00 +03:00
|
|
|
}
|
2015-12-20 13:47:14 +03:00
|
|
|
return r.source.OpenFile(name, flag, perm)
|
2015-12-13 16:56:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFilter) Open(n string) (File, error) {
|
2015-12-20 13:47:14 +03:00
|
|
|
return r.source.Open(n)
|
2015-12-13 16:56:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFilter) Mkdir(n string, p os.FileMode) error {
|
|
|
|
return syscall.EPERM
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFilter) MkdirAll(n string, p os.FileMode) error {
|
|
|
|
return syscall.EPERM
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFilter) Create(n string) (File, error) {
|
|
|
|
return nil, syscall.EPERM
|
|
|
|
}
|