Skip to content

Commit fae551b

Browse files
committed
Cache more clone operations.
1 parent bcbe7c1 commit fae551b

File tree

4 files changed

+87
-141
lines changed

4 files changed

+87
-141
lines changed

src/Terminal/PackageBump.gren

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ run config { projectPath, outline } =
110110
)
111111
|> Task.andThen
112112
(\{ packageName, packageVersion, knownVersions, currentPackage } ->
113-
let
114-
repoPath =
115-
Terminal.PackageInstall.localRepoPath packageName packageVersion projectPath
116-
in
117-
FileSystem.remove config.fsPermission { recursive = True, ignoreErrors = False } repoPath
118-
|> Task.onError (\_ -> Task.succeed repoPath) -- Probably because directory doesn't exist, that's fine
119-
|> Task.andThen (\_ -> Git.clonePackage config.cpPermission repoPath packageName packageVersion)
113+
Git.clonePackageCached
114+
{ childProcessPermission = config.cpPermission
115+
, fileSystemPermission = config.fsPermission
116+
, cacheRoot = config.cacheRoot
117+
, packageName = packageName
118+
, version = packageVersion
119+
}
120120
|> Task.mapError (\_ -> PreviousPackageCorruption)
121121
|> Task.andThen
122-
(\_ ->
122+
(\repoPath ->
123123
Path.append (Path.fromPosixString "gren.json") repoPath
124124
|> Terminal.PackageInstall.readOutline config.fsPermission
125125
|> Task.mapError (\_ -> PreviousPackageCorruption)
@@ -132,26 +132,26 @@ run config { projectPath, outline } =
132132
Err err ->
133133
Task.fail PreviousPackageCorruption
134134
)
135-
)
136-
|> Task.andThen
137-
(\publishedOutline ->
138-
Terminal.PackageInstall.run
139-
{ fsPermission = config.fsPermission
140-
, cpPermission = config.cpPermission
141-
, cacheRoot = config.cacheRoot
142-
, interactive = config.interactive
143-
, useColor = config.useColor
144-
, stdout = config.stdout
145-
, stdin = config.stdin
146-
}
147-
{ projectPath = repoPath, outline = publishedOutline }
148-
|> Task.mapError (\_ -> PreviousPackageCorruption)
149-
|> Task.map
150-
(\resolved ->
151-
{ currentPackage = currentPackage
152-
, publishedPackage = resolved
153-
, knownVersions = knownVersions
154-
}
135+
|> Task.andThen
136+
(\publishedOutline ->
137+
Terminal.PackageInstall.run
138+
{ fsPermission = config.fsPermission
139+
, cpPermission = config.cpPermission
140+
, cacheRoot = config.cacheRoot
141+
, interactive = config.interactive
142+
, useColor = config.useColor
143+
, stdout = config.stdout
144+
, stdin = config.stdin
145+
}
146+
{ projectPath = repoPath, outline = publishedOutline }
147+
|> Task.mapError (\_ -> PreviousPackageCorruption)
148+
|> Task.map
149+
(\resolved ->
150+
{ currentPackage = currentPackage
151+
, publishedPackage = resolved
152+
, knownVersions = knownVersions
153+
}
154+
)
155155
)
156156
)
157157
)

src/Terminal/PackageDiff.gren

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -185,35 +185,24 @@ prettifyLocalError error =
185185

186186

187187
type InstallHiddenProjectError
188-
= HiddenProjectFileSystemError FileSystem.Error
189-
| HiddenProjectGitCloneError Git.Error
188+
= HiddenProjectGitCloneError Git.Error
190189
| HiddenProjectReadOutlineError FileSystem.Error
191190
| HiddenProjectOutlineDecodeError Decode.Error
192191
| HiddenProjectInstallError Terminal.PackageInstall.PackageInstallError
193192

194193

195194
installHiddenProject : Config -> Path -> PackageName -> SemanticVersion -> Task InstallHiddenProjectError Terminal.PackageInstall.PackageResolution
196195
installHiddenProject config projectPath packageName packageVersion =
197-
let
198-
repoPath =
199-
Terminal.PackageInstall.localRepoPath packageName packageVersion projectPath
200-
in
201-
FileSystem.remove config.fsPermission { recursive = True, ignoreErrors = False } repoPath
202-
|> Task.onError
203-
(\err ->
204-
if FileSystem.errorIsNoSuchFileOrDirectory err then
205-
Task.succeed repoPath
206-
207-
else
208-
Task.fail <| HiddenProjectFileSystemError err
209-
)
210-
|> Task.andThen
211-
(\_ ->
212-
Git.clonePackage config.cpPermission repoPath packageName packageVersion
213-
|> Task.mapError HiddenProjectGitCloneError
214-
)
196+
Git.clonePackageCached
197+
{ childProcessPermission = config.cpPermission
198+
, fileSystemPermission = config.fsPermission
199+
, cacheRoot = config.cacheRoot
200+
, packageName = packageName
201+
, version = packageVersion
202+
}
203+
|> Task.mapError HiddenProjectGitCloneError
215204
|> Task.andThen
216-
(\_ ->
205+
(\repoPath ->
217206
Path.append (Path.fromPosixString "gren.json") repoPath
218207
|> Terminal.PackageInstall.readOutline config.fsPermission
219208
|> Task.mapError HiddenProjectReadOutlineError
@@ -226,40 +215,26 @@ installHiddenProject config projectPath packageName packageVersion =
226215
Err err ->
227216
Task.fail <| HiddenProjectOutlineDecodeError err
228217
)
229-
)
230-
|> Task.andThen
231-
(\publishedOutline ->
232-
Terminal.PackageInstall.run
233-
{ fsPermission = config.fsPermission
234-
, cpPermission = config.cpPermission
235-
, cacheRoot = config.cacheRoot
236-
, interactive = config.interactive
237-
, useColor = config.useColor
238-
, stdout = config.stdout
239-
, stdin = config.stdin
240-
}
241-
{ projectPath = repoPath, outline = publishedOutline }
242-
|> Task.mapError HiddenProjectInstallError
218+
|> Task.andThen
219+
(\publishedOutline ->
220+
Terminal.PackageInstall.run
221+
{ fsPermission = config.fsPermission
222+
, cpPermission = config.cpPermission
223+
, cacheRoot = config.cacheRoot
224+
, interactive = config.interactive
225+
, useColor = config.useColor
226+
, stdout = config.stdout
227+
, stdin = config.stdin
228+
}
229+
{ projectPath = repoPath, outline = publishedOutline }
230+
|> Task.mapError HiddenProjectInstallError
231+
)
243232
)
244233

245234

246235
prettifyHiddenProjectError : InstallHiddenProjectError -> PP.Document
247236
prettifyHiddenProjectError error =
248237
when error is
249-
HiddenProjectFileSystemError fsErr ->
250-
Help.report
251-
"FAILED TO INSTALL PACKAGE"
252-
Nothing
253-
(PP.verticalBlock
254-
[ PP.words "An error occured while I was installing the requested package."
255-
, PP.empty
256-
, PP.words "The error is:"
257-
, PP.empty
258-
, PP.words (FileSystem.errorToString fsErr)
259-
|> PP.indent
260-
]
261-
)
262-
263238
HiddenProjectGitCloneError gitError ->
264239
Git.report
265240
"FAILED TO FETCH PACKAGE"
@@ -306,7 +281,6 @@ type GlobalError
306281

307282
runGlobal : Config -> PackageName -> SemanticVersion -> SemanticVersion -> Task GlobalError Result
308283
runGlobal config packageName lowerVersion upperVersion =
309-
-- TODO: Store in global cache
310284
-- TODO: Perform application check here when packageName isn't specified
311285
Terminal.PackageInstall.readProjectOutline config.fsPermission
312286
|> Task.mapError GlobalReadProjectOutlineError

src/Terminal/PackageValidate.gren

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,16 @@ run config { projectPath, outline } =
140140
}
141141

