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

download github source files with correct encoding #248

Merged
merged 1 commit into from
Oct 12, 2014
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Paket/GitHub.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ let downloadDependenciesFile(rootPath,remoteFile:ModuleResolver.ResolvedSourceFi
| None -> return "" }

/// Gets a single file from github.
let downloadSourceFile(remoteFile:ModuleResolver.ResolvedSourceFile) = getFromUrl(None,sprintf "https://github.com/%s/%s/raw/%s/%s" remoteFile.Owner remoteFile.Project remoteFile.Commit remoteFile.Name)
let downloadSourceFile(remoteFile:ModuleResolver.ResolvedSourceFile) = downloadFromUrl(None,sprintf "https://github.com/%s/%s/raw/%s/%s" remoteFile.Owner remoteFile.Project remoteFile.Commit remoteFile.Name)
3 changes: 1 addition & 2 deletions src/Paket/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ let DownloadSourceFiles(rootPath,sourceFiles) =
return None
else
tracefn "Downloading %s to %s" (source.ToString()) destination
let! file = GitHub.downloadSourceFile source
Directory.CreateDirectory(destination |> Path.GetDirectoryName) |> ignore
File.WriteAllText(destination, file)
do! GitHub.downloadSourceFile source destination
File.WriteAllText(versionFile.FullName, source.Commit)

return None
Expand Down
35 changes: 35 additions & 0 deletions src/Paket/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,41 @@ let createWebClient(auth:Auth option) =
client.Headers.Add("user-agent", "Paket")
client

type System.Net.WebClient with
member this.AsyncDownloadFile (address: Uri, filePath: string) : Async<unit> =
let downloadAsync =
Async.FromContinuations (fun (cont, econt, ccont) ->
let userToken = new obj()
let rec handler =
System.ComponentModel.AsyncCompletedEventHandler (fun _ args ->
if userToken = args.UserState then
this.DownloadFileCompleted.RemoveHandler(handler)
if args.Cancelled then
ccont (new OperationCanceledException())
elif args.Error <> null then
econt args.Error
else
cont ())
this.DownloadFileCompleted.AddHandler(handler)
this.DownloadFileAsync(address, filePath, userToken)
)

async {
use! _holder = Async.OnCancel(fun _ -> this.CancelAsync())
return! downloadAsync
}

/// [omit]
let downloadFromUrl (auth:Auth option, url : string) (filePath: string) =
async {
try
use client = createWebClient auth
do! client.AsyncDownloadFile(Uri(url), filePath)
with
| exn ->
failwithf "Could not retrieve data from %s%s Message: %s" url Environment.NewLine exn.Message
}

/// [omit]
let getFromUrl (auth:Auth option, url : string) =
async {
Expand Down