Skip to content

Commit 716dee2

Browse files
committed
If a package is borked then try to extract files individually - fixes #3743
1 parent 5d962fb commit 716dee2

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/Paket.Core/Dependencies/NuGetCache.fs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,23 @@ let ExtractPackage(fileName:string, targetFolder, packageName:PackageName, versi
533533
ZipFile.ExtractToDirectory(fileName, targetFolder)
534534
with
535535
| exn ->
536-
let text = if detailed then sprintf "%s In rare cases a firewall might have blocked the download. Please look into the file and see if it contains text with further information." Environment.NewLine else ""
537-
let path = try Path.GetFullPath fileName with :? PathTooLongException -> sprintf "%s (!too long!)" fileName
538-
raise (Exception(sprintf "Error during extraction of %s.%s%s" path Environment.NewLine text, exn))
536+
try
537+
traceWarnfn "Package couldn't be extracted to %s. Message: %s. Trying to extract files individually." targetFolder exn.Message
538+
use archive = ZipFile.OpenRead fileName
539+
for entry in archive.Entries do
540+
let destinationPath = Path.GetFullPath(Path.Combine(targetFolder, entry.FullName))
541+
let fi = FileInfo(destinationPath)
542+
if not fi.Directory.Exists then
543+
fi.Directory.Create()
544+
if fi.Exists then
545+
try fi.Delete() with | _ -> ()
546+
547+
entry.ExtractToFile(destinationPath)
548+
with
549+
| exn ->
550+
let text = if detailed then sprintf "%s In rare cases a firewall might have blocked the download. Please look into the file and see if it contains text with further information." Environment.NewLine else ""
551+
let path = try Path.GetFullPath fileName with :? PathTooLongException -> sprintf "%s (!too long!)" fileName
552+
raise (Exception(sprintf "Error during extraction of %s.%s%s" path Environment.NewLine text, exn))
539553

540554
cleanup directory
541555
if verbose then

0 commit comments

Comments
 (0)