ce7cb702218693d08ea6d83464d2457c9250027c
This commit is contained in:
commit
34c5f8963c
1 changed files with 145336 additions and 0 deletions
34
services/frigate/model.fsx
Normal file
34
services/frigate/model.fsx
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
module Model
|
||||
|
||||
open System
|
||||
open System.IO
|
||||
open System.Security.Cryptography
|
||||
|
||||
type Outcome =
|
||||
| Cached
|
||||
| Installed
|
||||
|
||||
let private checksum path =
|
||||
use input = File.OpenRead path
|
||||
SHA256.HashData input |> Convert.ToHexString |> _.ToLowerInvariant()
|
||||
|
||||
let install expected destination (download: Stream -> unit) =
|
||||
if File.Exists destination && checksum destination = expected then
|
||||
Cached
|
||||
else
|
||||
Directory.CreateDirectory(Path.GetDirectoryName destination) |> ignore
|
||||
let temporary = destination + ".incoming"
|
||||
|
||||
try
|
||||
do
|
||||
use output = File.Create temporary
|
||||
download output
|
||||
|
||||
if checksum temporary <> expected then
|
||||
invalidOp "model checksum differs"
|
||||
|
||||
File.Move(temporary, destination, true)
|
||||
Installed
|
||||
finally
|
||||
if File.Exists temporary then
|
||||
File.Delete temporary
|
||||
Loading…
Reference in a new issue