moving a function and struct over to a common library, starting on lockfile for server

This commit is contained in:
2020-06-07 23:26:13 -04:00
parent 6d738b138d
commit b2238657c8
12 changed files with 123 additions and 119 deletions

37
common/commonlib.go Normal file
View File

@@ -0,0 +1,37 @@
package common
import (
"fmt"
"path/filepath"
)
// CheckFileTypes allows the server and client to do some basic validation on adding/removing file types to the toml file
func CheckFileTypes(input string, inputType string, ignores FileTypes) error {
switch inputType {
case "file":
fileExt := filepath.Ext(input) // TODO more sanity checking on ext
for _, ignoredExt := range ignores.Exts {
if fileExt == ignoredExt {
return fmt.Errorf("file ext is on ignored list, cannot add file with file ext %s", fileExt)
}
}
for _, ignoredFile := range ignores.Files {
if input == ignoredFile {
return fmt.Errorf("file name is on ignored list, cannot add file with name %s", input)
}
}
case "folder":
for _, ignoredFolder := range ignores.Folders {
if input == ignoredFolder {
return fmt.Errorf("folder name is on the ignored list, cannot add folder with name %s", input)
}
}
case "wildcard":
for _, ignoredExt := range ignores.Exts {
if input == ignoredExt {
return fmt.Errorf("cannot add wildcard, since that ext is already added to the ignore config %s", input)
}
}
}
return nil
}