Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
fix: DifferentialBackupFolder
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-houille committed Dec 22, 2023
1 parent e615d7f commit 36e8673
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
36 changes: 35 additions & 1 deletion EasyLib/Files/TransferManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,49 @@ public void ComputeDifference(List<List<string>> folders)
InstructionsFolder = new BackupFolder(folders[1][0]);
if (folders[2].Count != 0)
{
InstructionsFolder.SubFolders.Add(new BackupFolder(folders[3][0]));
InstructionsFolder.SubFolders.Add(new BackupFolder(folders[1][0]));
_compareBackupPath(InstructionsFolder.SubFolders[0], folders[0]);
folders[0].RemoveAt(folders[0].Count - 1);
}
else
{
_compareBackupPath(InstructionsFolder, folders[0]);
}
}

static void CopyDirectory(string sourceDir, string destinationDir, bool recursive)
{
// Get information about the source directory
var dir = new DirectoryInfo(sourceDir);

// Check if the source directory exists
if (!dir.Exists)
throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");

// Cache directories before we start copying
DirectoryInfo[] dirs = dir.GetDirectories();

// Create the destination directory
Directory.CreateDirectory(destinationDir);

// Get the files in the source directory and copy to the destination directory
foreach (FileInfo file in dir.GetFiles())
{
string targetFilePath = Path.Combine(destinationDir, file.Name);
file.CopyTo(targetFilePath);
}

// If recursive and copying subdirectories, recursively call this method
if (recursive)
{
foreach (DirectoryInfo subDir in dirs)
{
string newDestinationDir = Path.Combine(destinationDir, subDir.Name);
CopyDirectory(subDir.FullName, newDestinationDir, true);
}
}
}

/// <summary>
/// Compare the source with the existing backup folders if there is any
/// The result is stored in the InstructionsFolder property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ public List<List<string>> SelectFolders(List<List<string>> folders, string lastF
1 =>
[
folders[0],
[finalDestinationPath + Path.DirectorySeparatorChar + Path.GetDirectoryName(finalDestinationPath)], []
[finalDestinationPath + Path.DirectorySeparatorChar + Path.GetDirectoryName(finalDestinationPath)],
[finalDestinationPath]
],
_ =>
[
Directory.GetDirectories(folders[0][folderCount - 1]).Append(folders[0][0]).ToList(),
[finalDestinationPath + Path.DirectorySeparatorChar + Path.GetDirectoryName(finalDestinationPath)],
[folders[0][folderCount - 2]]
[folders[0][folderCount - 2] + Path.DirectorySeparatorChar]
]
};
}
Expand Down

0 comments on commit 36e8673

Please sign in to comment.