Skip to content

Commit

Permalink
Make fileRegister a set (#1653)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturmelanchyk authored Dec 24, 2024
1 parent b335ed3 commit 7403860
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Andrew Reid <andrew.reid at tixtrack.com>
Animesh Ray <mail.rayanimesh at gmail.com>
Arne Hormann <arnehormann at gmail.com>
Ariel Mashraki <ariel at mashraki.co.il>
Artur Melanchyk <[email protected]>
Asta Xie <xiemengjun at gmail.com>
B Lamarche <blam413 at gmail.com>
Brian Hendriks <brian at dolthub.com>
Expand Down
10 changes: 5 additions & 5 deletions infile.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

var (
fileRegister map[string]bool
fileRegister map[string]struct{}
fileRegisterLock sync.RWMutex
readerRegister map[string]func() io.Reader
readerRegisterLock sync.RWMutex
Expand All @@ -37,10 +37,10 @@ func RegisterLocalFile(filePath string) {
fileRegisterLock.Lock()
// lazy map init
if fileRegister == nil {
fileRegister = make(map[string]bool)
fileRegister = make(map[string]struct{})
}

fileRegister[strings.Trim(filePath, `"`)] = true
fileRegister[strings.Trim(filePath, `"`)] = struct{}{}
fileRegisterLock.Unlock()
}

Expand Down Expand Up @@ -123,9 +123,9 @@ func (mc *okHandler) handleInFileRequest(name string) (err error) {
} else { // File
name = strings.Trim(name, `"`)
fileRegisterLock.RLock()
fr := fileRegister[name]
_, exists := fileRegister[name]
fileRegisterLock.RUnlock()
if mc.cfg.AllowAllFiles || fr {
if mc.cfg.AllowAllFiles || exists {
var file *os.File
var fi os.FileInfo

Expand Down

0 comments on commit 7403860

Please sign in to comment.