Add update-local and update-local-changing modes

This commit is contained in:
Alexandre Archambault 2016-04-05 16:24:37 +02:00
parent 05d8224c49
commit 62720f94e0
4 changed files with 25 additions and 7 deletions

View File

@ -527,7 +527,7 @@ object Cache {
}
cachePolicy match {
case CachePolicy.FetchMissing | CachePolicy.LocalOnly =>
case CachePolicy.FetchMissing | CachePolicy.LocalOnly | CachePolicy.LocalUpdate | CachePolicy.LocalUpdateChanging =>
validErrFileExists.flatMap { exists =>
if (exists)
EitherT(Task.now(FileError.NotFound(url, Some(true)).left[Unit]))
@ -540,7 +540,7 @@ object Cache {
}
}
def checkFileExists(file: File, url: String): EitherT[Task, FileError, Unit] =
def checkFileExists(file: File, url: String, log: Boolean = true): EitherT[Task, FileError, Unit] =
EitherT {
Task {
if (file.exists()) {
@ -576,6 +576,8 @@ object Cache {
val cachePolicy0 = cachePolicy match {
case CachePolicy.UpdateChanging if !artifact.changing =>
CachePolicy.FetchMissing
case CachePolicy.LocalUpdateChanging if !artifact.changing =>
CachePolicy.LocalOnly
case other =>
other
}
@ -583,6 +585,10 @@ object Cache {
cachePolicy0 match {
case CachePolicy.LocalOnly =>
checkFileExists(file, url)
case CachePolicy.LocalUpdateChanging | CachePolicy.LocalUpdate =>
checkFileExists(file, url, log = false).flatMap { _ =>
update
}
case CachePolicy.UpdateChanging | CachePolicy.Update =>
update
case CachePolicy.FetchMissing =>

View File

@ -44,6 +44,10 @@ object CacheParse {
s.split(',').toVector.traverseU {
case "offline" =>
Seq(CachePolicy.LocalOnly).successNel
case "update-local-changing" =>
Seq(CachePolicy.LocalUpdateChanging).successNel
case "update-local" =>
Seq(CachePolicy.LocalUpdate).successNel
case "update-changing" =>
Seq(CachePolicy.UpdateChanging).successNel
case "update" =>

View File

@ -4,6 +4,8 @@ sealed abstract class CachePolicy extends Product with Serializable
object CachePolicy {
case object LocalOnly extends CachePolicy
case object LocalUpdateChanging extends CachePolicy
case object LocalUpdate extends CachePolicy
case object UpdateChanging extends CachePolicy
case object Update extends CachePolicy
case object FetchMissing extends CachePolicy

View File

@ -305,13 +305,19 @@ class Helper(
): Seq[Artifact] = {
if (subset == null && verbosityLevel >= 1) {
val msg = cachePolicies match {
case Seq(CachePolicy.LocalOnly) =>
" Checking artifacts"
case _ =>
" Fetching artifacts"
def isLocal(p: CachePolicy) = p match {
case CachePolicy.LocalOnly => true
case CachePolicy.LocalUpdate => true
case CachePolicy.LocalUpdateChanging => true
case _ => false
}
val msg =
if (cachePolicies.forall(isLocal))
" Checking artifacts"
else
" Fetching artifacts"
errPrintln(msg)
}