Skip to content

Commit bcbe7c1

Browse files
committed
Cache git clones in cache root.
1 parent 4fe447c commit bcbe7c1

File tree

9 files changed

+70
-18
lines changed

9 files changed

+70
-18
lines changed

src/Git.gren

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Git exposing
22
( Error(..)
33
, report
44
, clonePackage
5+
, clonePackageCached
56
, fetchLatestVersion
67
, fetchVersions
78
, hasLocalTag
@@ -11,12 +12,14 @@ module Git exposing
1112

1213
import Bytes
1314
import ChildProcess
15+
import FileSystem
1416
import FileSystem.Path as Path exposing (Path)
1517
import Compiler.PackageName as PackageName exposing (PackageName)
1618
import SemanticVersion exposing (SemanticVersion)
1719
import Task exposing (Task)
1820
import Terminal.Help as Help
1921
import CLI.PrettyPrinter as PP
22+
import Compiler.Paths
2023

2124

2225
type Error
@@ -127,6 +130,37 @@ clonePackage cpPerm repo name version =
127130
)
128131

129132

133+
clonePackageCached :
134+
{ childProcessPermission : ChildProcess.Permission
135+
, fileSystemPermission : FileSystem.Permission
136+
, cacheRoot : Compiler.Paths.CacheRoot
137+
, packageName : PackageName
138+
, version : SemanticVersion
139+
}
140+
-> Task Error Path
141+
clonePackageCached { childProcessPermission, fileSystemPermission, cacheRoot, packageName, version } =
142+
let
143+
packageDir =
144+
PackageName.toString packageName ++ "__" ++ SemanticVersion.toString version
145+
|> String.replace "/" "_"
146+
|> String.replace "." "_"
147+
|> Path.fromPosixString
148+
149+
packageSourcesDir =
150+
Compiler.Paths.packageSources cacheRoot
151+
152+
repoDir =
153+
Path.prepend packageSourcesDir packageDir
154+
in
155+
FileSystem.checkAccess fileSystemPermission [] repoDir
156+
|> Task.map (\_ -> repoDir)
157+
|> Task.onError
158+
(\_ ->
159+
clonePackage childProcessPermission repoDir packageName version
160+
|> Task.map (\_ -> repoDir)
161+
)
162+
163+
130164
constructFailedCommand : Array String -> ChildProcess.FailedRun -> Error
131165
constructFailedCommand args details =
132166
FailedCommand

