Skip to content

Commit

Permalink
Use smarter backward compatibility check
Browse files Browse the repository at this point in the history
  • Loading branch information
nopara73 committed Jun 30, 2019
1 parent eb1f248 commit 1d5a2d2
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions WalletWasabi/Stores/IndexStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,29 @@ private async Task TryEnsureBackwardsCompatibilityAsync()
foreach (var fileName in oldFileNames)
{
var oldFilePath = Path.Combine(oldIndexFolderPath, fileName);
if (File.Exists(oldFilePath))
var oldFile = new FileInfo(oldFilePath);
if (oldFile.Exists)
{
File.Copy(oldFilePath, oldFilePath.Replace(oldIndexFolderPath, WorkFolderPath), true);
File.Delete(oldFilePath);
string newFilePath = oldFilePath.Replace(oldIndexFolderPath, WorkFolderPath);
var newFile = new FileInfo(newFilePath);
// First, delete target file if exists, as File.Move() does not support overwrite.
if (newFile.Exists)
{
var newFileLarger = oldFile.Length > newFile.Length; // Because during development we may be moving between branches.
if (!newFileLarger)
{
newFile.Delete();
}
}

if (newFile.Exists)
{
File.Delete(oldFilePath);
}
else
{
File.Move(oldFilePath, newFilePath);
}
}
}

Expand Down

0 comments on commit 1d5a2d2

Please sign in to comment.