Skip to content

Commit 84cbb60

Browse files
committed
fix file move check
1 parent 9c61e1f commit 84cbb60

1 file changed

Lines changed: 6 additions & 26 deletions

File tree

FolderSync/Program.cs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ public static void Main(string[] args)
2525
InitalSync();
2626
CheckForMissingDirs();
2727
CheckForMoodifiedFiles();
28+
CheckForMovedFiles();
2829
CheckForCopiesInSource();
2930
CheckForMissingFiles();
3031
CheckForDeletedFiles();
3132
CheckForDeletedDirs();
32-
CheckForMovedFiles();
3333
// Sync();
3434
}
3535

@@ -84,30 +84,10 @@ private static void InvalidPath(string value)
8484
// Here we make sure that all required directories exist and clean the backup folder if the source is empty. We're not logging deletion here because it's not really a part of the actual file sync.
8585
private static void InitalSync()
8686
{
87-
string[] sourceDirs = Directory.GetDirectories(sourceRoot, "*", SearchOption.AllDirectories).OrderBy(s => s).ToArray();
88-
string[] destDirs = Directory.GetDirectories(backupRoot, "*", SearchOption.AllDirectories).OrderBy(s => s).ToArray();
89-
90-
foreach (var dir in sourceDirs) // Make sure the folders that are in the source are also in the backup
91-
{
92-
string backupDir = dir.Replace(sourceRoot, backupRoot);
93-
if (!Directory.Exists(backupDir))
94-
{
95-
Directory.CreateDirectory(backupDir);
96-
Log(backupDir, Actions.created);
97-
}
98-
}
99-
100-
if(Directory.GetFiles(sourceRoot, "*", SearchOption.AllDirectories).Length == 0 && Directory.GetFiles(backupRoot, "*", SearchOption.AllDirectories).Length > 0)
101-
{
102-
foreach (var file in Directory.GetFiles(backupRoot, "*", SearchOption.AllDirectories))
103-
File.Delete(file);
104-
}
105-
106-
if (sourceDirs.Length == 0 && destDirs.Length > 0) // If the source folder is empty, make sure the backup folder is empty as well
107-
{
108-
for (int i = destDirs.Length - 1; i >= 0; --i)
109-
Directory.Delete(destDirs[i]);
110-
}
87+
CheckForMissingDirs();
88+
CheckForDeletedFiles();
89+
CheckForDeletedDirs();
90+
CheckForMissingFiles();
11191
}
11292

11393
private static void CheckForMissingDirs()
@@ -160,7 +140,7 @@ private static void CheckForMovedFiles()
160140
foreach (var sourceFile in sourceFileList)
161141
{
162142
var backup = backupFileList.Find(backup => backup.IsFileMoved(sourceFile.GetRelativeFilePath, sourceFile.GetMD5Code));
163-
if (backup != null)
143+
if (backup != null && !File.Exists(backup.GetAbsoluteFilePath))
164144
{
165145
MoveFile(sourceFile, backup);
166146
}

0 commit comments

Comments
 (0)