@@ -2,7 +2,7 @@ package xsbt.boot
2
2
3
3
import Pre ._
4
4
import coursier ._
5
- import coursier .cache .FileCache
5
+ import coursier .cache .{ CacheDefaults , FileCache }
6
6
import coursier .core .{ Publication , Repository }
7
7
import coursier .credentials .DirectCredentials
8
8
import coursier .ivy .IvyRepository
@@ -26,9 +26,43 @@ class CousierUpdate(config: UpdateConfiguration) {
26
26
27
27
private def logFile = new File (bootDirectory, UpdateLogName )
28
28
private val logWriter = new PrintWriter (new FileWriter (logFile))
29
+
30
+ private def defaultCacheLocation : File = {
31
+ def absoluteFile (path : String ): File = new File (path).getAbsoluteFile()
32
+ def windowsCacheDirectory : File = {
33
+ // Per discussion in https://github.com/dirs-dev/directories-jvm/issues/43,
34
+ // LOCALAPPDATA environment variable may NOT represent the one-true
35
+ // Known Folders API (https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid)
36
+ // in case the user happened to have set the LOCALAPPDATA environmental variable.
37
+ // Given that there's no reliable way of accessing this API from JVM, I think it's actually
38
+ // better to use the LOCALAPPDATA as the first place to look.
39
+ // When it is not found, it will fall back to $HOME/AppData/Local.
40
+ // For the purpose of picking the Coursier cache directory, it's better to be
41
+ // fast, reliable, and predictable rather than strict adherence to Microsoft.
42
+ val base =
43
+ sys.env
44
+ .get(" LOCALAPPDATA" )
45
+ .map(absoluteFile)
46
+ .getOrElse(new File (new File (absoluteFile(sys.props(" user.home" )), " AppData" ), " Local" ))
47
+ new File (new File (new File (base, " Coursier" ), " Cache" ), " v1" )
48
+ }
49
+ sys.props
50
+ .get(" sbt.coursier.home" )
51
+ .map(home => new File (absoluteFile(home), " cache" ))
52
+ .orElse(sys.env.get(" COURSIER_CACHE" ).map(absoluteFile))
53
+ .orElse(sys.props.get(" coursier.cache" ).map(absoluteFile)) match {
54
+ case Some (dir) => dir
55
+ case _ =>
56
+ if (isWindows) windowsCacheDirectory
57
+ else CacheDefaults .location
58
+ }
59
+ }
29
60
private lazy val coursierCache = {
61
+ import coursier .util .Task
30
62
val credentials = bootCredentials
31
- val cache = credentials.foldLeft(FileCache ()) { _.addCredentials(_) }
63
+ val cache = credentials.foldLeft(FileCache (defaultCacheLocation)(Task .sync)) {
64
+ _.addCredentials(_)
65
+ }
32
66
cache
33
67
}
34
68
private lazy val coursierRepos : Seq [Repository ] =
0 commit comments