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 bab6224 commit ce631a5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/Paket/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ let ExtractPackages(force, packages:PackageResolution) =
match package.Source with
| Nuget source ->
let! packageFile = Nuget.DownloadPackage(source.Auth, source.Url, package.Name, package.Version.ToString(), force)
let! folder = Nuget.ExtractPackage(packageFile, package.Name, package.Version.ToString(), force)
let! folder = Nuget.CopyFromCache(packageFile, 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()))
let! folder = Nuget.ExtractPackage(packageFile, package.Name, package.Version.ToString(), force)
let! folder = Nuget.CopyFromCache(packageFile, package.Name, package.Version.ToString(), force)
return Some(package, Nuget.GetLibraries folder)
})

Expand Down
55 changes: 33 additions & 22 deletions src/Paket/Nuget.fs
Original file line number Diff line number Diff line change
Expand Up @@ -289,36 +289,47 @@ let DownloadPackage(auth, url, name, version, force) =
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, name, version, force) =
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 extracted" name version
return targetFolder
else
verbosefn "%s %s already copied" name version
else
CleanDir targetFolder
File.Copy(fileName, targetFile.FullName)
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
File.Copy(fileName, targetFile.FullName)
return! ExtractPackage(targetFile.FullName,targetFolder,name,version)
}

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

0 comments on commit ce631a5

Please sign in to comment.