Skip to content

Commit

Permalink
Fix: Relative paths not working properly when creating checkpoints #437
Browse files Browse the repository at this point in the history
… (#438)
  • Loading branch information
lock9 authored May 16, 2024
1 parent e811baf commit 90135f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
14 changes: 13 additions & 1 deletion src/neoxp/ExpressChainManagerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@ public ExpressChainManagerFactory(IFileSystem fileSystem)
this.fileSystem = fileSystem;
}

string ResolveChainFileName(string path) => fileSystem.ResolveFileName(path, EXPRESS_EXTENSION, () => DEFAULT_EXPRESS_FILENAME);
string ResolveChainFileName(string path) => fileSystem.ResolveFileName(path, EXPRESS_EXTENSION, () =>
{
var homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile, Environment.SpecialFolderOption.DoNotVerify);
var folder = fileSystem.Path.Combine(homeDir, ".neo-express");
if (!fileSystem.Path.Exists(folder))
fileSystem.Directory.CreateDirectory(folder);
var fileName = fileSystem.Path.Combine(folder, DEFAULT_EXPRESS_FILENAME);
return fileName;
});

internal static ExpressChain CreateChain(int nodeCount, byte? addressVersion, byte[]? privateKey = null)
{
Expand Down
20 changes: 4 additions & 16 deletions src/neoxp/Extensions/FileSystemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,13 @@ public static string ResolveFileName(this IFileSystem fileSystem, string fileNam
fileName = getDefaultFileName();
}

if (extension.Equals(fileSystem.Path.GetExtension(fileName), StringComparison.InvariantCultureIgnoreCase) == false)
fileName = $"{fileName}{extension}";

if (fileSystem.Path.IsPathFullyQualified(fileName) == false)
if (!fileSystem.Path.IsPathFullyQualified(fileName))
{
var defaultFileName = fileSystem.Path.Combine(fileSystem.Directory.GetCurrentDirectory(), fileName);
if (fileSystem.File.Exists(defaultFileName) == false)
{
var homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile, Environment.SpecialFolderOption.DoNotVerify);
var folder = fileSystem.Path.Combine(homeDir, ".neo-express");
if (fileSystem.Path.Exists(folder) == false)
fileSystem.Directory.CreateDirectory(folder);
fileName = fileSystem.Path.Combine(folder, fileName);
}
else
fileName = defaultFileName;
fileName = fileSystem.Path.Combine(fileSystem.Directory.GetCurrentDirectory(), fileName);
}

return fileName;
return extension.Equals(fileSystem.Path.GetExtension(fileName), StringComparison.OrdinalIgnoreCase)
? fileName : fileName + extension;
}

public static string GetTempFolder(this IFileSystem fileSystem)
Expand Down

0 comments on commit 90135f7

Please sign in to comment.