Skip to content

Commit c23e305

Browse files
committed
put a few checks from sync methods into a single method
1 parent 0c85cb6 commit c23e305

1 file changed

Lines changed: 14 additions & 17 deletions

File tree

FolderSync/SyncLogic.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@ public SyncLogic(Config config)
1212

1313
public void RunInitialSync()
1414
{
15-
if(!Directory.Exists(Config.SourceFolder))
16-
throw new DirectoryNotFoundException($"Source folder '{Config.SourceFolder}' no longer exists");
17-
if(!Directory.Exists(Config.BackupFolder))
18-
throw new DirectoryNotFoundException($"Backup folder '{Config.BackupFolder}' no longer exists");
19-
if (!Directory.Exists(Directory.GetParent(Config.LogFilePath).ToString()))
20-
throw new DirectoryNotFoundException($"Log file path '{Config.LogFilePath}' no longer exists");
21-
if(!File.Exists(Config.LogFilePath))
22-
throw new FileNotFoundException($"Log file '{Config.LogFilePath}' no longer exists");
23-
15+
CheckExistingDirs();
2416
CheckForMissingDirs();
2517
CheckForDeletedFiles();
2618
CheckForDeletedDirs();
@@ -32,14 +24,7 @@ public void RunSyncLoop()
3224
{
3325
while (true)
3426
{
35-
if(!Directory.Exists(Config.SourceFolder))
36-
throw new DirectoryNotFoundException($"Source folder '{Config.SourceFolder}' no longer exists");
37-
if(!Directory.Exists(Config.BackupFolder))
38-
throw new DirectoryNotFoundException($"Backup folder '{Config.BackupFolder}' no longer exists");
39-
if (!Directory.Exists(Directory.GetParent(Config.LogFilePath).ToString()))
40-
throw new DirectoryNotFoundException($"Log file path '{Config.LogFilePath}' no longer exists");
41-
if(!File.Exists(Config.LogFilePath))
42-
throw new FileNotFoundException($"Log file '{Config.LogFilePath}' no longer exists");
27+
CheckExistingDirs();
4328
CheckForMissingDirs();
4429
CheckForModifiedFiles();
4530
CheckForCopiesInSource();
@@ -50,6 +35,18 @@ public void RunSyncLoop()
5035
Thread.Sleep(Config.SyncPeriod * 60000);
5136
}
5237
}
38+
39+
private void CheckExistingDirs()
40+
{
41+
if (!Directory.Exists(Config.SourceFolder))
42+
throw new DirectoryNotFoundException($"Source folder '{Config.SourceFolder}' no longer exists");
43+
if (!Directory.Exists(Config.BackupFolder))
44+
throw new DirectoryNotFoundException($"Backup folder '{Config.BackupFolder}' no longer exists");
45+
if (!Directory.Exists(Directory.GetParent(Config.LogFilePath).ToString()))
46+
throw new DirectoryNotFoundException($"Log file path '{Config.LogFilePath}' no longer exists");
47+
if (!File.Exists(Config.LogFilePath))
48+
throw new FileNotFoundException($"Log file '{Config.LogFilePath}' no longer exists");
49+
}
5350

5451
private void WriteLogs()
5552
{

0 commit comments

Comments
 (0)