Skip to content

Commit fe5aed3

Browse files
committed
Prevent corruption of tar packages when downloading from registry
1 parent 7f45627 commit fe5aed3

5 files changed

Lines changed: 25 additions & 34 deletions

File tree

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spago.lock

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@
281281
},
282282
"package_set": {
283283
"address": {
284-
"registry": "75.0.0"
284+
"registry": "75.3.0"
285285
},
286286
"compiler": ">=0.15.15 <0.16.0",
287287
"content": {
@@ -354,6 +354,7 @@
354354
"codec-argonaut": "10.0.0",
355355
"codec-json": "2.0.0",
356356
"colors": "7.0.1",
357+
"compile-fail": "0.4.0",
357358
"concur-core": "0.5.0",
358359
"concur-react": "0.5.0",
359360
"concurrent-queues": "3.0.0",
@@ -492,10 +493,10 @@
492493
"hylograph-canvas": "0.1.0",
493494
"hylograph-d3-kernel": "0.1.0",
494495
"hylograph-graph": "0.2.0",
495-
"hylograph-layout": "0.2.0",
496-
"hylograph-music": "0.1.0",
496+
"hylograph-layout": "0.2.1",
497+
"hylograph-music": "0.2.0",
497498
"hylograph-optics": "0.1.0",
498-
"hylograph-selection": "0.1.1",
499+
"hylograph-selection": "0.3.4",
499500
"hylograph-simulation": "0.3.0",
500501
"hylograph-simulation-core": "0.1.0",
501502
"hylograph-simulation-halogen": "0.3.0",
@@ -546,6 +547,7 @@
546547
"leveldb": "1.0.1",
547548
"liminal": "1.0.1",
548549
"linalg": "6.0.0",
550+
"linear": "0.1.0",
549551
"lists": "7.0.0",
550552
"literals": "1.0.2",
551553
"logging": "3.0.0",
@@ -727,6 +729,7 @@
727729
"semirings": "7.0.0",
728730
"shuffle": "2.0.0",
729731
"sigil": "0.3.0",
732+
"sigil-hats": "0.2.0",
730733
"signal": "13.0.0",
731734
"simple-emitter": "3.0.1",
732735
"simple-i18n": "2.0.1",
@@ -740,7 +743,7 @@
740743
"soundfonts": "4.1.0",
741744
"sparse-matrices": "2.0.1",
742745
"sparse-polynomials": "3.0.1",
743-
"spec": "8.1.1",
746+
"spec": "8.1.2",
744747
"spec-discovery": "8.4.1",
745748
"spec-mocha": "5.1.1",
746749
"spec-node": "0.0.3",
@@ -880,7 +883,7 @@
880883
"yoga-dynamodb": "0.1.1",
881884
"yoga-elasticsearch": "0.1.1",
882885
"yoga-fastify": "0.5.1",
883-
"yoga-fastify-om": "0.4.1",
886+
"yoga-fastify-om": "0.4.4",
884887
"yoga-fetch": "1.0.1",
885888
"yoga-fetch-om": "0.6.2",
886889
"yoga-http-api": "0.3.1",
@@ -892,7 +895,7 @@
892895
"yoga-om-layer": "2.0.0",
893896
"yoga-om-strom": "0.4.2",
894897
"yoga-om-workerbees": "0.1.2",
895-
"yoga-opentelemetry": "0.1.1",
898+
"yoga-opentelemetry": "0.2.0",
896899
"yoga-options": "0.1.1",
897900
"yoga-pino": "0.1.1",
898901
"yoga-postgres": "6.0.0",
@@ -1004,10 +1007,6 @@
10041007
"ordered-collections",
10051008
"prelude"
10061009
]
1007-
},
1008-
"spec": {
1009-
"git": "https://github.com/purescript-spec/purescript-spec.git",
1010-
"ref": "2f8c7fd6ee04041d947f4629248695ac667257e1"
10111010
}
10121011
}
10131012
},
@@ -1354,15 +1353,6 @@
13541353
"tuples"
13551354
]
13561355
},
1357-
"debug": {
1358-
"type": "registry",
1359-
"version": "6.0.2",
1360-
"integrity": "sha256-d/EzRm/J2JyzvlIeo2Ex78Y7HRB0IXBitnVJywL4gHk=",
1361-
"dependencies": [
1362-
"functions",
1363-
"prelude"
1364-
]
1365-
},
13661356
"distributive": {
13671357
"type": "registry",
13681358
"version": "6.0.0",
@@ -2845,9 +2835,9 @@
28452835
]
28462836
},
28472837
"spec": {
2848-
"type": "git",
2849-
"url": "https://github.com/purescript-spec/purescript-spec.git",
2850-
"rev": "2f8c7fd6ee04041d947f4629248695ac667257e1",
2838+
"type": "registry",
2839+
"version": "8.1.2",
2840+
"integrity": "sha256-klPPJ6lBQI1CGOAdLJ+ZoGRt8XZippkTKjn53BrSkL0=",
28512841
"dependencies": [
28522842
"aff",
28532843
"ansi",
@@ -2856,7 +2846,6 @@
28562846
"bifunctors",
28572847
"control",
28582848
"datetime",
2859-
"debug",
28602849
"effect",
28612850
"either",
28622851
"exceptions",

spago.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ package:
8484
- spec-node
8585
workspace:
8686
packageSet:
87-
registry: 75.0.0
87+
registry: 75.3.0
8888
extraPackages:
8989
registry-lib:
9090
git: https://github.com/purescript/registry-dev.git
@@ -162,7 +162,3 @@ workspace:
162162
git: https://github.com/klntsky/purescript-search-trie.git
163163
ref: e7f7f22486a1dba22171ec885dbc2149dc815119
164164
json-codecs: 4.0.0
165-
spec:
166-
git: https://github.com/purescript-spec/purescript-spec.git
167-
ref: 2f8c7fd6ee04041d947f4629248695ac667257e1
168-

src/Spago/Command/Fetch.purs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,12 @@ fetchPackagesToLocalCache packages = do
342342
unless (archiveSha == versionMetadata.hash) do
343343
die $ "Archive fetched for " <> packageVersion <> " has a different hash (" <> Sha256.print archiveSha <> ") than expected (" <> Sha256.print versionMetadata.hash <> ")"
344344
-- if everything's alright we stash the tar in the global cache
345+
-- Write to a temp file then atomically rename, so parallel processes
346+
-- don't corrupt the archive by writing to the same path simultaneously.
347+
let tempArchivePath = globalCachePackagePath </> (versionString <> ".tar.gz." <> Path.basename tempDir)
345348
logDebug $ "Fetched archive for " <> packageVersion <> ", saving it in the global cache: " <> Path.quote archivePath
346-
FS.writeFile archivePath archiveBuffer
349+
FS.writeFile tempArchivePath archiveBuffer
350+
FS.moveSync { src: tempArchivePath, dst: archivePath }
347351
logDebug $ "Unpacking archive to temp folder: " <> Path.quote tempDir
348352
(liftEffect $ Tar.extract { filename: archivePath, cwd: tempDir }) >>= case _ of
349353
Right _ -> pure unit

src/Spago/Prelude.purs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import Data.String.Extra (levenshtein)
3434
import Data.Traversable (class Traversable)
3535
import Effect.Aff as Aff
3636
import Effect.Now as Now
37+
import Effect.Random as Random
3738
import JSON (JSON)
3839
import JSON as JSON
3940
import Node.Buffer as Buffer
@@ -175,7 +176,8 @@ mkTemp' maybeSuffix = liftAff do
175176
-- Get a random string
176177
(HexString random) <- liftEffect do
177178
now <- Now.now
178-
sha <- Sha256.hashString $ show now <> fromMaybe "" maybeSuffix
179+
rand <- Random.random
180+
sha <- Sha256.hashString $ show now <> show rand <> fromMaybe "" maybeSuffix
179181
shaToHex sha
180182
-- Return the dir, but don't make it - that's the responsibility of the client
181183
let tempDirPath = Paths.paths.temp </> String.drop 56 random

0 commit comments

Comments
 (0)