From df10b49779c7f77b94a9a26ce663f4e9842024a2 Mon Sep 17 00:00:00 2001 From: Kukks Date: Mon, 30 May 2022 10:53:47 +0200 Subject: [PATCH 1/2] test fx: Do not crash when node data has already been downloaded --- NBitcoin.TestFramework/NBitcoin.TestFramework.csproj | 1 + NBitcoin.TestFramework/NodeBuilder.cs | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/NBitcoin.TestFramework/NBitcoin.TestFramework.csproj b/NBitcoin.TestFramework/NBitcoin.TestFramework.csproj index c6944c131b..72415601c9 100644 --- a/NBitcoin.TestFramework/NBitcoin.TestFramework.csproj +++ b/NBitcoin.TestFramework/NBitcoin.TestFramework.csproj @@ -27,6 +27,7 @@ + diff --git a/NBitcoin.TestFramework/NodeBuilder.cs b/NBitcoin.TestFramework/NodeBuilder.cs index 160cddd37e..991980fc56 100644 --- a/NBitcoin.TestFramework/NodeBuilder.cs +++ b/NBitcoin.TestFramework/NodeBuilder.cs @@ -161,7 +161,17 @@ public static string EnsureDownloaded(NodeDownloadData downloadData) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - ZipFile.ExtractToDirectory(zip, extractDirectory); + //from https://feedback.telerik.com/document-processing/1518667-ziplibrary-allow-zipfile-extracttodirectory-to-overwrite-existing-files-when-extract-zip + using var source = ZipFile.Open(zip, ZipArchiveMode.Read, null); + foreach (var entry in source.Entries) + { + var fullPath = Path.GetFullPath(Path.Combine(extractDirectory, entry.FullName)); + + if (Path.GetFileName(fullPath).Length == 0) continue; + Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); + // The boolean parameter determines whether an existing file that has the same name as the destination file should be overwritten + entry.ExtractToFile(fullPath, true); + } } else { From 3f7a0b9d6f37d60625ba9fdcb4eba11c7daa19d1 Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Mon, 30 May 2022 12:36:18 +0200 Subject: [PATCH 2/2] Update NBitcoin.TestFramework/NodeBuilder.cs Co-authored-by: Kimi <58662979+kiminuo@users.noreply.github.com> --- NBitcoin.TestFramework/NodeBuilder.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NBitcoin.TestFramework/NodeBuilder.cs b/NBitcoin.TestFramework/NodeBuilder.cs index 991980fc56..3c56781970 100644 --- a/NBitcoin.TestFramework/NodeBuilder.cs +++ b/NBitcoin.TestFramework/NodeBuilder.cs @@ -161,7 +161,8 @@ public static string EnsureDownloaded(NodeDownloadData downloadData) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - //from https://feedback.telerik.com/document-processing/1518667-ziplibrary-allow-zipfile-extracttodirectory-to-overwrite-existing-files-when-extract-zip + // From https://feedback.telerik.com/document-processing/1518667-ziplibrary-allow-zipfile-extracttodirectory-to-overwrite-existing-files-when-extract-zip + using var source = ZipFile.Open(zip, ZipArchiveMode.Read, null); foreach (var entry in source.Entries) {