diff --git a/backuper.go b/backuper.go index 3848d03..a83f8e8 100644 --- a/backuper.go +++ b/backuper.go @@ -14,14 +14,14 @@ import ( "github.com/nxshock/progressmessage" ) -type Mask struct { +type Pattern struct { Path string // Маски имени файла - FileNameMaskList []string + FileNamePatternList []string // Маски пути - FilePathMaskList []string + FilePathPatternList []string // Вкючать файлы в покаталогах Recursive bool @@ -169,7 +169,7 @@ func (b *Config) doBackup(index *Index) error { func (b *Config) fileList(fileNames chan File) { errorCount := 0 - for _, mask := range b.Masks { + for _, mask := range b.Patterns { if mask.Recursive { err := filepath.WalkDir(mask.Path, func(path string, d fs.DirEntry, err error) error { if err != nil { @@ -191,8 +191,8 @@ func (b *Config) fileList(fileNames chan File) { return nil } - if isFilePathMatchMasks(mask.FilePathMaskList, path) && isFileNameMatchMasks(mask.FileNameMaskList, path) { - if !isFilePathMatchMasks(b.GlobalExcludeFilePathMasks, path) && !isFileNameMatchMasks(b.GlobalExcludeFileNameMasks, path) { + if isFilePathMatchPatterns(mask.FilePathPatternList, path) && isFileNameMatchPatterns(mask.FileNamePatternList, path) { + if !isFilePathMatchPatterns(b.GlobalExcludeFilePathPatterns, path) && !isFileNameMatchPatterns(b.GlobalExcludeFileNamePatterns, path) { info, err := os.Stat(path) if err != nil { errorCount++ @@ -236,8 +236,8 @@ func (b *Config) fileList(fileNames chan File) { //fileName := filepath.Base(fileOrDirPath) fileName := fileOrDirPath // TODO: тестирование, маска должна накладываться на путь - if isFilePathMatchMasks(mask.FilePathMaskList, fileName) && isFileNameMatchMasks(mask.FileNameMaskList, fileName) { - if !isFilePathMatchMasks(b.GlobalExcludeFilePathMasks, fileName) && !isFileNameMatchMasks(b.GlobalExcludeFileNameMasks, fileName) { + if isFilePathMatchPatterns(mask.FilePathPatternList, fileName) && isFileNameMatchPatterns(mask.FileNamePatternList, fileName) { + if !isFilePathMatchPatterns(b.GlobalExcludeFilePathPatterns, fileName) && !isFileNameMatchPatterns(b.GlobalExcludeFileNamePatterns, fileName) { file := File{ SourcePath: fileOrDirPath, DestinationPath: filepath.ToSlash(fileOrDirPath), diff --git a/config.go b/config.go index 277276e..e14cfef 100644 --- a/config.go +++ b/config.go @@ -19,13 +19,13 @@ type Config struct { FileName string // Маски файлов для включения в архив - Masks []*Mask + Patterns []*Pattern // Маски файлов для исключения - GlobalExcludeFileNameMasks []string + GlobalExcludeFileNamePatterns []string // Маски путей для исключения - GlobalExcludeFilePathMasks []string + GlobalExcludeFilePathPatterns []string // Логгер 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} - for _, mask := range config.Masks { - if len(mask.FilePathMaskList) == 0 { - mask.FilePathMaskList = []string{"*"} + for _, mask := range config.Patterns { + if len(mask.FilePathPatternList) == 0 { + mask.FilePathPatternList = []string{"*"} } } diff --git a/examples/config.toml b/examples/config.toml index 84e43a2..3654dbf 100644 --- a/examples/config.toml +++ b/examples/config.toml @@ -6,5 +6,5 @@ MinimalLogLevel = 1 [[Masks]] Path = "/home/user/go/src" -FileNameMaskList = ["*.go", "go.mod", "go.sum"] +FileNamePatternList = ["*.go", "go.mod", "go.sum"] Recursive = true diff --git a/index.go b/index.go index 169f39e..dc48b6d 100644 --- a/index.go +++ b/index.go @@ -69,7 +69,7 @@ func (index *Index) GetFilesLocation(mask string, t time.Time) ([]File, error) { var files2 []File for fileName := range index.Files { - if isFilePathMatchMasks([]string{mask}, fileName) { + if isFilePathMatchPatterns([]string{mask}, fileName) { files := index.Files[fileName] file := files[0] diff --git a/utils.go b/utils.go index 3d16c99..66b403d 100644 --- a/utils.go +++ b/utils.go @@ -57,8 +57,8 @@ func stringIn(s string, ss []string) (bool, int) { return false, -1 } -func isFileNameMatchMasks(masks []string, fileName string) bool { - for _, mask := range masks { +func isFileNameMatchPatterns(patterns []string, fileName string) bool { + for _, mask := range patterns { if match.Match(filepath.Base(fileName), mask) { return true } @@ -67,8 +67,8 @@ func isFileNameMatchMasks(masks []string, fileName string) bool { return false } -func isFilePathMatchMasks(masks []string, fileName string) bool { - for _, mask := range masks { +func isFilePathMatchPatterns(patterns []string, fileName string) bool { + for _, mask := range patterns { if match.Match(fileName, mask) { return true }