Rename mask to pattern

This commit is contained in:
nxshock 2023-03-19 12:18:33 +05:00
parent 71ee59c4fc
commit 8e1c69fdea
5 changed files with 20 additions and 20 deletions

View File

@ -14,14 +14,14 @@ import (
"github.com/nxshock/progressmessage" "github.com/nxshock/progressmessage"
) )
type Mask struct { type Pattern struct {
Path string Path string
// Маски имени файла // Маски имени файла
FileNameMaskList []string FileNamePatternList []string
// Маски пути // Маски пути
FilePathMaskList []string FilePathPatternList []string
// Вкючать файлы в покаталогах // Вкючать файлы в покаталогах
Recursive bool Recursive bool
@ -169,7 +169,7 @@ func (b *Config) doBackup(index *Index) error {
func (b *Config) fileList(fileNames chan File) { func (b *Config) fileList(fileNames chan File) {
errorCount := 0 errorCount := 0
for _, mask := range b.Masks { for _, mask := range b.Patterns {
if mask.Recursive { if mask.Recursive {
err := filepath.WalkDir(mask.Path, func(path string, d fs.DirEntry, err error) error { err := filepath.WalkDir(mask.Path, func(path string, d fs.DirEntry, err error) error {
if err != nil { if err != nil {
@ -191,8 +191,8 @@ func (b *Config) fileList(fileNames chan File) {
return nil return nil
} }
if isFilePathMatchMasks(mask.FilePathMaskList, path) && isFileNameMatchMasks(mask.FileNameMaskList, path) { if isFilePathMatchPatterns(mask.FilePathPatternList, path) && isFileNameMatchPatterns(mask.FileNamePatternList, path) {
if !isFilePathMatchMasks(b.GlobalExcludeFilePathMasks, path) && !isFileNameMatchMasks(b.GlobalExcludeFileNameMasks, path) { if !isFilePathMatchPatterns(b.GlobalExcludeFilePathPatterns, path) && !isFileNameMatchPatterns(b.GlobalExcludeFileNamePatterns, path) {
info, err := os.Stat(path) info, err := os.Stat(path)
if err != nil { if err != nil {
errorCount++ errorCount++
@ -236,8 +236,8 @@ func (b *Config) fileList(fileNames chan File) {
//fileName := filepath.Base(fileOrDirPath) //fileName := filepath.Base(fileOrDirPath)
fileName := fileOrDirPath // TODO: тестирование, маска должна накладываться на путь fileName := fileOrDirPath // TODO: тестирование, маска должна накладываться на путь
if isFilePathMatchMasks(mask.FilePathMaskList, fileName) && isFileNameMatchMasks(mask.FileNameMaskList, fileName) { if isFilePathMatchPatterns(mask.FilePathPatternList, fileName) && isFileNameMatchPatterns(mask.FileNamePatternList, fileName) {
if !isFilePathMatchMasks(b.GlobalExcludeFilePathMasks, fileName) && !isFileNameMatchMasks(b.GlobalExcludeFileNameMasks, fileName) { if !isFilePathMatchPatterns(b.GlobalExcludeFilePathPatterns, fileName) && !isFileNameMatchPatterns(b.GlobalExcludeFileNamePatterns, fileName) {
file := File{ file := File{
SourcePath: fileOrDirPath, SourcePath: fileOrDirPath,
DestinationPath: filepath.ToSlash(fileOrDirPath), DestinationPath: filepath.ToSlash(fileOrDirPath),

View File

@ -19,13 +19,13 @@ type Config struct {
FileName string FileName string
// Маски файлов для включения в архив // Маски файлов для включения в архив
Masks []*Mask Patterns []*Pattern
// Маски файлов для исключения // Маски файлов для исключения
GlobalExcludeFileNameMasks []string GlobalExcludeFileNamePatterns []string
// Маски путей для исключения // Маски путей для исключения
GlobalExcludeFilePathMasks []string GlobalExcludeFilePathPatterns []string
// Логгер // Логгер
Logger LoggerConfig Logger LoggerConfig
@ -73,9 +73,9 @@ func LoadConfig(filePath string) (*Config, error) {
config.logger = Logger{logger: log.New(os.Stderr, "", 0), MinimalLogLevel: config.Logger.MinimalLogLevel} config.logger = Logger{logger: log.New(os.Stderr, "", 0), MinimalLogLevel: config.Logger.MinimalLogLevel}
for _, mask := range config.Masks { for _, mask := range config.Patterns {
if len(mask.FilePathMaskList) == 0 { if len(mask.FilePathPatternList) == 0 {
mask.FilePathMaskList = []string{"*"} mask.FilePathPatternList = []string{"*"}
} }
} }

View File

@ -6,5 +6,5 @@ MinimalLogLevel = 1
[[Masks]] [[Masks]]
Path = "/home/user/go/src" Path = "/home/user/go/src"
FileNameMaskList = ["*.go", "go.mod", "go.sum"] FileNamePatternList = ["*.go", "go.mod", "go.sum"]
Recursive = true Recursive = true

View File

@ -69,7 +69,7 @@ func (index *Index) GetFilesLocation(mask string, t time.Time) ([]File, error) {
var files2 []File var files2 []File
for fileName := range index.Files { for fileName := range index.Files {
if isFilePathMatchMasks([]string{mask}, fileName) { if isFilePathMatchPatterns([]string{mask}, fileName) {
files := index.Files[fileName] files := index.Files[fileName]
file := files[0] file := files[0]

View File

@ -57,8 +57,8 @@ func stringIn(s string, ss []string) (bool, int) {
return false, -1 return false, -1
} }
func isFileNameMatchMasks(masks []string, fileName string) bool { func isFileNameMatchPatterns(patterns []string, fileName string) bool {
for _, mask := range masks { for _, mask := range patterns {
if match.Match(filepath.Base(fileName), mask) { if match.Match(filepath.Base(fileName), mask) {
return true return true
} }
@ -67,8 +67,8 @@ func isFileNameMatchMasks(masks []string, fileName string) bool {
return false return false
} }
func isFilePathMatchMasks(masks []string, fileName string) bool { func isFilePathMatchPatterns(patterns []string, fileName string) bool {
for _, mask := range masks { for _, mask := range patterns {
if match.Match(fileName, mask) { if match.Match(fileName, mask) {
return true return true
} }