@@ -53,6 +53,8 @@ class BackupPerformer
53
53
54
54
private EnumerationOptions _enumerationOptions ;
55
55
56
+ private string _backupDirectory ;
57
+
56
58
public BackupPerformer ( )
57
59
{
58
60
IsRunning = false ;
@@ -71,6 +73,7 @@ public BackupPerformer()
71
73
AttributesToSkip = 0 ,
72
74
} ;
73
75
_pathsCopiedTo = new Dictionary < string , bool > ( ) ;
76
+ _backupDirectory = "" ;
74
77
}
75
78
76
79
public void Cancel ( )
@@ -161,6 +164,10 @@ private void CopyDirectory(FolderFileItem itemBeingCopied, string sourceDirName,
161
164
}
162
165
if ( ! _directoryPathsSeen . Contains ( subDir . FullName ) )
163
166
{
167
+ if ( ! string . IsNullOrWhiteSpace ( _backupDirectory ) && ! subDir . FullName . StartsWith ( _backupDirectory ) )
168
+ {
169
+ continue ; // don't back up backup directory
170
+ }
164
171
string temppath = Path . Combine ( destDirName , subDir . Name ) ;
165
172
if ( ShouldAllowPath ( excludedPaths , subDir . FullName ) )
166
173
{
@@ -209,6 +216,10 @@ private Dictionary<string, ulong> GetFilePathsAndSizesInDirectory(string sourceD
209
216
}
210
217
if ( ! _directoryPathsSeen . Contains ( subDir . FullName ) )
211
218
{
219
+ if ( ! string . IsNullOrWhiteSpace ( _backupDirectory ) && ! subDir . FullName . StartsWith ( _backupDirectory ) )
220
+ {
221
+ continue ; // don't back up backup directory
222
+ }
212
223
if ( ShouldAllowPath ( excludedPaths , subDir . FullName ) )
213
224
{
214
225
var additionalFileInfo = GetFilePathsAndSizesInDirectory ( subDir . FullName , searchSubDirs ) ;
@@ -582,6 +593,7 @@ private void IterateOverFiles(List<FolderFileItem> paths, string backupDirectory
582
593
throw new Exception ( "Couldn't create backup directory (directory already exists)" ) ;
583
594
}
584
595
}
596
+ _backupDirectory = backupDirectory ;
585
597
// ok, start copying the files if not using compressed file.
586
598
if ( ! UsesCompressedFile || _isCalculatingFileSize )
587
599
{
@@ -602,7 +614,6 @@ private void IterateOverFiles(List<FolderFileItem> paths, string backupDirectory
602
614
else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ||
603
615
RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
604
616
{
605
- // Do something
606
617
if ( directoryName . StartsWith ( pathRoot ) )
607
618
{
608
619
directoryName = directoryName . Substring ( 1 ) ;
0 commit comments