Skip to content

Commit ce4139d

Browse files
committed
adds git fallback cacheOrApi to fix #373
1 parent 6e7ff66 commit ce4139d

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

buckaroo/DefaultSourceExplorer.fs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,31 @@ open Buckaroo.Console
66
open Buckaroo.RichOutput
77
open Buckaroo.Logger
88

9+
10+
911
type DefaultSourceExplorer (console : ConsoleManager, downloadManager : DownloadManager, gitManager : GitManager) =
1012
let logger = createLogger console (Some "explorer")
1113
let toOptional = Async.Catch >> (Async.map Choice.toOption)
1214

1315
let fromFileCache url revision path =
1416
gitManager.GetFile url revision path |> toOptional
1517

18+
19+
// We fetch from cache or api if possible.
20+
// However fetching from api might be not feasable if credentials are required.
21+
// In such case we fallback to git and try to find the requested commit.
1622
let cacheOrApi (api, url : string, rev : string, path : string) = async {
1723
let! cached = fromFileCache url rev path
1824
match cached with
1925
| Some data -> return data
20-
| None -> return! api rev path
26+
| None ->
27+
match! (api rev path |> Async.Catch) with
28+
| Choice1Of2 result ->
29+
return result
30+
| Choice2Of2 error ->
31+
logger.Info("failed to fetch file using api, falling back to git")
32+
do! gitManager.FindCommit url rev None
33+
return! fromFileCache url rev path |> Async.map (Option.getOrRaise <| error)
2134
}
2235

2336
let extractFileFromHttp (source : HttpLocation) (filePath : string) = async {

0 commit comments

Comments
 (0)