Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
noahehall committed Mar 15, 2023
1 parent f139355 commit 442d971
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: boat
name: boat-ci
on:
push:
branches: [develop, deploy]
Expand Down
84 changes: 42 additions & 42 deletions src/boat/private/FileManager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,56 @@
## ===========
## Saving to and Retrieving from disk

import ../../../bdd
# import ../../../bdd

# valgrind throws if this file is imported into ./Config.nim
import std/[
asyncdispatch, # causes valgrind to throw
locks,
# locks,
threadpool, # causes valgrind to throw
]

import BoatConstants, BoatErrors

# export asyncdispatch

type SaveType* = enum
parsedConfig,
upsertManifest,
remoteManifest,

proc fileDir*(self: SaveType): string =
result = case self
of parsedConfig, upsertManifest: cacheDir
else: tempDir

proc toDisk*[T](
self: SaveType,
fname: string,
data: T,
): Future[string] {.async.} =
## persists data to cache or temp dir and returns path
## if file already exists, will overwrite if content is different
raise tddError
# file exists ?
# content is same? return true
# persist data
# lock
# save as self.fileDir / hash(fname)
# unlock
# return success
result = true

proc fromDisk*[T](
self: SaveType,
fname: string,
to: T,
errorNotFound = false
): Future[T] {.async.} =
## parse to T and return T
## throws if errorNotFound is true; else returns empty T
raise tddError
# yield readAsync self.fileDir / hash(fname)
# if file not found / cant be read then throw if errorNotFound is true
if errorNotFound and "cant load file" is string: raise fileLoadError
else: result = new(to)
# type SaveType* = enum
# parsedConfig,
# upsertManifest,
# remoteManifest,

# proc fileDir*(self: SaveType): string =
# result = case self
# of parsedConfig, upsertManifest: cacheDir
# else: tempDir

# proc toDisk*[T](
# self: SaveType,
# fname: string,
# data: T,
# ): Future[string] {.async.} =
# ## persists data to cache or temp dir and returns path
# ## if file already exists, will overwrite if content is different
# raise tddError
# # file exists ?
# # content is same? return true
# # persist data
# # lock
# # save as self.fileDir / hash(fname)
# # unlock
# # return success
# result = true

# proc fromDisk*[T](
# self: SaveType,
# fname: string,
# to: T,
# errorNotFound = false
# ): Future[T] {.async.} =
# ## parse to T and return T
# ## throws if errorNotFound is true; else returns empty T
# raise tddError
# # yield readAsync self.fileDir / hash(fname)
# # if file not found / cant be read then throw if errorNotFound is true
# if errorNotFound and "cant load file" is string: raise fileLoadError
# else: result = new(to)

0 comments on commit 442d971

Please sign in to comment.