rm beacon_chain/filepath.nim

This commit is contained in:
Jenkins 2024-03-20 10:21:29 +02:00
parent 656114f5fc
commit 50a29368c3
4 changed files with 5 additions and 52 deletions

View File

@ -10,8 +10,7 @@ import
forks,
presets,
state_transition],
./spec/datatypes/[phase0, altair, bellatrix],
"."/filepath
./spec/datatypes/[phase0, altair, bellatrix]
from ./spec/datatypes/capella import BeaconState
from ./spec/datatypes/deneb import TrustedSignedBeaconBlock
export
@ -211,7 +210,7 @@ proc new(T: type BeaconChainDBV0,
): BeaconChainDBV0 =
BeaconChainDBV0(
)
proc new*(T: type BeaconChainDB,
proc new(T: type BeaconChainDB,
db: SqStoreRef,
cfg: RuntimeConfig = defaultRuntimeConfig
): BeaconChainDB =
@ -285,7 +284,7 @@ proc new*(T: type BeaconChainDB,
SqStoreRef.init("", "test", readOnly = readOnly, inMemory = true).expect(
"working database (out of memory?)")
else:
if (let res = secureCreatePath(dir); res.isErr):
if (let res = createPath(dir, 0o700); res.isErr):
quit 1
SqStoreRef.init(
dir, "nbc", readOnly = readOnly, manualCheckpoint = true).expectDb()

View File

@ -1,45 +0,0 @@
import stew/io2
type
ByteChar = byte | char
const INCOMPLETE_ERROR = IoErrorCode(28) # ENOSPC
proc secureCreatePath*(path: string): IoResult[void] =
when defined(windows):
let sres = createFoldersUserOnlySecurityDescriptor()
if sres.isErr():
error "Could not allocate security descriptor", path = path,
errorMsg = ioErrorMsg(sres.error), errorCode = $sres.error
err(sres.error)
else:
var sd = sres.get()
createPath(path, 0o700, secDescriptor = sd.getDescriptor())
else:
createPath(path, 0o700)
proc secureWriteFile*[T: ByteChar](path: string,
data: openArray[T]): IoResult[void] =
when defined(windows):
let sres = createFilesUserOnlySecurityDescriptor()
if sres.isErr():
error "Could not allocate security descriptor", path = path,
errorMsg = ioErrorMsg(sres.error), errorCode = $sres.error
err(sres.error())
else:
var sd = sres.get()
let res = writeFile(path, data, 0o600, sd.getDescriptor())
if res.isErr():
# writeFile() will not attempt to remove file on failure
discard removeFile(path)
err(res.error())
else:
ok()
else:
let res = writeFile(path, data, 0o600)
if res.isErr():
# writeFile() will not attempt to remove file on failure
discard removeFile(path)
err(res.error())
else:
ok()

View File

@ -159,7 +159,7 @@ proc start(node: BeaconNode) {.raises: [CatchableError].} =
when isMainModule:
import
confutils,
../beacon_chain/[conf, filepath]
../beacon_chain/conf
const
dataDir = "./test_keymanager_api"
nodeDataDir = dataDir / "node-0"

View File

@ -42,7 +42,6 @@ proc detectTTY*(stdoutKind: StdoutLogKind): StdoutLogKind =
when defaultChroniclesStream.outputs.type.arity == 2:
from std/os import splitFile
from "."/filepath import secureCreatePath
proc setupFileLimits*() =
when not defined(windows):
@ -87,7 +86,7 @@ proc setupLogging*(
let
logFile = logFile.get.string
logFileDir = splitFile(logFile).dir
lres = secureCreatePath(logFileDir)
lres = createPath(logFileDir, 0o700)
if lres.isOk():
try:
let