feat: agent-side global exclusions configuration matching Karen's Replicator Other Settings

This commit is contained in:
Carlos Tello
2026-08-17 00:32:44 -03:00
parent 2cb23591ee
commit bf68cd2a74
4 changed files with 52 additions and 5 deletions
+1
View File
@@ -45,6 +45,7 @@ class AgentConfig(BaseModel):
min_stable_time_seconds: int = 60
log_level: str = "INFO"
local_folders: List[LocalFolderJob] = []
enable_global_exclusions: bool = True
# Notification preferences (configurable from GUI and Tray)
enable_notifications: bool = True
+27 -4
View File
@@ -48,6 +48,18 @@ def is_file_stable(filepath: Path, min_stable_seconds: int = 60, sample_interval
import platform
import stat
DEFAULT_GLOBAL_EXCLUSIONS = [
"pagefile.sys",
"hiberfil.sys",
"thumbs.db",
"desktop.ini",
"recycle.bin",
"recycler",
"$recycle.bin",
"temp",
"*.tmp"
]
class DirectoryScanner:
"""Scans Windows source paths for files matching specific backup patterns."""
@@ -59,7 +71,8 @@ class DirectoryScanner:
skip_hidden: bool = False,
skip_system: bool = False,
skip_readonly: bool = False,
min_stable_seconds: int = 60
min_stable_seconds: int = 60,
enable_global_exclusions: bool = True
):
self.source_path = Path(source_path).resolve()
self.patterns = [p.strip() for p in file_patterns.split(",") if p.strip()]
@@ -68,6 +81,7 @@ class DirectoryScanner:
self.skip_system = skip_system
self.skip_readonly = skip_readonly
self.min_stable_seconds = min_stable_seconds
self.enable_global_exclusions = enable_global_exclusions
def scan(self) -> List[Path]:
"""Returns list of all matching files that are stable and ready for backup."""
@@ -78,16 +92,19 @@ class DirectoryScanner:
if self.source_path.is_file():
if self._matches_patterns(self.source_path.name) and not self._matches_exclude(self.source_path.name):
if not self._should_skip_by_attributes(self.source_path):
matched_files.append(self.source_path)
if not (self.enable_global_exclusions and self._is_globally_excluded(self.source_path.name)):
if not self._should_skip_by_attributes(self.source_path):
matched_files.append(self.source_path)
return matched_files
for root, dirs, files in os.walk(self.source_path):
# Prune excluded directories from search in-place
dirs[:] = [d for d in dirs if not self._matches_exclude(d)]
dirs[:] = [d for d in dirs if not self._matches_exclude(d) and not (self.enable_global_exclusions and self._is_globally_excluded(d))]
for file in files:
if self._matches_patterns(file) and not self._matches_exclude(file):
if self.enable_global_exclusions and self._is_globally_excluded(file):
continue
full_path = Path(root) / file
if not self._should_skip_by_attributes(full_path):
matched_files.append(full_path)
@@ -108,6 +125,12 @@ class DirectoryScanner:
return True
return False
def _is_globally_excluded(self, name: str) -> bool:
for pattern in DEFAULT_GLOBAL_EXCLUSIONS:
if fnmatch.fnmatch(name.lower(), pattern.lower()):
return True
return False
def _should_skip_by_attributes(self, filepath: Path) -> bool:
if platform.system() != "Windows":
return False
+2 -1
View File
@@ -416,7 +416,8 @@ class AgentDaemon:
skip_hidden=getattr(job, "skip_hidden", False),
skip_system=getattr(job, "skip_system", False),
skip_readonly=getattr(job, "skip_readonly", False),
min_stable_seconds=min_stable
min_stable_seconds=min_stable,
enable_global_exclusions=getattr(self.config, "enable_global_exclusions", True)
)
files = scanner.scan()