Skip to content

Commit

Permalink
Fixes issues around using "/" or "C:\" as root outgoing directory
Browse files Browse the repository at this point in the history
  • Loading branch information
sbeus committed Feb 20, 2024
1 parent 663113c commit 691230e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ func (s *Server) routeCheckMapping(w http.ResponseWriter, r *http.Request) {
Logger: log.Get(),
}
path := reqBody.ExamplePath
if strings.HasPrefix(path, reqBody.RootPath) {
root := strings.TrimSuffix(strings.TrimSuffix(reqBody.RootPath, "/"), `\`)
if strings.HasPrefix(path, root) {
path = path[len(reqBody.RootPath)+1:]
}
mappedPath := pathMapper.Translate(path)
Expand Down
4 changes: 2 additions & 2 deletions http/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ func TestMisc(t *testing.T) {
payload := map[string]any{
"path": `C:\Data\2024\133.dat`,
"source": source,
"root": `C:\Data`,
"root": `C:\`,
"mapping": []any{
map[string]string{
"from": `^(?P<year>\d{4})\\(?P<day>\d+)\.dat$`,
"from": `(?P<year>\d{4})\\(?P<day>\d+)\.dat$`,
"to": `{{.__source}}.{{parseDayOfYear .year .day | formatDate "Ymd"}}.000000.dat`,
},
},
Expand Down
8 changes: 7 additions & 1 deletion store/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ func (dir *Local) getRelPath(path string) string {
}

func (dir *Local) shouldIgnore(relPath string, isDir bool) bool {
if !dir.IncludeHidden && strings.HasPrefix(filepath.Base(relPath), ".") {
if !dir.IncludeHidden &&
relPath != "" &&
strings.HasPrefix(filepath.Base(relPath), ".") {
return true
}
var pattern *regexp.Regexp
Expand Down Expand Up @@ -181,6 +183,10 @@ func (dir *Local) handleNode(path string, info os.FileInfo, err error) error {
}

relPath := dir.getRelPath(path)
if relPath == "" {
// Root directory
return nil
}
if info.IsDir() {
if dir.shouldIgnore(relPath, true) {
dir.debug("Ignored Local Directory:", path)
Expand Down

0 comments on commit 691230e

Please sign in to comment.