go-p2p/node/core_fs.go
Virgil be55b2499b chore(node): upgrade to core v0.8.0-alpha.1
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 14:31:25 +00:00

53 lines
1 KiB
Go

// SPDX-License-Identifier: EUPL-1.2
package node
import core "dappco.re/go/core"
var localFS = (&core.Fs{}).New("/")
func fsEnsureDir(path string) error {
return fsResultErr(localFS.EnsureDir(path))
}
func fsWrite(path, content string) error {
return fsResultErr(localFS.Write(path, content))
}
func fsRead(path string) (string, error) {
result := localFS.Read(path)
if !result.OK {
return "", fsResultErr(result)
}
content, ok := result.Value.(string)
if !ok {
return "", core.E("node.fsRead", "filesystem read returned non-string content", nil)
}
return content, nil
}
func fsDelete(path string) error {
return fsResultErr(localFS.Delete(path))
}
func fsRename(oldPath, newPath string) error {
return fsResultErr(localFS.Rename(oldPath, newPath))
}
func fsExists(path string) bool {
return localFS.Exists(path)
}
func fsResultErr(result core.Result) error {
if result.OK {
return nil
}
if err, ok := result.Value.(error); ok && err != nil {
return err
}
return core.E("node.fs", "filesystem operation failed", nil)
}