mirror of
https://github.com/gilbertchen/duplicacy
synced 2025-12-10 21:33:19 +00:00
Remove runtime OS check for excluding by attributes
This commit is contained in:
@@ -1255,7 +1255,7 @@ func copySnapshots(context *cli.Context) {
|
||||
destinationStorage.SetRateLimits(0, context.Int("upload-limit-rate"))
|
||||
|
||||
destinationManager := duplicacy.CreateBackupManager(destination.SnapshotID, destinationStorage, repository,
|
||||
destinationPassword, "", "", fasle)
|
||||
destinationPassword, "", "", false)
|
||||
duplicacy.SavePassword(*destination, "password", destinationPassword)
|
||||
destinationManager.SetupSnapshotCache(destination.Name)
|
||||
|
||||
|
||||
@@ -200,6 +200,10 @@ func (manager *BackupManager) Backup(top string, quickMode bool, threads int, ta
|
||||
LOG_INFO("BACKUP_KEY", "RSA encryption is enabled")
|
||||
}
|
||||
|
||||
if manager.excludeByAttribute {
|
||||
LOG_INFO("BACKUP_EXCLUDE", "Exclude files with no-backup attributes")
|
||||
}
|
||||
|
||||
remoteSnapshot := manager.SnapshotManager.downloadLatestSnapshot(manager.snapshotID)
|
||||
if remoteSnapshot == nil {
|
||||
remoteSnapshot = CreateEmptySnapshot(manager.snapshotID)
|
||||
|
||||
@@ -28,29 +28,6 @@ var fileModeMask = os.ModePerm | os.ModeSetuid | os.ModeSetgid | os.ModeSticky
|
||||
// Regex for matching 'StartChunk:StartOffset:EndChunk:EndOffset'
|
||||
var contentRegex = regexp.MustCompile(`^([0-9]+):([0-9]+):([0-9]+):([0-9]+)`)
|
||||
|
||||
// AttributeExcludeName attribute name to determine file exclusion
|
||||
var AttributeExcludeName = getDefaultAttributeExcludeName()
|
||||
|
||||
// AttributeExcludeValue attribute value to determine file exclusion
|
||||
var AttributeExcludeValue = getDefaultAttributeExcludeValue()
|
||||
|
||||
func getDefaultAttributeExcludeName() string {
|
||||
if runtime.GOOS == "darwin" {
|
||||
return "com.apple.metadata:com_apple_backup_excludeItem"
|
||||
}
|
||||
if runtime.GOOS == "linux" {
|
||||
return "duplicacy_exclude"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func getDefaultAttributeExcludeValue() string {
|
||||
if runtime.GOOS == "darwin" {
|
||||
return "com.apple.backupd"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Entry encapsulates information about a file or directory.
|
||||
type Entry struct {
|
||||
Path string
|
||||
@@ -547,16 +524,10 @@ func ListEntries(top string, path string, fileList *[]*Entry, patterns []string,
|
||||
entry.ReadAttributes(top)
|
||||
}
|
||||
|
||||
if excludeByAttribute && (runtime.GOOS == "darwin" || runtime.GOOS == "linux") {
|
||||
attrValue, ok := entry.Attributes[AttributeExcludeName]
|
||||
if ok {
|
||||
attrValueString := string(attrValue)
|
||||
if strings.Contains(attrValueString, AttributeExcludeValue) {
|
||||
LOG_WARN("LIST_NOBACKUPXATTR", "%s is excluded due to extended attribute: %s", entry.Path, AttributeExcludeName)
|
||||
if excludeByAttribute && excludedByAttribute(entry.Attributes) {
|
||||
LOG_DEBUG("LIST_EXCLUDE", "%s is excluded by attribute", entry.Path)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if f.Mode()&(os.ModeNamedPipe|os.ModeSocket|os.ModeDevice) != 0 {
|
||||
LOG_WARN("LIST_SKIP", "Skipped non-regular file %s", entry.Path)
|
||||
|
||||
@@ -58,7 +58,7 @@ func CreateEmptySnapshot(id string) (snapshto *Snapshot) {
|
||||
|
||||
// CreateSnapshotFromDirectory creates a snapshot from the local directory 'top'. Only 'Files'
|
||||
// will be constructed, while 'ChunkHashes' and 'ChunkLengths' can only be populated after uploading.
|
||||
func CreateSnapshotFromDirectory(id string, top string, nobackupFile string, filtersFile string, , excludeByAttribute bool) (snapshot *Snapshot, skippedDirectories []string,
|
||||
func CreateSnapshotFromDirectory(id string, top string, nobackupFile string, filtersFile string, excludeByAttribute bool) (snapshot *Snapshot, skippedDirectories []string,
|
||||
skippedFiles []string, err error) {
|
||||
|
||||
snapshot = &Snapshot{
|
||||
|
||||
14
src/duplicacy_utils_darwin.go
Normal file
14
src/duplicacy_utils_darwin.go
Normal file
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) Acrosync LLC. All rights reserved.
|
||||
// Free for personal use and commercial trial
|
||||
// Commercial use requires per-user licenses available from https://duplicacy.com
|
||||
|
||||
package duplicacy
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func excludedByAttribute(attirbutes map[string][]byte) bool {
|
||||
value, ok := attirbutes["com.apple.metadata:com_apple_backup_excludeItem"]
|
||||
return ok && strings.Contains(string(value), "com.apple.backupd")
|
||||
}
|
||||
13
src/duplicacy_utils_linux.go
Normal file
13
src/duplicacy_utils_linux.go
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) Acrosync LLC. All rights reserved.
|
||||
// Free for personal use and commercial trial
|
||||
// Commercial use requires per-user licenses available from https://duplicacy.com
|
||||
|
||||
package duplicacy
|
||||
|
||||
import (
|
||||
)
|
||||
|
||||
func excludedByAttribute(attirbutes map[string][]byte) bool {
|
||||
_, ok := attirbutes["duplicacy_exclude"]
|
||||
return ok
|
||||
}
|
||||
@@ -131,3 +131,7 @@ func SplitDir(fullPath string) (dir string, file string) {
|
||||
i := strings.LastIndex(fullPath, "\\")
|
||||
return fullPath[:i+1], fullPath[i+1:]
|
||||
}
|
||||
|
||||
func excludedByAttribute(attirbutes map[string][]byte) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user