mirror of
https://github.com/jkl1337/duplicacy.git
synced 2026-01-02 19:54:54 -06:00
- Replaced static check for .duplicacy directory with usage of predefined filters.
Do not "misuse" property nobackupFile to trigger this feature. - Restructured ProcessFilterFile function and splitted it in smaller parts. - Prepare usage of new filter syntax for arguments of restore command.
This commit is contained in:
@@ -481,9 +481,6 @@ func ListEntries(top string, path string, fileList *[]*Entry, patterns []string,
|
|||||||
entries := make([]*Entry, 0, 4)
|
entries := make([]*Entry, 0, 4)
|
||||||
|
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
if (f.Name() == DUPLICACY_DIRECTORY) && (nobackupFile == "") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
entry := CreateEntryFromFileInfo(f, normalizedPath)
|
entry := CreateEntryFromFileInfo(f, normalizedPath)
|
||||||
if len(patterns) > 0 && !MatchPath(entry.Path, patterns) {
|
if len(patterns) > 0 && !MatchPath(entry.Path, patterns) {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -69,18 +70,7 @@ func CreateSnapshotFromDirectory(id string, top string, nobackupFile string) (sn
|
|||||||
|
|
||||||
var patterns []string
|
var patterns []string
|
||||||
|
|
||||||
patterns = ProcessFilterFile(path.Join(GetDuplicacyPreferencePath(), "filters"), make([]string, 0))
|
patterns = ProcessFilters()
|
||||||
|
|
||||||
LOG_DEBUG("REGEX_DEBUG", "There are %d compiled regular expressions stored", len(RegexMap))
|
|
||||||
|
|
||||||
LOG_INFO("SNAPSHOT_FILTER", "Loaded %d include/exclude pattern(s)", len(patterns))
|
|
||||||
|
|
||||||
if IsTracing() {
|
|
||||||
for _, pattern := range patterns {
|
|
||||||
LOG_TRACE("SNAPSHOT_PATTERN", "Pattern: %s", pattern)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
directories := make([]*Entry, 0, 256)
|
directories := make([]*Entry, 0, 256)
|
||||||
directories = append(directories, CreateEntry("", 0, 0, 0))
|
directories = append(directories, CreateEntry("", 0, 0, 0))
|
||||||
@@ -122,6 +112,43 @@ func CreateSnapshotFromDirectory(id string, top string, nobackupFile string) (sn
|
|||||||
return snapshot, skippedDirectories, skippedFiles, nil
|
return snapshot, skippedDirectories, skippedFiles, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AppendPattern(patterns []string, new_pattern string) (new_patterns []string) {
|
||||||
|
for _, pattern := range patterns {
|
||||||
|
if pattern == new_pattern {
|
||||||
|
LOG_INFO("SNAPSHOT_FILTER", "Ignoring duplicate pattern: %s ...", new_pattern)
|
||||||
|
return patterns
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new_patterns = append(patterns, new_pattern)
|
||||||
|
return new_patterns
|
||||||
|
}
|
||||||
|
func ProcessFilters() (patterns []string) {
|
||||||
|
patternFileLines := []string{
|
||||||
|
`# ============================ exclude the internal files and directories in all ".duplicacy" subfolders`,
|
||||||
|
`e:(?i)(^|/)` + regexp.QuoteMeta(DUPLICACY_DIRECTORY) + `/cache/`,
|
||||||
|
`e:(?i)(^|/)` + regexp.QuoteMeta(DUPLICACY_DIRECTORY) + `/temporary$`,
|
||||||
|
`# ============================ exclude the internal files and directories in toplevel ".duplicacy" subfolder`,
|
||||||
|
`e:(?i)^` + regexp.QuoteMeta(DUPLICACY_DIRECTORY) + `/incomplete$`,
|
||||||
|
`e:(?i)^` + regexp.QuoteMeta(DUPLICACY_DIRECTORY) + `/logs/`,
|
||||||
|
"@" + joinPath(GetDuplicacyPreferencePath(), "filters"),
|
||||||
|
}
|
||||||
|
LOG_DEBUG("SNAPSHOT_FILTER", "Adding standard filters ...")
|
||||||
|
patterns = ProcessFilterLines(patternFileLines, make([]string, 0))
|
||||||
|
|
||||||
|
LOG_DEBUG("REGEX_DEBUG", "There are %d compiled regular expressions stored", len(RegexMap))
|
||||||
|
|
||||||
|
LOG_INFO("SNAPSHOT_FILTER", "Loaded %d include/exclude pattern(s)", len(patterns))
|
||||||
|
|
||||||
|
if IsTracing() {
|
||||||
|
for _, pattern := range patterns {
|
||||||
|
LOG_TRACE("SNAPSHOT_PATTERN", "Pattern: %s", pattern)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return patterns
|
||||||
|
}
|
||||||
|
|
||||||
func ProcessFilterFile(patternFile string, includedFiles []string) (patterns []string) {
|
func ProcessFilterFile(patternFile string, includedFiles []string) (patterns []string) {
|
||||||
if Contains(includedFiles, patternFile) {
|
if Contains(includedFiles, patternFile) {
|
||||||
// cycle in include mechanism discovered.
|
// cycle in include mechanism discovered.
|
||||||
@@ -132,7 +159,14 @@ func ProcessFilterFile(patternFile string, includedFiles []string) (patterns []s
|
|||||||
LOG_INFO("SNAPSHOT_FILTER", "Parsing filter file %s ...", patternFile)
|
LOG_INFO("SNAPSHOT_FILTER", "Parsing filter file %s ...", patternFile)
|
||||||
patternFileContent, err := ioutil.ReadFile(patternFile)
|
patternFileContent, err := ioutil.ReadFile(patternFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, pattern := range strings.Split(string(patternFileContent), "\n") {
|
patternFileLines := strings.Split(string(patternFileContent), "\n")
|
||||||
|
patterns = ProcessFilterLines(patternFileLines, includedFiles)
|
||||||
|
}
|
||||||
|
return patterns
|
||||||
|
}
|
||||||
|
|
||||||
|
func ProcessFilterLines(patternFileLines []string, includedFiles []string) (patterns []string) {
|
||||||
|
for _, pattern := range patternFileLines {
|
||||||
pattern = strings.TrimSpace(pattern)
|
pattern = strings.TrimSpace(pattern)
|
||||||
if len(pattern) == 0 {
|
if len(pattern) == 0 {
|
||||||
continue
|
continue
|
||||||
@@ -140,11 +174,20 @@ func ProcessFilterFile(patternFile string, includedFiles []string) (patterns []s
|
|||||||
|
|
||||||
if strings.HasPrefix(pattern, "@") {
|
if strings.HasPrefix(pattern, "@") {
|
||||||
patternIncludeFile := strings.TrimSpace(pattern[1:])
|
patternIncludeFile := strings.TrimSpace(pattern[1:])
|
||||||
|
if patternIncludeFile == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if ! filepath.IsAbs(patternIncludeFile) {
|
if ! filepath.IsAbs(patternIncludeFile) {
|
||||||
patternIncludeFile = joinPath(filepath.Dir(patternFile), patternIncludeFile)
|
basePath := ""
|
||||||
|
if len(includedFiles) == 0 {
|
||||||
|
basePath, _ = os.Getwd()
|
||||||
|
} else {
|
||||||
|
basePath = filepath.Dir(includedFiles[len(includedFiles)-1])
|
||||||
|
}
|
||||||
|
patternIncludeFile = joinPath(basePath, patternIncludeFile)
|
||||||
}
|
}
|
||||||
for _, pattern := range ProcessFilterFile(patternIncludeFile, includedFiles) {
|
for _, pattern := range ProcessFilterFile(patternIncludeFile, includedFiles) {
|
||||||
patterns = append(patterns, pattern)
|
patterns = AppendPattern(patterns, pattern)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -168,8 +211,7 @@ func ProcessFilterFile(patternFile string, includedFiles []string) (patterns []s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
patterns = append(patterns, pattern)
|
patterns = AppendPattern(patterns, pattern)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return patterns
|
return patterns
|
||||||
|
|||||||
Reference in New Issue
Block a user