diff --git a/EasyBackupAvalonia/Helpers/BackupPerformer.cs b/EasyBackupAvalonia/Helpers/BackupPerformer.cs index f2e3c8a..7b9661f 100644 --- a/EasyBackupAvalonia/Helpers/BackupPerformer.cs +++ b/EasyBackupAvalonia/Helpers/BackupPerformer.cs @@ -53,6 +53,8 @@ class BackupPerformer private EnumerationOptions _enumerationOptions; + private string _backupDirectory; + public BackupPerformer() { IsRunning = false; @@ -71,6 +73,7 @@ public BackupPerformer() AttributesToSkip = 0, }; _pathsCopiedTo = new Dictionary(); + _backupDirectory = ""; } public void Cancel() @@ -161,6 +164,10 @@ private void CopyDirectory(FolderFileItem itemBeingCopied, string sourceDirName, } if (!_directoryPathsSeen.Contains(subDir.FullName)) { + if (!string.IsNullOrWhiteSpace(_backupDirectory) && !subDir.FullName.StartsWith(_backupDirectory)) + { + continue; // don't back up backup directory + } string temppath = Path.Combine(destDirName, subDir.Name); if (ShouldAllowPath(excludedPaths, subDir.FullName)) { @@ -209,6 +216,10 @@ private Dictionary GetFilePathsAndSizesInDirectory(string sourceD } if (!_directoryPathsSeen.Contains(subDir.FullName)) { + if (!string.IsNullOrWhiteSpace(_backupDirectory) && !subDir.FullName.StartsWith(_backupDirectory)) + { + continue; // don't back up backup directory + } if (ShouldAllowPath(excludedPaths, subDir.FullName)) { var additionalFileInfo = GetFilePathsAndSizesInDirectory(subDir.FullName, searchSubDirs); @@ -582,6 +593,7 @@ private void IterateOverFiles(List paths, string backupDirectory throw new Exception("Couldn't create backup directory (directory already exists)"); } } + _backupDirectory = backupDirectory; // ok, start copying the files if not using compressed file. if (!UsesCompressedFile || _isCalculatingFileSize) { @@ -602,7 +614,6 @@ private void IterateOverFiles(List paths, string backupDirectory else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - // Do something if (directoryName.StartsWith(pathRoot)) { directoryName = directoryName.Substring(1);