Skip to content

Commit

Permalink
Fix Trash getting detected
Browse files Browse the repository at this point in the history
The .DiffTrash folder would be detected as an actual directory, this fix excludes this folder from the search.
  • Loading branch information
bfourk committed Feb 23, 2024
1 parent 694f5e7 commit b2e1089
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 5 additions & 3 deletions FileDiff/Crawler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public static void Crawl(string Root, string NewDir, CrawlInfo Output)
string NewPath = Path.Join(Root,NewDir);
string[] Files = Directory.GetFiles(NewPath);
string[] Directories = Directory.GetDirectories(NewPath);
foreach (string File in Files)
foreach (string CrawledFile in Files)
{
// Add file to the list
Output.Files.Add(File.Substring(File.IndexOf("/./")+3));
Output.Files.Add(CrawledFile.Substring(CrawledFile.IndexOf("/./")+3));
}
foreach (string Dir in Directories)
{
// Crawl subdirectory
Expand All @@ -37,7 +39,7 @@ public static void FindFolderChanges(List<string> DirectoryListMain, List<string
}

foreach (string FolderLocation in DirectoryListSync)
if (!DirectoryListMain.Contains(FolderLocation))
if (!DirectoryListMain.Contains(FolderLocation) && !FolderLocation.Contains(".DiffTrash"))
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("- [{0}]",FolderLocation);
Expand Down
15 changes: 12 additions & 3 deletions FileDiff/FileDiff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static void Main(string[] args)

// Search for deletions
foreach(string FileLocation in SyncDirectoryList.Files)
if (!MainDirectoryList.Files.Contains(FileLocation))
if (!MainDirectoryList.Files.Contains(FileLocation) && !FileLocation.Contains(".DiffTrash"))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("- {0}",FileLocation);
Expand Down Expand Up @@ -224,10 +224,13 @@ public static void Main(string[] args)
{
inc++;
string Path1 = Path.Join(SyncDirectory, del);

// The file could have been deleted at this point, double-check
if (!File.Exists(Path1))
continue;
Console.WriteLine("- {0}", del);
try
{

string NewPath = Path.Join(GarbagePath,del);
if (File.Exists(NewPath))
{
Expand All @@ -248,8 +251,14 @@ public static void Main(string[] args)
try
{
string DirPath = Path.Join(SyncDirectory, del);
Console.WriteLine(DirPath);
// The directory could have been deleted at this point, double-check.
if (!Directory.Exists(DirPath))
continue;

string NewPath = Path.Join(GarbagePath, del);
if (File.Exists(NewPath))

if (Directory.Exists(NewPath))
{
Console.WriteLine("Warn: File with similar name already exists in trash, adding number to beginning");
Directory.Move(DirPath,Path.Join(GarbagePath,inc.ToString()+del));
Expand Down

0 comments on commit b2e1089

Please sign in to comment.