Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regexpfs: always use file name instead of path #310

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion regexpfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package afero

import (
"os"
"path/filepath"
"regexp"
"syscall"
"time"
Expand Down Expand Up @@ -29,7 +30,7 @@ func (r *RegexpFs) matchesName(name string) error {
if r.re == nil {
return nil
}
if r.re.MatchString(name) {
if r.re.MatchString(filepath.Base(name)) {
return nil
}
return syscall.ENOENT
Expand Down
18 changes: 18 additions & 0 deletions ro_regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,21 @@ func TestFilterRegexReadDir(t *testing.T) {
t.Errorf("Got wrong number of names: %v", names)
}
}

func TestFilterRegexTarget(t *testing.T) {
mfs := &MemMapFs{}
fs := &RegexpFs{re: regexp.MustCompile(`^a`), source: mfs}

mfs.MkdirAll("/dir/", 0777)

_, err := fs.Create("a.txt")
if err != nil {
t.Errorf("Got unexpected error: %#err", err)
}

// regexp is applied with file name (not file path)
_, err = fs.Create("/dir/a.txt")
if err != nil {
t.Errorf("Got unexpected error: %#err", err)
}
}