Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cache bug and fail on cache creation failures #296

Merged
merged 2 commits into from
Jul 28, 2021
Merged
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.dhallj.imports

import java.nio.file.{Files, Path, Paths}

import cats.Applicative
import cats.effect.Async
import cats.implicits._
import java.nio.file.{Files, Path, Paths}
import org.dhallj.core.DhallException.ResolutionFailure

trait ImportCache[F[_]] {
def get(key: Array[Byte]): F[Option[Array[Byte]]]
Expand Down Expand Up @@ -73,17 +73,10 @@ object ImportCache {
if (isWindows)
makeCacheFromEnvVar("LOCALAPPDATA", "")
else makeCacheFromEnvVar("HOME", ".cache")
cache <- cacheO.fold[F[ImportCache[F]]](F.as(warnCacheNotCreated, new NoopImportCache[F]))(F.pure)
cache <- F.fromOption(cacheO, new ResolutionFailure("Failed to create cache"))
} yield cache

def isWindows = System.getProperty("os.name").toLowerCase.contains("Windows")

def warnCacheNotCreated: F[Unit] =
F.delay(
println(
"WARNING: failed to create cache at either $XDG_CACHE_HOME}/dhall or $HOME/.cache/dhall. Are these locations writable?"
)
)
def isWindows = System.getProperty("os.name").toLowerCase.contains("windows")

for {
xdgCache <- makeCacheFromEnvVar("XDG_CACHE_HOME", "")
Expand Down