def fetch_if

near-v-framework@0.4.0.0 · domain/architecture/system/effects.bend:85

import near-v-framework@0.4.0.0/domain/architecture/system/effects.bend as Effects
import Base
import bend-kit-files@0.1.0.0/files.bend as Fs
import near-v-framework@0.4.0.0/domain/architecture/system/effs/io.bend as X

85# The package's hash, as Bend's local cache names it. A package not cached yet is fetched first by
86# checking a file that imports it: the hub has it exactly when that succeeds.
87def fetch_if(missing: Bool, +home: String, +n: String, +v: String, +e: String, +cached: String) -> IO(String):
88  match missing:
89    case False{}:
90      IO.pure(String, cached)
91    case True{}:
92      do IO<String>:
93        X.write("/tmp/v-probe.bend", "import Base\nimport " ++ n ++ "@" ++ v ++ "/" ++ Fs.path.file_name(e) ++ " as P\n")
94        _ : Bool <- X.succeeds(home ++ "/.bend/bin/bend", ["/tmp/v-probe.bend", "--check-only"])
95        X.read(home ++ "/.bend/lib/names/" ++ n ++ "@" ++ v)

Uses (12)

Used by (1)