aboutsummaryrefslogtreecommitdiff
path: root/hotline
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-25 20:51:16 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-25 20:51:16 -0700
commitb8c0a83a87eb108e8dfe02fd08c234087f166f04 (patch)
treecb8285cab4a7aeaf2da662804e4a2a945b4d0ff0 /hotline
parent264b7c27c7a46e2d0eb699812c8e38cf771fcf00 (diff)
Add config option to specify ignored filename patterns
Diffstat (limited to 'hotline')
-rw-r--r--hotline/config.go1
-rw-r--r--hotline/files.go20
-rw-r--r--hotline/transaction_handlers.go2
3 files changed, 18 insertions, 5 deletions
diff --git a/hotline/config.go b/hotline/config.go
index d6d801e..aeae275 100644
--- a/hotline/config.go
+++ b/hotline/config.go
@@ -13,4 +13,5 @@ type Config struct {
MaxDownloadsPerClient int `yaml:"MaxDownloadsPerClient"` // Per client simultaneous download limit
MaxConnectionsPerIP int `yaml:"MaxConnectionsPerIP"` // Max connections per IP
PreserveResourceForks bool `yaml:"PreserveResourceForks"` // Enable preservation of file info and resource forks in sidecar files
+ IgnoreFiles []string `yaml:"IgnoreFiles"` // List of regular expression for filtering files from the file list
}
diff --git a/hotline/files.go b/hotline/files.go
index dc19653..aa248f8 100644
--- a/hotline/files.go
+++ b/hotline/files.go
@@ -7,6 +7,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
+ "regexp"
"strings"
)
@@ -30,7 +31,7 @@ func fileTypeFromInfo(info fs.FileInfo) (ft fileType, err error) {
return ft, nil
}
-func getFileNameList(path string) (fields []Field, err error) {
+func getFileNameList(path string, ignoreList []string) (fields []Field, err error) {
files, err := os.ReadDir(path)
if err != nil {
return fields, nil
@@ -39,7 +40,7 @@ func getFileNameList(path string) (fields []Field, err error) {
for _, file := range files {
var fnwi FileNameWithInfo
- if strings.HasPrefix(file.Name(), ".") {
+ if ignoreFile(file.Name(), ignoreList) {
continue
}
@@ -72,7 +73,7 @@ func getFileNameList(path string) (fields []Field, err error) {
var c uint32
for _, f := range dir {
- if !strings.HasPrefix(f.Name(), ".") {
+ if !ignoreFile(f.Name(), ignoreList) {
c += 1
}
}
@@ -94,7 +95,7 @@ func getFileNameList(path string) (fields []Field, err error) {
var c uint32
for _, f := range dir {
- if !strings.HasPrefix(f.Name(), ".") {
+ if !ignoreFile(f.Name(), ignoreList) {
c += 1
}
}
@@ -201,3 +202,14 @@ func EncodeFilePath(filePath string) []byte {
return bytes
}
+
+func ignoreFile(fileName string, ignoreList []string) bool {
+ // skip files that match any regular expression present in the IgnoreFiles list
+ matchIgnoreFilter := 0
+ for _, pattern := range ignoreList {
+ if match, _ := regexp.MatchString(pattern, fileName); match {
+ matchIgnoreFilter += 1
+ }
+ }
+ return matchIgnoreFilter > 0
+}
diff --git a/hotline/transaction_handlers.go b/hotline/transaction_handlers.go
index 2a81768..412868c 100644
--- a/hotline/transaction_handlers.go
+++ b/hotline/transaction_handlers.go
@@ -1668,7 +1668,7 @@ func HandleGetFileNameList(cc *ClientConn, t *Transaction) (res []Transaction, e
return res, err
}
- fileNames, err := getFileNameList(fullPath)
+ fileNames, err := getFileNameList(fullPath, cc.Server.Config.IgnoreFiles)
if err != nil {
return res, err
}