Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some bugs in NupkgWriter #1694

Merged
merged 1 commit into from
May 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions src/Paket.Core/NupkgWriter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ let nuspecDoc (info:CompleteInfo) =
let buildDependencyNode (Id, requirement:VersionRequirement) =
let dep = XElement(ns + "dependency")
dep.SetAttributeValue(XName.Get "id", Id)
dep.SetAttributeValue(XName.Get "version", requirement.FormatInNuGetSyntax())
let version = requirement.FormatInNuGetSyntax()
if String.IsNullOrEmpty version then () else
dep.SetAttributeValue(XName.Get "version", version)
dep

let buildDependenciesNode excludedDependencies dependencyList =
if List.isEmpty dependencyList then () else
let d = XElement(ns + "dependencies")
dependencyList
dependencyList
|> List.filter (fun d -> Set.contains (fst d) excludedDependencies |> not)
|> List.iter (buildDependencyNode >> d.Add)
metadataNode.Add d
Expand Down Expand Up @@ -150,10 +152,11 @@ let corePropsDoc (core : CompleteCoreInfo) =
let node = XElement(ns + name)
node.SetValue value
root.Add node
!! dc "creator" core.Authors

!! dc "creator" (core.Authors |> List.reduce (fun s1 s2 -> s1 + ", " + s2))
!! dc "description" core.Description
!! dc "identifier" core.Id
!! ns "version" core.Version
!! ns "version" core.Version.Value
XElement(ns + "keywords") |> root.Add
!! dc "title" core.Id
!! ns "lastModifiedBy" "paket"
Expand Down Expand Up @@ -239,31 +242,31 @@ let Write (core : CompleteCoreInfo) optional workingDir outputDir =
let problemChars = ["@","~~at~~"; "+","~~plus~~"]

let fakeEscapeProblemChars (source:string) =
problemChars
|> List.fold (fun (escaped:string) (problem, fakeEscape) ->
escaped.Replace(problem,fakeEscape)) source

let unFakeEscapeProblemChars (source:string) =
problemChars
|> List.fold (fun (escaped:string) (problem, fakeEscape) ->
escaped.Replace(fakeEscape, problem)) source

let escapeTarget (target:string) =
let escapedTargetParts =
target.Replace("\\", "/").Split('/')
problemChars
|> List.fold (fun (escaped:string) (problem, fakeEscape) ->
escaped.Replace(problem,fakeEscape)) source

let unFakeEscapeProblemChars (source:string) =
problemChars
|> List.fold (fun (escaped:string) (problem, fakeEscape) ->
escaped.Replace(fakeEscape, problem)) source

let escapeTarget (target:string) =
let escapedTargetParts =
target.Replace("\\", "/").Split('/')
|> Array.map Uri.EscapeDataString
String.Join("/" ,escapedTargetParts)

let toUri (escapedTarget:string) =
let toUri (escapedTarget:string) =
let uri1 = Uri(escapedTarget, UriKind.Relative)
let uri2 = Uri(uri1.GetComponents(UriComponents.SerializationInfoString, UriFormat.SafeUnescaped), UriKind.Relative)
uri2.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped)

target
|> fakeEscapeProblemChars
|> fakeEscapeProblemChars
|> escapeTarget
|> unFakeEscapeProblemChars
|> toUri
|> toUri

let addEntry path writerF =
if entries.Contains(path) then () else
Expand All @@ -276,7 +279,7 @@ let Write (core : CompleteCoreInfo) optional workingDir outputDir =
let addEntryFromFile path source =
if entries.Contains(path) then () else
entries.Add path |> ignore

zipFile.CreateEntryFromFile(source,path) |> ignore

let ensureValidTargetName (target:string) =
Expand Down