|
3 | 3 | ## ===========
|
4 | 4 | ## Saving to and Retrieving from disk
|
5 | 5 |
|
6 |
| -import ../../../bdd |
| 6 | +# import ../../../bdd |
7 | 7 |
|
8 | 8 | # valgrind throws if this file is imported into ./Config.nim
|
9 | 9 | import std/[
|
10 | 10 | asyncdispatch, # causes valgrind to throw
|
11 |
| - locks, |
| 11 | + # locks, |
12 | 12 | threadpool, # causes valgrind to throw
|
13 | 13 | ]
|
14 | 14 |
|
15 | 15 | import BoatConstants, BoatErrors
|
16 | 16 |
|
17 | 17 | # export asyncdispatch
|
18 | 18 |
|
19 |
| -type SaveType* = enum |
20 |
| - parsedConfig, |
21 |
| - upsertManifest, |
22 |
| - remoteManifest, |
23 |
| - |
24 |
| -proc fileDir*(self: SaveType): string = |
25 |
| - result = case self |
26 |
| - of parsedConfig, upsertManifest: cacheDir |
27 |
| - else: tempDir |
28 |
| - |
29 |
| -proc toDisk*[T]( |
30 |
| - self: SaveType, |
31 |
| - fname: string, |
32 |
| - data: T, |
33 |
| - ): Future[string] {.async.} = |
34 |
| - ## persists data to cache or temp dir and returns path |
35 |
| - ## if file already exists, will overwrite if content is different |
36 |
| - raise tddError |
37 |
| - # file exists ? |
38 |
| - # content is same? return true |
39 |
| - # persist data |
40 |
| - # lock |
41 |
| - # save as self.fileDir / hash(fname) |
42 |
| - # unlock |
43 |
| - # return success |
44 |
| - result = true |
45 |
| - |
46 |
| -proc fromDisk*[T]( |
47 |
| - self: SaveType, |
48 |
| - fname: string, |
49 |
| - to: T, |
50 |
| - errorNotFound = false |
51 |
| - ): Future[T] {.async.} = |
52 |
| - ## parse to T and return T |
53 |
| - ## throws if errorNotFound is true; else returns empty T |
54 |
| - raise tddError |
55 |
| - # yield readAsync self.fileDir / hash(fname) |
56 |
| - # if file not found / cant be read then throw if errorNotFound is true |
57 |
| - if errorNotFound and "cant load file" is string: raise fileLoadError |
58 |
| - else: result = new(to) |
| 19 | +# type SaveType* = enum |
| 20 | +# parsedConfig, |
| 21 | +# upsertManifest, |
| 22 | +# remoteManifest, |
| 23 | + |
| 24 | +# proc fileDir*(self: SaveType): string = |
| 25 | +# result = case self |
| 26 | +# of parsedConfig, upsertManifest: cacheDir |
| 27 | +# else: tempDir |
| 28 | + |
| 29 | +# proc toDisk*[T]( |
| 30 | +# self: SaveType, |
| 31 | +# fname: string, |
| 32 | +# data: T, |
| 33 | +# ): Future[string] {.async.} = |
| 34 | +# ## persists data to cache or temp dir and returns path |
| 35 | +# ## if file already exists, will overwrite if content is different |
| 36 | +# raise tddError |
| 37 | +# # file exists ? |
| 38 | +# # content is same? return true |
| 39 | +# # persist data |
| 40 | +# # lock |
| 41 | +# # save as self.fileDir / hash(fname) |
| 42 | +# # unlock |
| 43 | +# # return success |
| 44 | +# result = true |
| 45 | + |
| 46 | +# proc fromDisk*[T]( |
| 47 | +# self: SaveType, |
| 48 | +# fname: string, |
| 49 | +# to: T, |
| 50 | +# errorNotFound = false |
| 51 | +# ): Future[T] {.async.} = |
| 52 | +# ## parse to T and return T |
| 53 | +# ## throws if errorNotFound is true; else returns empty T |
| 54 | +# raise tddError |
| 55 | +# # yield readAsync self.fileDir / hash(fname) |
| 56 | +# # if file not found / cant be read then throw if errorNotFound is true |
| 57 | +# if errorNotFound and "cant load file" is string: raise fileLoadError |
| 58 | +# else: result = new(to) |
0 commit comments