Skip to content

Commit

Permalink
Fix infinite recursion backups
Browse files Browse the repository at this point in the history
Closes #12
  • Loading branch information
Deadpikle committed Jul 31, 2024
1 parent 0457a5b commit 84cf4af
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion EasyBackupAvalonia/Helpers/BackupPerformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class BackupPerformer

private EnumerationOptions _enumerationOptions;

private string _backupDirectory;

public BackupPerformer()
{
IsRunning = false;
Expand All @@ -71,6 +73,7 @@ public BackupPerformer()
AttributesToSkip = 0,
};
_pathsCopiedTo = new Dictionary<string, bool>();
_backupDirectory = "";
}

public void Cancel()
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -209,6 +216,10 @@ private Dictionary<string, ulong> 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);
Expand Down Expand Up @@ -582,6 +593,7 @@ private void IterateOverFiles(List<FolderFileItem> 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)
{
Expand All @@ -602,7 +614,6 @@ private void IterateOverFiles(List<FolderFileItem> paths, string backupDirectory
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ||
RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// Do something
if (directoryName.StartsWith(pathRoot))
{
directoryName = directoryName.Substring(1);
Expand Down

0 comments on commit 84cf4af

Please sign in to comment.