Skip to content

Commit

Permalink
Merge branch 'cache-error-handling' of https://github.com/xavierzwirt…
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Jun 29, 2016
2 parents e74d6da + 9da53ef commit 9ea746e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
8 changes: 8 additions & 0 deletions src/Paket.Core/Cache.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ type Cache =

settings

member this.IsAccessible =
try
let targetFolder = DirectoryInfo(this.Location)
if not targetFolder.Exists then
targetFolder.Create()
true
with
| _ -> false
34 changes: 21 additions & 13 deletions src/Paket.Core/GarbageCollection.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,29 @@ let deleteUnusedPackages root (lockFile:LockFile) =
/// Removes older packages from the cache
let removeOlderVersionsFromCache(cache:Cache, packageName:PackageName, versions:SemVerInfo seq) =
let targetFolder = DirectoryInfo(cache.Location)
if not targetFolder.Exists then
targetFolder.Create()
let cont =
try
if not targetFolder.Exists then
targetFolder.Create()
true
with
| exn ->
traceWarnfn "Could not garbage collect cache: %s" exn.Message
false

match cache.CacheType with
| Some CacheType.CurrentVersion ->
let fileNames =
versions
|> Seq.map (fun v -> packageName.ToString() + "." + v.Normalize() + ".nupkg" |> normalizePath)
|> Set.ofSeq
if cont then
match cache.CacheType with
| Some CacheType.CurrentVersion ->
let fileNames =
versions
|> Seq.map (fun v -> packageName.ToString() + "." + v.Normalize() + ".nupkg" |> normalizePath)
|> Set.ofSeq

targetFolder.EnumerateFiles(packageName.ToString() + ".*.nupkg")
|> Seq.iter (fun fi ->
if not <| fileNames.Contains(fi.Name |> normalizePath) then
fi.Delete())
| _ -> ()
targetFolder.EnumerateFiles(packageName.ToString() + ".*.nupkg")
|> Seq.iter (fun fi ->
if not <| fileNames.Contains(fi.Name |> normalizePath) then
fi.Delete())
| _ -> ()

let cleanupCaches (dependenciesFile:DependenciesFile) (lockFile:LockFile) =
let allCaches = dependenciesFile.Groups |> Seq.collect (fun kv -> kv.Value.Caches) |> Seq.toList
Expand Down

0 comments on commit 9ea746e

Please sign in to comment.