Skip to content
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
Caches that a cache is inaccessible for the duration of running a com…
…mand
  • Loading branch information
xavierzwirtz committed Jun 29, 2016
commit 38a6c34844e2600f477b243a9fa179b6ea81e83a
13 changes: 12 additions & 1 deletion src/Paket.Core/Cache.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,15 @@ type Cache =
for kv in kvPairs do
failwithf "Unknown package settings %s: %s" kv.Key kv.Value

settings
settings

[<CompilationRepresentation (CompilationRepresentationFlags.ModuleSuffix)>]
module Cache =
let private lockObj = System.Object()
let mutable private inaccessibleCaches = Set.empty<Cache>
let setInaccessible cache =
lock lockObj (fun () ->
inaccessibleCaches <- inaccessibleCaches |> Set.add cache)
let isInaccessible cache =
lock lockObj (fun () ->
inaccessibleCaches |> Set.contains cache)
48 changes: 26 additions & 22 deletions src/Paket.Core/GarbageCollection.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,34 @@ 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)
let cont =
try
if not targetFolder.Exists then
targetFolder.Create()
true
with
| exn ->
traceWarnfn "Could not garbage collect cache: %s" exn.Message
false
if Cache.isInaccessible cache then
verbosefn "Cache %s is inaccessible, skipping" cache.Location
else
let targetFolder = DirectoryInfo(cache.Location)
let cont =
try
if not targetFolder.Exists then
targetFolder.Create()
true
with
| exn ->
traceWarnfn "Could not garbage collect cache: %s" exn.Message
Cache.setInaccessible cache
false

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
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
26 changes: 17 additions & 9 deletions src/Paket.Core/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -480,17 +480,25 @@ let CopyFromCache(root, groupName, cacheFileName, licenseCacheFile, packageName:

/// Puts the package into the cache
let CopyToCache(cache:Cache, fileName, force) =
let targetFolder = DirectoryInfo(cache.Location)
if not targetFolder.Exists then
targetFolder.Create()
try
if Cache.isInaccessible cache then
verbosefn "Cache %s is inaccessible, skipping" cache.Location
else
let targetFolder = DirectoryInfo(cache.Location)
if not targetFolder.Exists then
targetFolder.Create()

let fi = FileInfo(fileName)
let targetFile = FileInfo(Path.Combine(targetFolder.FullName, fi.Name))
let fi = FileInfo(fileName)
let targetFile = FileInfo(Path.Combine(targetFolder.FullName, fi.Name))

if not force && targetFile.Exists then
verbosefn "%s already in cache %s" fi.Name targetFolder.FullName
else
File.Copy(fileName, targetFile.FullName, force)
if not force && targetFile.Exists then
verbosefn "%s already in cache %s" fi.Name targetFolder.FullName
else
File.Copy(fileName, targetFile.FullName, force)
with
| _ ->
Cache.setInaccessible cache
reraise()

let DownloadLicense(root,force,packageName:PackageName,version:SemVerInfo,licenseUrl,targetFileName) =
async {
Expand Down