From f76bc5a41659f56f3bb9eb899ba1b5d02501a4fa Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Mon, 13 Oct 2014 18:09:38 +0200 Subject: [PATCH] Initial support for full github projects - references #113 --- RELEASE_NOTES.md | 3 +++ src/Paket.Core/DependenciesFile.fs | 1 + src/Paket.Core/GitHub.fs | 42 +++++++++++++++++++++++++++++- src/Paket.Core/RestoreProcess.fs | 5 ++-- 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 78e41b740d..8e4edffcad 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,6 @@ +#### 0.6.13 - 13.10.2014 +* Initial support for full github projects - https://github.com/fsprojects/Paket/issues/113 + #### 0.6.12 - 13.10.2014 * BUGFIX: Paket only deletes files which will are downloaded by init-auto-restore process - https://github.com/fsprojects/Paket/pull/254 diff --git a/src/Paket.Core/DependenciesFile.fs b/src/Paket.Core/DependenciesFile.fs index 0fee773342..beb659ee1e 100644 --- a/src/Paket.Core/DependenciesFile.fs +++ b/src/Paket.Core/DependenciesFile.fs @@ -107,6 +107,7 @@ module DependenciesFileParser = | _ -> failwithf "invalid github specification:%s %s" Environment.NewLine trimmed match parts with | [| _; projectSpec; fileSpec |] -> SourceFile(getParts projectSpec, fileSpec) + | [| _; projectSpec; |] -> SourceFile(getParts projectSpec, "FULLPROJECT") | _ -> failwithf "invalid github specification:%s %s" Environment.NewLine trimmed | _ -> Blank diff --git a/src/Paket.Core/GitHub.fs b/src/Paket.Core/GitHub.fs index ce3b1c4276..698db86859 100644 --- a/src/Paket.Core/GitHub.fs +++ b/src/Paket.Core/GitHub.fs @@ -3,6 +3,7 @@ open Paket open Newtonsoft.Json.Linq open System.IO +open Ionic.Zip // Gets the sha1 of a branch let getSHA1OfBranch owner project branch = @@ -31,5 +32,44 @@ let downloadDependenciesFile(rootPath,remoteFile:ModuleResolver.ResolvedSourceFi return text | None -> return "" } + +let ExtractZip(fileName : string, targetFolder) = + let zip = ZipFile.Read(fileName) + Directory.CreateDirectory(targetFolder) |> ignore + for zipEntry in zip do + zipEntry.Extract(targetFolder, ExtractExistingFileAction.OverwriteSilently) + +let rec DirectoryCopy(sourceDirName, destDirName, copySubDirs) = + let dir = new DirectoryInfo(sourceDirName) + let dirs = dir.GetDirectories() + + + if not <| Directory.Exists(destDirName) then + Directory.CreateDirectory(destDirName) |> ignore + + for file in dir.GetFiles() do + file.CopyTo(Path.Combine(destDirName, file.Name), false) |> ignore + + // If copying subdirectories, copy them and their contents to new location. + if copySubDirs then + for subdir in dirs do + DirectoryCopy(subdir.FullName, Path.Combine(destDirName, subdir.Name), copySubDirs) + /// Gets a single file from github. -let downloadSourceFile(remoteFile:ModuleResolver.ResolvedSourceFile) = downloadFromUrl(None,sprintf "https://github.com/%s/%s/raw/%s/%s" remoteFile.Owner remoteFile.Project remoteFile.Commit remoteFile.Name) \ No newline at end of file +let downloadGithubFiles(remoteFile:ModuleResolver.ResolvedSourceFile,destitnation) = async { + match remoteFile.Name with + | "FULLPROJECT" -> + let fi = FileInfo(destitnation) + let projectPath = fi.Directory.FullName + let zipFile = Path.Combine(projectPath,sprintf "%s.zip" remoteFile.Commit) + do! downloadFromUrl(None,sprintf "https://github.com/%s/%s/archive/%s.zip" remoteFile.Owner remoteFile.Project remoteFile.Commit) zipFile + + ExtractZip(zipFile,projectPath) + + let source = Path.Combine(projectPath, sprintf "%s-%s" remoteFile.Project remoteFile.Commit) + DirectoryCopy(source,projectPath,true) + + Directory.Delete(source,true) + + | _ -> return! downloadFromUrl(None,sprintf "https://github.com/%s/%s/raw/%s/%s" remoteFile.Owner remoteFile.Project remoteFile.Commit remoteFile.Name) destitnation +} \ No newline at end of file diff --git a/src/Paket.Core/RestoreProcess.fs b/src/Paket.Core/RestoreProcess.fs index 52ca9275a7..5022520df5 100644 --- a/src/Paket.Core/RestoreProcess.fs +++ b/src/Paket.Core/RestoreProcess.fs @@ -41,8 +41,7 @@ let DownloadSourceFile(rootPath, source:ResolvedSourceFile) = let destination = Path.Combine(rootPath, source.FilePath) let isInRightVersion = - if not <| File.Exists destination then false - else if not <| versionFile.Exists then false + if not <| versionFile.Exists then false else source.Commit = File.ReadAllText(versionFile.FullName) if isInRightVersion then @@ -51,7 +50,7 @@ let DownloadSourceFile(rootPath, source:ResolvedSourceFile) = tracefn "Downloading %s to %s" (source.ToString()) destination Directory.CreateDirectory(destination |> Path.GetDirectoryName) |> ignore - do! GitHub.downloadSourceFile source destination + do! GitHub.downloadGithubFiles(source,destination) File.WriteAllText(versionFile.FullName, source.Commit) }