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"
)
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),

View File

@ -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{"*"}
}
}

View File

@ -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

View File

@ -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]

View File

@ -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
}