142142
Just packageVersion ->
143-
let
144-
repoPath =
145-
Terminal.PackageInstall.localRepoPath pkgOutline.name packageVersion projectPath
146-
in
147-
FileSystem.remove config.fsPermission { recursive = True, ignoreErrors = False } repoPath
148-
|> Task.onError
149-
(\err ->
150-
if FileSystem.errorIsNoSuchFileOrDirectory err then
151-
Task.succeed repoPath
152-
else
153-
Task.fail PreviousPackageCorrupted
154-
)
155-
|> Task.andThen
156-
(\_ ->
157-
Git.clonePackage config.cpPermission repoPath pkgOutline.name packageVersion
158-
|> Task.mapError (\_ -> PreviousPackageCorrupted)
159-
)
143+
Git.clonePackageCached
144+
{ childProcessPermission = config.cpPermission
145+
, fileSystemPermission = config.fsPermission
146+
, cacheRoot = config.cacheRoot
147+
, packageName = pkgOutline.name
148+
, version = packageVersion
149+
}
150+
|> Task.mapError (\_ -> PreviousPackageCorrupted)
160151
|> Task.andThen
161-
(\_ ->
152+
(\repoPath ->
162153
Path.append (Path.fromPosixString "gren.json") repoPath
163154
|> Terminal.PackageInstall.readOutline config.fsPermission
164155
|> Task.mapError (\_ -> PreviousPackageCorrupted)
@@ -171,20 +162,20 @@ run config { projectPath, outline } =
171162
Err err ->
172163
Task.fail PreviousPackageCorrupted
173164
)
174-
)
175-
|> Task.andThen
176-
(\previousOutline ->
177-
Terminal.PackageInstall.run
178-
{ fsPermission = config.fsPermission
179-
, cpPermission = config.cpPermission
180-
, cacheRoot = config.cacheRoot
181-
, interactive = config.interactive
182-
, useColor = config.useColor
183-
, stdout = config.stdout
184-
, stdin = config.stdin
185-
}
186-
{ projectPath = repoPath, outline = previousOutline }
187-
|> Task.mapError (\_ -> PreviousPackageCorrupted)
165+
|> Task.andThen
166+
(\previousOutline ->
167+
Terminal.PackageInstall.run
168+
{ fsPermission = config.fsPermission
169+
, cpPermission = config.cpPermission
170+
, cacheRoot = config.cacheRoot
171+
, interactive = config.interactive
172+
, useColor = config.useColor
173+
, stdout = config.stdout
174+
, stdin = config.stdin
175+
}
176+
{ projectPath = repoPath, outline = previousOutline }
177+
|> Task.mapError (\_ -> PreviousPackageCorrupted)
178+
)
188179
)
189180
|> Task.map
190181
(\previousPackage ->

src/Terminal/Run.gren

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ import Terminal.Help as Help
3131

3232

3333
type Error
34-
= TempPathError FileSystem.Error
35-
| ReadProjectOutlineError PackageInstall.ReadProjectOutlineError
34+
= ReadProjectOutlineError PackageInstall.ReadProjectOutlineError
3635
| PackageInstallError PackageInstall.PackageInstallError
3736
| NotAnApplication
3837

@@ -152,19 +151,17 @@ makeProject config projectOutline =
152151
clonePackage : MakeConfig msg -> PackageName -> Task Error ProjectOutline
153152
clonePackage config packageName =
154153
let
155-
getTempDir =
156-
FileSystem.makeTempDirectory config.fsPermission "gren-run"
157-
|> Task.mapError TempPathError
158-
159-
clone tempDir =
154+
clone =
160155
Git.fetchLatestVersion config.cpPermission packageName
161156
|> Task.andThen
162157
(\version ->
163-
Git.clonePackage
164-
config.cpPermission
165-
tempDir
166-
packageName
167-
version
158+
Git.clonePackageCached
159+
{ childProcessPermission = config.cpPermission
160+
, fileSystemPermission = config.fsPermission
161+
, cacheRoot = config.cacheRoot
162+
, packageName = packageName
163+
, version = version
164+
}
168165
)
169166
|> Task.mapError
170167
(\e ->
@@ -175,11 +172,10 @@ clonePackage config packageName =
175172
}
176173
)
177174
in
178-
Task.await getTempDir <| \tempDir ->
179-
Task.await (clone tempDir) <| \_ ->
180-
Task.await (getProjectOutline config.fsPermission tempDir) <| \outline ->
175+
Task.await clone <| \repoDir ->
176+
Task.await (getProjectOutline config.fsPermission repoDir) <| \outline ->
181177
Task.succeed
182-
{ projectPath = tempDir
178+
{ projectPath = repoDir
183179
, outline = outline
184180
}
185181

@@ -286,21 +282,6 @@ getOutputPath projectOutline =
286282
prettifyError : Error -> PP.Document
287283
prettifyError error =
288284
when error is
289-
TempPathError err ->
290-
Help.report
291-
"FILESYSTEM ERROR"
292-
Nothing
293-
(PP.verticalBlock
294-
[ PP.words "Failed to access temporary file path."
295-
, PP.empty
296-
, PP.words "The error provided by the operating system is:"
297-
, PP.empty
298-
, PP.words (FileSystem.errorToString err)
299-
|> PP.color PP.Red
300-
|> PP.indent
301-
]
302-
)
303-
304285
NotAnApplication ->
305286
Help.report
306287
"NOT AN APPLICATION"

0 commit comments

Comments
 (0)