@@ -33,21 +33,25 @@ public RemoteSync(string host, string username, string password,
3333 _username = username ;
3434 _password = password ;
3535 _searchPattern = searchPattern ;
36- _localRootDirectory = Path . TrimEndingDirectorySeparator (
37- Path . GetFullPath ( localRootDirectory ) ) ;
36+ _localRootDirectory = Path . TrimEndingDirectorySeparator ( Path . GetFullPath ( localRootDirectory ) ) ;
3837 _remoteRootDirectory = remoteRootDirectory . TrimEnd ( '/' , '\\ ' ) ;
3938 _director = director ;
4039 _excludedFolders = excludedFolders ?? new List < string > ( ) ;
4140 _sftp = new SftpClient ( host , username , password ) ;
4241
43- //Our first instance is responsible for creating all of the the directories
44- //Subsequent instances will not be created until this is done
45- DoneMakingFolders = createFolders ? CreateDirectories ( _localRootDirectory , _remoteRootDirectory ) : Task . CompletedTask ;
42+ //The first instance is responsible for creating ALL of the the directories.
43+ //Subsequent instances will not be created until this one completes.
44+
45+ DoneMakingFolders = createFolders
46+ ? CreateDirectories ( _localRootDirectory , _remoteRootDirectory )
47+ : Task . CompletedTask ;
4648
4749 //Now perform the initial sync for the pattern this instance is responsible for
50+
4851 DoneInitialSync = InitialSync ( _localRootDirectory , _remoteRootDirectory ) ;
4952
5053 //Once the initial sync is done, we can start watching the file system for changes
54+
5155 DoneInitialSync . ContinueWith ( ( tmp ) =>
5256 {
5357 _director . AddCallback ( searchPattern , ( args ) => Fsw_Changed ( null , args ) ) ;
@@ -62,14 +66,14 @@ public RemoteSync(string host, string username, string password,
6266 _username = username ;
6367 _password = password ;
6468 _searchPattern = searchPattern ;
65- _localRootDirectory = Path . TrimEndingDirectorySeparator (
66- Path . GetFullPath ( localRootDirectory ) ) ;
69+ _localRootDirectory = Path . TrimEndingDirectorySeparator ( Path . GetFullPath ( localRootDirectory ) ) ;
6770 _remoteRootDirectory = remoteRootDirectory . TrimEnd ( '/' , '\\ ' ) ;
6871 _director = director ;
6972 _excludedFolders = excludedFolders ?? new List < string > ( ) ;
7073 _sftp = new SftpClient ( host , username , password ) ;
7174
7275 DoneMakingFolders = Task . CompletedTask ;
76+
7377 DoneInitialSync = initialSyncTask ;
7478
7579 DoneInitialSync . ContinueWith ( ( tmp ) =>
@@ -79,14 +83,9 @@ public RemoteSync(string host, string username, string password,
7983 }
8084
8185 public static async Task RunSharedInitialSyncAsync (
82- string host ,
83- string username ,
84- string password ,
85- string localRootDirectory ,
86- string remoteRootDirectory ,
87- string [ ] searchPatterns ,
88- List < string > ? excludedFolders ,
89- int workerCount )
86+ string host , string username , string password ,
87+ string localRootDirectory , string remoteRootDirectory ,
88+ string [ ] searchPatterns , List < string > ? excludedFolders , int workerCount )
9089 {
9190 if ( workerCount <= 0 || searchPatterns . Length == 0 )
9291 {
@@ -108,6 +107,7 @@ public static async Task RunSharedInitialSyncAsync(
108107 }
109108
110109 var workQueue = new ConcurrentQueue < SyncWorkItem > ( ) ;
110+
111111 foreach ( var pair in EnumerateLocalDirectories ( localRootDirectory , remoteRootDirectory , excludedFolders ) )
112112 {
113113 foreach ( var pattern in searchPatterns )
@@ -117,6 +117,7 @@ public static async Task RunSharedInitialSyncAsync(
117117 }
118118
119119 var workers = new List < Task > ( ) ;
120+
120121 for ( int i = 0 ; i < workerCount ; i ++ )
121122 {
122123 workers . Add ( Task . Run ( async ( ) =>
0 commit comments