]> git.r.bdr.sh - rbdr/mobius/commitdiff
Merge pull request #45 from jhalter/add_ignorefiles_option
authorJeff Halter <redacted>
Sun, 26 Jun 2022 03:53:36 +0000 (20:53 -0700)
committerGitHub <redacted>
Sun, 26 Jun 2022 03:53:36 +0000 (20:53 -0700)
Add config option to specify ignored filename patterns

cmd/mobius-hotline-server/mobius/config/config.yaml
hotline/config.go
hotline/files.go
hotline/transaction_handlers.go

index a903023f587a442dd3c694e747efafc44eee2ffb..3ca812162578099a1e38251c2480c534428b3249 100644 (file)
@@ -19,8 +19,8 @@ EnableTrackerRegistration: false
 
 # List of trackers to register with
 Trackers:
-- hltracker.com:5499
-- tracker.preterhuman.net:5499
+  - hltracker.com:5499
+  - tracker.preterhuman.net:5499
 
 # Preserve resource forks and file type/creator codes for files uploaded by Macintosh clients.
 # This comes with trade-offs.  For more details, see:
@@ -42,3 +42,8 @@ MaxDownloadsPerClient: 0
 
 # Maximum simultaneous connections/IP; currently unimplemented
 MaxConnectionsPerIP: 0
+
+# List of Regular Expression filters for the Files list
+IgnoreFiles:
+  - '^\.*'     # Ignore all files starting with ".".  Leave this set if you are using the PreserveResourceForks option.
+  - '^@'       # Ignore all files starting with "@"
\ No newline at end of file
index d6d801e92a9956edcdf9b16e1b65d917103b5751..aeae27534716eb6d11af1ec9856a2e8981f0bc1b 100644 (file)
@@ -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
 }
index dc196536d8b7abfc870c07f96ecb0dbc2a48eef5..aa248f81893f06ca0d61e2b27e0f106a9b707c10 100644 (file)
@@ -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
+}
index 2a817687f531ca774fac3c33641550542826699e..412868c8d62242e0118cce93b797e91709ab6e8b 100644 (file)
@@ -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
        }