Skip to content

Commit 4fc519b

Browse files
committed
Refactoring towards #27
1 parent 4667c46 commit 4fc519b

2 files changed

Lines changed: 26 additions & 27 deletions

File tree

‎src/Paket/Hashing.fs‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,9 @@
11
module Hashing
22

33
open System.Security.Cryptography
4-
open System.Xml.Linq
5-
open System.Net
64
open System
75
open System.IO
86

9-
/// Gets hash value and algorithm from Nuget.
10-
let getDetailsFromNuget name version =
11-
async {
12-
use wc = new WebClient()
13-
let! data = sprintf "https://www.nuget.org/api/v2/Packages(Id='%s',Version='%s')" name version
14-
|> wc.DownloadStringTaskAsync
15-
|> Async.AwaitTask
16-
let data = XDocument.Parse data
17-
18-
let getAttribute =
19-
let rootNs = XName.Get("entry", "http://www.w3.org/2005/Atom")
20-
let propertiesNs =
21-
XName.Get("properties", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata")
22-
let attributesNs attribute =
23-
XName.Get(attribute, "http://schemas.microsoft.com/ado/2007/08/dataservices")
24-
25-
let properties =
26-
rootNs
27-
|> data.Element
28-
|> fun entry -> entry.Element(propertiesNs)
29-
fun attribute -> properties.Element(attributesNs attribute).Value
30-
return (getAttribute "PackageHash", getAttribute "PackageHashAlgorithm")
31-
}
32-
337
let private getAlgorithm algorithmName =
348
match algorithmName with
359
| "SHA512" -> Some(SHA512.Create() :> HashAlgorithm)

‎src/Paket/Nuget.fs‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open System.Net
77
open System.Xml
88
open Newtonsoft.Json
99
open Ionic.Zip
10+
open System.Xml.Linq
1011

1112
/// Gets versions of the given package.
1213
let getAllVersions(nugetURL,package) =
@@ -61,6 +62,30 @@ let getDependencies nugetURL package version =
6162
|> Array.toList
6263
return packages
6364
}
65+
66+
/// Gets hash value and algorithm from Nuget.
67+
let getDetailsFromNuget name version =
68+
async {
69+
use wc = new WebClient()
70+
let! data = sprintf "https://www.nuget.org/api/v2/Packages(Id='%s',Version='%s')" name version
71+
|> wc.DownloadStringTaskAsync
72+
|> Async.AwaitTask
73+
let data = XDocument.Parse data
74+
75+
let getAttribute =
76+
let rootNs = XName.Get("entry", "http://www.w3.org/2005/Atom")
77+
let propertiesNs =
78+
XName.Get("properties", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata")
79+
let attributesNs attribute =
80+
XName.Get(attribute, "http://schemas.microsoft.com/ado/2007/08/dataservices")
81+
82+
let properties =
83+
rootNs
84+
|> data.Element
85+
|> fun entry -> entry.Element(propertiesNs)
86+
fun attribute -> properties.Element(attributesNs attribute).Value
87+
return (getAttribute "PackageHash", getAttribute "PackageHashAlgorithm")
88+
}
6489

6590
/// The NuGet cache folder.
6691
let CacheFolder =
@@ -89,7 +114,7 @@ let DownloadPackage(source, name, version, force) =
89114
do! client.DownloadFileTaskAsync(Uri url, targetFileName)
90115
|> Async.AwaitIAsyncResult
91116
|> Async.Ignore
92-
let! hashDetails = Hashing.getDetailsFromNuget name version
117+
let! hashDetails = getDetailsFromNuget name version
93118
match hashDetails |> Hashing.compareWith name targetFile with
94119
| Some error ->
95120
// TODO: File.Delete targetFileName

0 commit comments

Comments
 (0)