Skip to content

Commit

Permalink
fix/valgrind-async-disaptch-threadpool-failure
Browse files Browse the repository at this point in the history
  • Loading branch information
noahehall committed Mar 15, 2023
1 parent f139355 commit a3e67a1
Showing 1 changed file with 42 additions and 42 deletions.
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 a3e67a1

Please sign in to comment.