Skip to content

Commit

Permalink
Make sure we extract if the package is there but not extracted - rela…
Browse files Browse the repository at this point in the history
…tes to #166
  • Loading branch information
forki committed Sep 25, 2014
1 parent d6d264d commit ec4e524
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 49 deletions.
3 changes: 1 addition & 2 deletions src/Paket/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ let ExtractPackages(force, packages:PackageResolution) =
let package = kv.Value
match package.Source with
| Nuget source ->
let! packageFile = Nuget.DownloadPackage(source.Auth, source.Url, package.Name, package.Version.ToString(), force)
let! folder = Nuget.CopyFromCache(packageFile, package.Name, package.Version.ToString(), force)
let! folder = Nuget.DownloadPackage(source.Auth, source.Url, package.Name, package.Version.ToString(), force)
return Some(package, Nuget.GetLibraries folder)
| LocalNuget path ->
let packageFile = Path.Combine(path, sprintf "%s.%s.nupkg" package.Name (package.Version.ToString()))
Expand Down
94 changes: 47 additions & 47 deletions src/Paket/Nuget.fs
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,57 @@ let getDetailsFromLocalFile path package version =
return { Name = officialName; Url = package; Dependencies = dependencies }
}


let isExtracted fileName =
let fi = FileInfo(fileName)
if not fi.Exists then false else
let di = fi.Directory
di.EnumerateFileSystemInfos()
|> Seq.forall (fun f -> f.FullName = fi.FullName)

/// Extracts the given package to the ./packages folder
let ExtractPackage(fileName:string, targetFolder, name, version) =
async {
let zip = ZipFile.Read(fileName)
Directory.CreateDirectory(targetFolder) |> ignore
for e in zip do
e.Extract(targetFolder, ExtractExistingFileAction.OverwriteSilently)

// cleanup folder structure
let rec cleanup (dir : DirectoryInfo) =
for sub in dir.GetDirectories() do
let newName = sub.FullName.Replace("%2B", "+")
if sub.FullName <> newName then
Directory.Move(sub.FullName, newName)
cleanup (DirectoryInfo newName)
else
cleanup sub
cleanup (DirectoryInfo targetFolder)
tracefn "%s %s unzipped to %s" name version targetFolder
return targetFolder
}

/// Extracts the given package to the ./packages folder
let CopyFromCache(cacheFileName, name, version, force) =
async {
let targetFolder = DirectoryInfo(Path.Combine("packages", name)).FullName
let fi = FileInfo(cacheFileName)
let targetFile = FileInfo(Path.Combine(targetFolder, fi.Name))
if not force && targetFile.Exists then
verbosefn "%s %s already copied" name version
else
CleanDir targetFolder
File.Copy(cacheFileName, targetFile.FullName)
return! ExtractPackage(targetFile.FullName,targetFolder,name,version)
}

/// Downloads the given package to the NuGet Cache folder
let DownloadPackage(auth, url, name, version, force) =
async {
let targetFileName = Path.Combine(CacheFolder, name + "." + version + ".nupkg")
let targetFile = FileInfo targetFileName
if not force && targetFile.Exists && targetFile.Length > 0L then
verbosefn "%s %s already downloaded" name version
return targetFileName
verbosefn "%s %s already downloaded" name version
else
// discover the link on the fly
let! nugetPackage = getDetailsFromNuget force auth url name version
Expand Down Expand Up @@ -283,53 +326,10 @@ let DownloadPackage(auth, url, name, version, force) =
let! bytes = httpResponseStream.AsyncRead(buffer, 0, bufferSize)
bytesRead := bytes
do! fileStream.AsyncWrite(buffer, 0, !bytesRead)
return targetFileName

with
| exn -> failwithf "Could not download %s %s.%s %s" name version Environment.NewLine exn.Message
return targetFileName
}

let isExtracted fileName =
let fi = FileInfo(fileName)
if not fi.Exists then false else
let di = fi.Directory
di.EnumerateFileSystemInfos()
|> Seq.forall (fun f -> f.FullName = fi.FullName)

/// Extracts the given package to the ./packages folder
let ExtractPackage(fileName:string, targetFolder, name, version) =
async {
let zip = ZipFile.Read(fileName)
Directory.CreateDirectory(targetFolder) |> ignore
for e in zip do
e.Extract(targetFolder, ExtractExistingFileAction.OverwriteSilently)

// cleanup folder structure
let rec cleanup (dir : DirectoryInfo) =
for sub in dir.GetDirectories() do
let newName = sub.FullName.Replace("%2B", "+")
if sub.FullName <> newName then
Directory.Move(sub.FullName, newName)
cleanup (DirectoryInfo newName)
else
cleanup sub
cleanup (DirectoryInfo targetFolder)
tracefn "%s %s unzipped to %s" name version targetFolder
return targetFolder
}

/// Extracts the given package to the ./packages folder
let CopyFromCache(fileName, name, version, force) =
async {
let targetFolder = DirectoryInfo(Path.Combine("packages", name)).FullName
let fi = FileInfo(fileName)
let targetFile = FileInfo(Path.Combine(targetFolder, fi.Name))
if not force && targetFile.Exists then
verbosefn "%s %s already copied" name version
else
CleanDir targetFolder
File.Copy(fileName, targetFile.FullName)
return! ExtractPackage(targetFile.FullName,targetFolder,name,version)
return! CopyFromCache(targetFile.FullName, name, version, force)
}

/// Finds all libraries in a nuget packge.
Expand Down

0 comments on commit ec4e524

Please sign in to comment.