Refactor moving (2/2)

This commit is contained in:
Shivam 2020-06-16 17:15:43 +02:00
parent b75fd7bfa8
commit 02d66c4856
1 changed files with 3 additions and 8 deletions

View File

@ -57,7 +57,7 @@ internal void Migrate()
if (!cfgDestination.Exists)
destination.CreateSubdirectory(config_directory);
moveFileIfExists("bracket.json", destination);
moveFileIfExists("drawings.txt", destination);
moveFileIfExists("drawings_results.txt", destination);
@ -77,7 +77,8 @@ private void moveFileIfExists(string file, DirectoryInfo destination)
{
Logger.Log($"Migrating {file} to default tournament storage.");
var fileInfo = new System.IO.FileInfo(storage.GetFullPath(file));
moveFile(fileInfo, destination);
attemptOperation(() => fileInfo.CopyTo(Path.Combine(destination.FullName, fileInfo.Name), true));
fileInfo.Delete();
}
}
@ -112,12 +113,6 @@ private void deleteRecursive(DirectoryInfo target)
attemptOperation(target.Delete);
}
private void moveFile(System.IO.FileInfo file, DirectoryInfo destination)
{
attemptOperation(() => file.CopyTo(Path.Combine(destination.FullName, file.Name), true));
file.Delete();
}
private void attemptOperation(Action action, int attempts = 10)
{
while (true)