drop filter_regexp for now, needs some more changes for reading dirs

This commit is contained in:
Hanno Hecker 2015-12-15 18:17:36 +01:00
parent 8c337dcc24
commit 03c0cb5702
2 changed files with 3 additions and 106 deletions

View File

@ -1,104 +0,0 @@
package afero
import (
"os"
"regexp"
"syscall"
"time"
)
type RegexpFilter struct {
file *regexp.Regexp
dir *regexp.Regexp
}
func NewRegexpFilter(file *regexp.Regexp, dir *regexp.Regexp) Fs {
return &RegexpFilter{file: file, dir: dir}
}
func (r *RegexpFilter) Chtimes(n string, a, m time.Time) error {
if !r.file.MatchString(n) {
return syscall.ENOENT
}
return nil
}
func (r *RegexpFilter) Chmod(n string, m os.FileMode) error {
if !r.file.MatchString(n) {
return syscall.ENOENT
}
return nil
}
func (r *RegexpFilter) Name() string {
return "RegexpFilter"
}
func (r *RegexpFilter) Stat(n string) (os.FileInfo, error) {
// FIXME - what about Stat() on dirs?
if !r.file.MatchString(n) {
return nil, syscall.ENOENT
}
return nil, nil
}
func (r *RegexpFilter) Rename(o, n string) error {
// FIXME - what about renaming dirs?
switch {
case !r.file.MatchString(o):
return syscall.ENOENT
case !r.file.MatchString(n):
return syscall.EPERM
default:
return nil
}
}
func (r *RegexpFilter) RemoveAll(p string) error {
if !r.dir.MatchString(p) {
return syscall.EPERM // FIXME ENOENT?
}
return nil
}
func (r *RegexpFilter) Remove(n string) error {
if !r.file.MatchString(n) {
return syscall.ENOENT
}
return nil
}
func (r *RegexpFilter) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
if !r.file.MatchString(name) {
return nil, syscall.ENOENT
}
return nil, nil
}
func (r *RegexpFilter) Open(n string) (File, error) {
if !r.file.MatchString(n) {
return nil, syscall.ENOENT
}
return nil, nil
}
func (r *RegexpFilter) Mkdir(n string, p os.FileMode) error {
if !r.dir.MatchString(n) {
return syscall.EPERM
}
return nil
}
func (r *RegexpFilter) MkdirAll(n string, p os.FileMode) error {
if !r.dir.MatchString(n) {
return syscall.EPERM
}
return nil
}
func (r *RegexpFilter) Create(n string) (File, error) {
if !r.file.MatchString(n) {
return nil, syscall.EPERM
}
return nil, nil
}

View File

@ -1,7 +1,7 @@
package afero package afero
import ( import (
"regexp" // "regexp"
"testing" "testing"
) )
@ -52,7 +52,7 @@ func TestReadonlyRemoveAndRead(t *testing.T) {
t.Errorf("File still present") t.Errorf("File still present")
} }
} }
/*
func TestRegexp(t *testing.T) { func TestRegexp(t *testing.T) {
mfs := &MemMapFs{} mfs := &MemMapFs{}
fs := NewFilter(mfs) fs := NewFilter(mfs)
@ -75,3 +75,4 @@ func TestRORegexpChain(t *testing.T) {
} }
t.Logf("ERR=%s", err) t.Logf("ERR=%s", err)
} }
*/