feat: agent-side global exclusions configuration matching Karen's Replicator Other Settings
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user