Skip to content

Commit ab40e47

Browse files
Gabriella439locallycompact
authored andcommitted
Fix dhall freeze --cache --all to be idempotent (dhall-lang#2500)
The fix in dhall-lang#2350 introduced a new problem: now `dhall freeze --cache --all` is not idempotent and will fail if you run it a second time on the same due to trying to resolve the `missing` import. This change fixes that.
1 parent e1ed817 commit ab40e47

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

dhall/src/Dhall/Freeze.hs

+12-1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,17 @@ freezeRemoteImportWithSettings settings directory import_ =
223223
Remote {} -> freezeImportWithSettings settings directory import_
224224
_ -> return import_
225225

226+
-- | See 'freezeRemoteImport'.
227+
freezeNonMissingImportWithSettings
228+
:: EvaluateSettings
229+
-> FilePath
230+
-> Import
231+
-> IO Import
232+
freezeNonMissingImportWithSettings settings directory import_ =
233+
case importType (importHashed import_) of
234+
Missing -> return import_
235+
_ -> freezeImportWithSettings settings directory import_
236+
226237
-- | See 'freeze'.
227238
freezeWithSettings
228239
:: EvaluateSettings
@@ -322,7 +333,7 @@ freezeExpressionWithSettings
322333
freezeExpressionWithSettings settings directory scope intent expression = do
323334
let freezeScope =
324335
case scope of
325-
AllImports -> freezeImportWithSettings
336+
AllImports -> freezeNonMissingImportWithSettings
326337
OnlyRemoteImports -> freezeRemoteImportWithSettings
327338

328339
let freezeFunction = freezeScope settings directory

dhall/src/Dhall/Main.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ parseMode =
513513
parseAllFlag =
514514
Options.Applicative.switch
515515
( Options.Applicative.long "all"
516-
<> Options.Applicative.help "Add integrity checks to all imports (not just remote imports)"
516+
<> Options.Applicative.help "Add integrity checks to all imports (not just remote imports) except for missing imports"
517517
)
518518

519519
parseCacheFlag =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- The purpose of this test is to verify that `dhall freeze --cached` is
2+
-- idempotent and doesn't attempt to resolve the `missing` import
3+
missing
4+
sha256:27abdeddfe8503496adeb623466caa47da5f63abd2bc6fa19f6cfcb73ecfed70
5+
? ./True.dhall
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
missing
2+
sha256:27abdeddfe8503496adeb623466caa47da5f63abd2bc6fa19f6cfcb73ecfed70
3+
? ./True.dhall

0 commit comments

Comments
 (0)