src/Main.gren

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ parseUserArgs model compilerPath =
388388
Terminal.Init.run
389389
{ fsPermission = model.fsPermission
390390
, cpPermission = model.cpPermission
391+
, cacheRoot = model.cacheRoot
391392
, stdout = model.stdout
392393
, stdin = model.stdin
393394
, interactive = model.interactive
@@ -409,6 +410,7 @@ parseUserArgs model compilerPath =
409410
Terminal.PackageInstall.run
410411
{ fsPermission = model.fsPermission
411412
, cpPermission = model.cpPermission
413+
, cacheRoot = model.cacheRoot
412414
, interactive = model.interactive
413415
, useColor = model.useColor
414416
, stdout = model.stdout
@@ -471,6 +473,7 @@ parseUserArgs model compilerPath =
471473
Terminal.Run.make
472474
{ fsPermission = model.fsPermission
473475
, cpPermission = model.cpPermission
476+
, cacheRoot = model.cacheRoot
474477
, useColor = model.useColor
475478
, compilerPath = compilerPath
476479
, pathToString = model.pathToString
@@ -540,6 +543,7 @@ parseUserArgs model compilerPath =
540543
Terminal.PackageInstall.addPackage
541544
{ fsPermission = model.fsPermission
542545
, cpPermission = model.cpPermission
546+
, cacheRoot = model.cacheRoot
543547
, interactive = model.interactive
544548
, useColor = model.useColor
545549
, stdout = model.stdout
@@ -561,6 +565,7 @@ parseUserArgs model compilerPath =
561565
Terminal.PackageUninstall.run
562566
{ fsPermission = model.fsPermission
563567
, cpPermission = model.cpPermission
568+
, cacheRoot = model.cacheRoot
564569
, interactive = model.interactive
565570
, useColor = model.useColor
566571
, stdout = model.stdout
@@ -602,6 +607,7 @@ parseUserArgs model compilerPath =
602607
Terminal.PackageValidate.run
603608
{ fsPermission = model.fsPermission
604609
, cpPermission = model.cpPermission
610+
, cacheRoot = model.cacheRoot
605611
, interactive = model.interactive
606612
, useColor = model.useColor
607613
, stdout = model.stdout
@@ -634,6 +640,7 @@ parseUserArgs model compilerPath =
634640
Terminal.PackageBump.run
635641
{ fsPermission = model.fsPermission
636642
, cpPermission = model.cpPermission
643+
, cacheRoot = model.cacheRoot
637644
, interactive = model.interactive
638645
, useColor = model.useColor
639646
, stdout = model.stdout
@@ -666,6 +673,7 @@ parseUserArgs model compilerPath =
666673
Terminal.PackageDiff.runLocal
667674
{ fsPermission = model.fsPermission
668675
, cpPermission = model.cpPermission
676+
, cacheRoot = model.cacheRoot
669677
, interactive = model.interactive
670678
, useColor = model.useColor
671679
, stdout = model.stdout
@@ -678,6 +686,7 @@ parseUserArgs model compilerPath =
678686
Terminal.PackageDiff.runLocal
679687
{ fsPermission = model.fsPermission
680688
, cpPermission = model.cpPermission
689+
, cacheRoot = model.cacheRoot
681690
, interactive = model.interactive
682691
, useColor = model.useColor
683692
, stdout = model.stdout
@@ -702,6 +711,7 @@ parseUserArgs model compilerPath =
702711
Terminal.PackageDiff.runGlobal
703712
{ fsPermission = model.fsPermission
704713
, cpPermission = model.cpPermission
714+
, cacheRoot = model.cacheRoot
705715
, interactive = model.interactive
706716
, useColor = model.useColor
707717
, stdout = model.stdout
@@ -717,6 +727,7 @@ parseUserArgs model compilerPath =
717727
Terminal.PackageDiff.runGlobal
718728
{ fsPermission = model.fsPermission
719729
, cpPermission = model.cpPermission
730+
, cacheRoot = model.cacheRoot
720731
, interactive = model.interactive
721732
, useColor = model.useColor
722733
, stdout = model.stdout
@@ -764,6 +775,7 @@ resolveProject model =
764775
Terminal.PackageInstall.run
765776
{ fsPermission = model.fsPermission
766777
, cpPermission = model.cpPermission
778+
, cacheRoot = model.cacheRoot
767779
, interactive = model.interactive
768780
, useColor = model.useColor
769781
, stdout = model.stdout

src/Terminal/Init.gren

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Compiler.Platform as Platform exposing (Platform)
1919
import Compiler.PackageName as PackageName exposing (PackageName)
2020
import Compiler.Outline as Outline
2121
import Compiler.License as License
22+
import Compiler.Paths
2223
import Terminal.Help
2324
import Git
2425
import SemanticVersion exposing (SemanticVersion)
@@ -33,6 +34,7 @@ type alias Config =
3334
, stdin : Stream.Readable Bytes
3435
, fsPermission : FileSystem.Permission
3536
, cpPermission : ChildProcess.Permission
37+
, cacheRoot : Compiler.Paths.CacheRoot
3638
, interactive : Bool
3739
, useColor : Bool
3840
, package : Bool
@@ -192,6 +194,7 @@ generateGrenJson config deps =
192194
, stdin = config.stdin
193195
, fsPermission = config.fsPermission
194196
, cpPermission = config.cpPermission
197+
, cacheRoot = config.cacheRoot
195198
, interactive = config.interactive
196199
, useColor = config.useColor
197200
}

src/Terminal/PackageBump.gren

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import CLI.PrettyPrinter as PP
3535
type alias Config =
3636
{ fsPermission : FileSystem.Permission
3737
, cpPermission : ChildProcess.Permission
38+
, cacheRoot : Compiler.Paths.CacheRoot
3839
, interactive : Bool
3940
, useColor : Bool
4041
, stdout : Stream.Writable Bytes
@@ -90,6 +91,7 @@ run config { projectPath, outline } =
9091
Terminal.PackageInstall.run
9192
{ fsPermission = config.fsPermission
9293
, cpPermission = config.cpPermission
94+
, cacheRoot = config.cacheRoot
9395
, interactive = config.interactive
9496
, useColor = config.useColor
9597
, stdout = config.stdout
@@ -136,6 +138,7 @@ run config { projectPath, outline } =
136138
Terminal.PackageInstall.run
137139
{ fsPermission = config.fsPermission
138140
, cpPermission = config.cpPermission
141+
, cacheRoot = config.cacheRoot
139142
, interactive = config.interactive
140143
, useColor = config.useColor
141144
, stdout = config.stdout

src/Terminal/PackageDiff.gren

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import CLI.PrettyPrinter as PP
3838
type alias Config =
3939
{ fsPermission : FileSystem.Permission
4040
, cpPermission : ChildProcess.Permission
41+
, cacheRoot : Compiler.Paths.CacheRoot
4142
, interactive : Bool
4243
, useColor : Bool
4344
, stdout : Stream.Writable Bytes
@@ -110,6 +111,7 @@ runLocal config maybeVersion =
110111
Terminal.PackageInstall.run
111112
{ fsPermission = config.fsPermission
112113
, cpPermission = config.cpPermission
114+
, cacheRoot = config.cacheRoot
113115
, interactive = config.interactive
114116
, useColor = config.useColor
115117
, stdout = config.stdout
@@ -230,6 +232,7 @@ installHiddenProject config projectPath packageName packageVersion =
230232
Terminal.PackageInstall.run
231233
{ fsPermission = config.fsPermission
232234
, cpPermission = config.cpPermission
235+
, cacheRoot = config.cacheRoot
233236
, interactive = config.interactive
234237
, useColor = config.useColor
235238
, stdout = config.stdout

src/Terminal/PackageInstall.gren

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import Terminal.Help as Help
4242
type alias Config =
4343
{ fsPermission : FileSystem.Permission
4444
, cpPermission : ChildProcess.Permission
45+
, cacheRoot : Compiler.Paths.CacheRoot
4546
, interactive : Bool
4647
, useColor : Bool
4748
, stdout : Stream.Writable Bytes
@@ -372,9 +373,6 @@ installStep config opts =
372373
bundlePath =
373374
packageBundlePath name lowerBound opts.projectPath
374375

375-
repoPath =
376-
localRepoPath name lowerBound opts.projectPath
377-
378376
packageReportTask =
379377
Stream.Log.string config.stdout (" " ++ PackageName.toString name ++ " ")
380378

@@ -389,21 +387,13 @@ installStep config opts =
389387
reportTask
390388
|> Task.andThen
391389
(\_ ->
392-
FileSystem.remove config.fsPermission { recursive = True, ignoreErrors = False } repoPath
393-
)
394-
|> Task.onError (\err ->
395-
if FileSystem.errorIsNoSuchFileOrDirectory err then
396-
Task.succeed repoPath
397-
398-
else
399-
Task.fail <| PackageInstallFileSystemError
400-
{ package = name
401-
, error = err
390+
Git.clonePackageCached
391+
{ childProcessPermission = config.cpPermission
392+
, fileSystemPermission = config.fsPermission
393+
, cacheRoot = config.cacheRoot
394+
, packageName = name
395+
, version = lowerBound
402396
}
403-
)
404-
|> Task.andThen
405-
(\_ ->
406-
Git.clonePackage config.cpPermission repoPath name lowerBound
407397
|> Task.mapError
408398
(\err ->
409399
PackageInstallGitError
@@ -412,7 +402,7 @@ installStep config opts =
412402
}
413403
)
414404
)
415-
|> Task.andThen (\{} ->
405+
|> Task.andThen (\repoPath ->
416406
(Path.append (Path.fromPosixString "gren.json") repoPath)
417407
|> readOutline config.fsPermission
418408
|> Task.mapError

src/Terminal/PackageUninstall.gren

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import Terminal.PackageInstall
3131
type alias Config =
3232
{ fsPermission : FileSystem.Permission
3333
, cpPermission : ChildProcess.Permission
34+
, cacheRoot : Compiler.Paths.CacheRoot
3435
, interactive : Bool
3536
, useColor : Bool
3637
, stdout : Stream.Writable Bytes

src/Terminal/PackageValidate.gren

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import CLI.PrettyPrinter as PP
3636
type alias Config =
3737
{ fsPermission : FileSystem.Permission
3838
, cpPermission : ChildProcess.Permission
39+
, cacheRoot : Compiler.Paths.CacheRoot
3940
, interactive : Bool
4041
, useColor : Bool
4142
, stdout : Stream.Writable Bytes
@@ -108,6 +109,7 @@ run config { projectPath, outline } =
108109
Terminal.PackageInstall.run
109110
{ fsPermission = config.fsPermission
110111
, cpPermission = config.cpPermission
112+
, cacheRoot = config.cacheRoot
111113
, interactive = config.interactive
112114
, useColor = config.useColor
113115
, stdout = config.stdout
@@ -175,6 +177,7 @@ run config { projectPath, outline } =
175177
Terminal.PackageInstall.run
176178
{ fsPermission = config.fsPermission
177179
, cpPermission = config.cpPermission
180+
, cacheRoot = config.cacheRoot
178181
, interactive = config.interactive
179182
, useColor = config.useColor
180183
, stdout = config.stdout

src/Terminal/Run.gren

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Terminal.Run exposing
1111
import CLI.PrettyPrinter as PP
1212
import Compiler.PackageName as PackageName exposing (PackageName)
1313
import Compiler.Backend as Backend
14+
import Compiler.Paths
1415
import Bytes exposing (Bytes)
1516
import ChildProcess
1617
import Compiler.Backend
@@ -38,6 +39,7 @@ type Error
3839

3940
type alias MakeConfig msg =
4041
{ fsPermission : FileSystem.Permission
42+
, cacheRoot : Compiler.Paths.CacheRoot
4143
, cpPermission : ChildProcess.Permission
4244
, useColor : Bool
4345
, compilerPath : Path
@@ -96,6 +98,7 @@ makeProject config projectOutline =
9698
PackageInstall.run
9799
{ fsPermission = config.fsPermission
98100
, cpPermission = config.cpPermission
101+
, cacheRoot = config.cacheRoot
99102
, useColor = config.useColor
100103
, interactive = False
101104
, stdout = nullStream |> Stream.writable

0 commit comments

Comments
 (0)