2016-01-11 23:31:07 +03:00
|
|
|
package afero
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2018-03-22 19:32:10 +03:00
|
|
|
var _ Lstater = (*ReadOnlyFs)(nil)
|
|
|
|
|
2016-01-11 23:31:07 +03:00
|
|
|
type ReadOnlyFs struct {
|
|
|
|
source Fs
|
|
|
|
}
|
|
|
|
|
2016-01-12 05:41:03 +03:00
|
|
|
func NewReadOnlyFs(source Fs) Fs {
|
|
|
|
return &ReadOnlyFs{source: source}
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:31:07 +03:00
|
|
|
func (r *ReadOnlyFs) ReadDir(name string) ([]os.FileInfo, error) {
|
|
|
|
return ReadDir(r.source, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFs) Chtimes(n string, a, m time.Time) error {
|
2022-05-03 17:06:13 +03:00
|
|
|
return os.ErrPermission
|
2016-01-11 23:31:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFs) Chmod(n string, m os.FileMode) error {
|
2022-05-03 17:06:13 +03:00
|
|
|
return os.ErrPermission
|
2016-01-11 23:31:07 +03:00
|
|
|
}
|
|
|
|
|
2020-12-07 16:19:45 +03:00
|
|
|
func (r *ReadOnlyFs) Chown(n string, uid, gid int) error {
|
2022-05-03 17:06:13 +03:00
|
|
|
return os.ErrPermission
|
2020-12-07 16:19:45 +03:00
|
|
|
}
|
|
|
|
|
2016-01-11 23:31:07 +03:00
|
|
|
func (r *ReadOnlyFs) Name() string {
|
|
|
|
return "ReadOnlyFilter"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFs) Stat(name string) (os.FileInfo, error) {
|
|
|
|
return r.source.Stat(name)
|
|
|
|
}
|
|
|
|
|
2018-03-22 19:32:10 +03:00
|
|
|
func (r *ReadOnlyFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
|
|
|
|
if lsf, ok := r.source.(Lstater); ok {
|
|
|
|
return lsf.LstatIfPossible(name)
|
|
|
|
}
|
|
|
|
fi, err := r.Stat(name)
|
|
|
|
return fi, false, err
|
|
|
|
}
|
|
|
|
|
2019-12-10 08:24:03 +03:00
|
|
|
func (r *ReadOnlyFs) SymlinkIfPossible(oldname, newname string) error {
|
|
|
|
return &os.LinkError{Op: "symlink", Old: oldname, New: newname, Err: ErrNoSymlink}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFs) ReadlinkIfPossible(name string) (string, error) {
|
|
|
|
if srdr, ok := r.source.(LinkReader); ok {
|
|
|
|
return srdr.ReadlinkIfPossible(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
return "", &os.PathError{Op: "readlink", Path: name, Err: ErrNoReadlink}
|
|
|
|
}
|
|
|
|
|
2016-01-11 23:31:07 +03:00
|
|
|
func (r *ReadOnlyFs) Rename(o, n string) error {
|
2022-05-03 17:06:13 +03:00
|
|
|
return os.ErrPermission
|
2016-01-11 23:31:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFs) RemoveAll(p string) error {
|
2022-05-03 17:06:13 +03:00
|
|
|
return os.ErrPermission
|
2016-01-11 23:31:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFs) Remove(n string) error {
|
2022-05-03 17:06:13 +03:00
|
|
|
return os.ErrPermission
|
2016-01-11 23:31:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFs) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
|
2022-05-03 17:06:13 +03:00
|
|
|
if flag&(os.O_WRONLY|os.O_RDWR|os.O_APPEND|os.O_CREATE|os.O_TRUNC) != 0 {
|
|
|
|
return nil, os.ErrPermission
|
2016-01-11 23:31:07 +03:00
|
|
|
}
|
|
|
|
return r.source.OpenFile(name, flag, perm)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFs) Open(n string) (File, error) {
|
|
|
|
return r.source.Open(n)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFs) Mkdir(n string, p os.FileMode) error {
|
2022-05-03 17:06:13 +03:00
|
|
|
return os.ErrPermission
|
2016-01-11 23:31:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFs) MkdirAll(n string, p os.FileMode) error {
|
2022-05-03 17:06:13 +03:00
|
|
|
return os.ErrPermission
|
2016-01-11 23:31:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReadOnlyFs) Create(n string) (File, error) {
|
2022-05-03 17:06:13 +03:00
|
|
|
return nil, os.ErrPermission
|
2016-01-11 23:31:07 +03:00
|
|
|
}
|