Skip to content

Commit 84cf4af

Browse files
committed
Fix infinite recursion backups
Closes #12
1 parent 0457a5b commit 84cf4af

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

EasyBackupAvalonia/Helpers/BackupPerformer.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class BackupPerformer
5353

5454
private EnumerationOptions _enumerationOptions;
5555

56+
private string _backupDirectory;
57+
5658
public BackupPerformer()
5759
{
5860
IsRunning = false;
@@ -71,6 +73,7 @@ public BackupPerformer()
7173
AttributesToSkip = 0,
7274
};
7375
_pathsCopiedTo = new Dictionary<string, bool>();
76+
_backupDirectory = "";
7477
}
7578

7679
public void Cancel()
@@ -161,6 +164,10 @@ private void CopyDirectory(FolderFileItem itemBeingCopied, string sourceDirName,
161164
}
162165
if (!_directoryPathsSeen.Contains(subDir.FullName))
163166
{
167+
if (!string.IsNullOrWhiteSpace(_backupDirectory) && !subDir.FullName.StartsWith(_backupDirectory))
168+
{
169+
continue; // don't back up backup directory
170+
}
164171
string temppath = Path.Combine(destDirName, subDir.Name);
165172
if (ShouldAllowPath(excludedPaths, subDir.FullName))
166173
{
@@ -209,6 +216,10 @@ private Dictionary<string, ulong> GetFilePathsAndSizesInDirectory(string sourceD
209216
}
210217
if (!_directoryPathsSeen.Contains(subDir.FullName))
211218
{
219+
if (!string.IsNullOrWhiteSpace(_backupDirectory) && !subDir.FullName.StartsWith(_backupDirectory))
220+
{
221+
continue; // don't back up backup directory
222+
}
212223
if (ShouldAllowPath(excludedPaths, subDir.FullName))
213224
{
214225
var additionalFileInfo = GetFilePathsAndSizesInDirectory(subDir.FullName, searchSubDirs);
@@ -582,6 +593,7 @@ private void IterateOverFiles(List<FolderFileItem> paths, string backupDirectory
582593
throw new Exception("Couldn't create backup directory (directory already exists)");
583594
}
584595
}
596+
_backupDirectory = backupDirectory;
585597
// ok, start copying the files if not using compressed file.
586598
if (!UsesCompressedFile || _isCalculatingFileSize)
587599
{
@@ -602,7 +614,6 @@ private void IterateOverFiles(List<FolderFileItem> paths, string backupDirectory
602614
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ||
603615
RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
604616
{
605-
// Do something
606617
if (directoryName.StartsWith(pathRoot))
607618
{
608619
directoryName = directoryName.Substring(1);

0 commit comments

Comments
 (0)