fix bolt path
This commit is contained in:
parent
c04c3e8778
commit
efee1d19ff
29
.github/ISSUE_TEMPLATE.md
vendored
29
.github/ISSUE_TEMPLATE.md
vendored
@ -1,29 +0,0 @@
|
||||
<!--
|
||||
If you are reporting a new issue, please check to see if it's already been reported
|
||||
by searching the issue list for this repository first, to avoid duplicates. If there
|
||||
is a duplicate, please close your issue and add a comment to the existing issue instead.
|
||||
|
||||
If you suspect your issue is a bug, please edit your issue description to
|
||||
include the BUG REPORT INFORMATION shown below. If you don't provide this and we
|
||||
cannot debug your issue, we will close it. We will, however, reopen it if you
|
||||
later provide the information.
|
||||
|
||||
If you have an issue that can be shown visually, please provide a screenshot or
|
||||
gif of the problem as well.
|
||||
|
||||
---------------------------------------------------
|
||||
BUG REPORT INFORMATION
|
||||
---------------------------------------------------
|
||||
Use the commands below to provide key information from your environment:
|
||||
You do NOT have to include this information if this is a FEATURE REQUEST
|
||||
-->
|
||||
|
||||
**- Do you want to request a *feature* or report a *bug*?**
|
||||
|
||||
**- What is happening?**
|
||||
|
||||
**- If you think it's a bug, please provide complete repro steps.**
|
||||
|
||||
**- What did you expect to happen?**
|
||||
|
||||
**- Go version? OS version? or anything else you think might be helpful.**
|
44
.github/PULL_REQUEST_TEMPLATE.md
vendored
44
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -1,44 +0,0 @@
|
||||
<!--
|
||||
Thanks for submitting a pull request!
|
||||
|
||||
Please make sure you've read and understood our contributing guidelines;
|
||||
https://github.com/jrapoport/chestnut/blob/master/CONTRIBUTING.md
|
||||
|
||||
If this is a bug fix, make sure your description includes "fixes #xxxx", or
|
||||
"closes #xxxx", where #xxxx is the issue number.
|
||||
|
||||
Please provide enough information so that we can review your pull request.
|
||||
The first three fields are mandatory:
|
||||
-->
|
||||
|
||||
**- Problem**
|
||||
|
||||
<!--
|
||||
Explain **why** you are making this change.
|
||||
What existing problem does the pull request solve?
|
||||
-->
|
||||
|
||||
**- Solution**
|
||||
|
||||
<!--
|
||||
Explain **how** this change fixes the problem.
|
||||
What does this change do to solve the the problem?
|
||||
-->
|
||||
|
||||
**- Changes**
|
||||
|
||||
<!--
|
||||
Explain **what** the actual changes are.
|
||||
What did you change to implement your solution?
|
||||
-->
|
||||
|
||||
**- Changelog**
|
||||
|
||||
<!--
|
||||
A short (one line) summary that describes the change for the changelog:
|
||||
-->
|
||||
|
||||
**- Tip me in BTC or ETH (not mandatory but encouraged)**
|
||||
|
||||
btc: bc1qqswuhm3nk60uv9g4j6e2230q46n9yklm4060wv
|
||||
eth: 0x1866daF9F494F0C565CD4B93FA8B0FC3303a9acF
|
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -7,7 +7,7 @@ jobs:
|
||||
test:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.15.x]
|
||||
go-version: [1.15.x, 1.16.x]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Install Go
|
||||
|
@ -1,6 +1,10 @@
|
||||
# 🌰 Chestnut
|
||||
|
||||
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/jrapoport/chestnut/test?style=flat-square) [![Go Report Card](https://goreportcard.com/badge/github.com/jrapoport/chestnut?style=flat-square&)](https://goreportcard.com/report/github.com/jrapoport/chestnut) ![Codecov branch](https://img.shields.io/codecov/c/github/jrapoport/chestnut/master?style=flat-square&token=7REY4BDPHW) ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/jrapoport/chestnut?style=flat-square) [![GitHub](https://img.shields.io/github/license/jrapoport/chestnut?style=flat-square)](https://github.com/jrapoport/chestnut/blob/master/LICENSE)
|
||||
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/jrapoport/chestnut/test?style=flat-square)
|
||||
[![Go Report Card](https://goreportcard.com/badge/github.com/jrapoport/chestnut?style=flat-square&)](https://goreportcard.com/report/github.com/jrapoport/chestnut)
|
||||
[![Codecov branch](https://img.shields.io/codecov/c/github/jrapoport/chestnut/master?style=flat-square&token=7REY4BDPHW)](https://codecov.io/gh/jrapoport/chestnut)
|
||||
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/jrapoport/chestnut?style=flat-square)
|
||||
[![GitHub](https://img.shields.io/github/license/jrapoport/chestnut?style=flat-square)](https://github.com/jrapoport/chestnut/blob/master/LICENSE)
|
||||
|
||||
[![Buy Me A Coffee](https://img.shields.io/badge/buy%20me%20a%20coffee-☕-6F4E37?style=flat-square)](https://www.buymeacoffee.com/jrapoport)
|
||||
|
||||
|
13
codecov.yml
13
codecov.yml
@ -1,2 +1,15 @@
|
||||
coverage:
|
||||
status:
|
||||
project:
|
||||
default:
|
||||
target: auto
|
||||
threshold: 5%
|
||||
if_not_found: success
|
||||
patch:
|
||||
default:
|
||||
target: auto
|
||||
threshold: 5%
|
||||
if_not_found: success
|
||||
|
||||
ignore:
|
||||
- "examples/"
|
||||
|
16
go.mod
16
go.mod
@ -4,17 +4,17 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/btcsuite/btcd v0.21.0-beta
|
||||
github.com/google/uuid v1.1.4
|
||||
github.com/google/uuid v1.2.0
|
||||
github.com/hashicorp/go-version v1.2.1
|
||||
github.com/ipfs/go-ipfs v0.7.0
|
||||
github.com/ipfs/go-ipfs v0.8.0
|
||||
github.com/json-iterator/go v1.1.10
|
||||
github.com/klauspost/compress v1.11.6
|
||||
github.com/libp2p/go-libp2p-core v0.8.0
|
||||
github.com/klauspost/compress v1.11.13
|
||||
github.com/libp2p/go-libp2p-core v0.8.5
|
||||
github.com/modern-go/reflect2 v1.0.1
|
||||
github.com/sirupsen/logrus v1.7.0
|
||||
github.com/stretchr/testify v1.6.1
|
||||
github.com/xujiajun/nutsdb v0.5.0
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/xujiajun/nutsdb v0.6.0
|
||||
go.etcd.io/bbolt v1.3.5
|
||||
go.uber.org/zap v1.16.0
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
|
||||
)
|
||||
|
@ -35,7 +35,7 @@ func NewKeystore(store storage.Storage, opt ...chestnut.ChestOption) *Keystore {
|
||||
logger := log.Named(cn.Logger(), logName)
|
||||
ks := &Keystore{cn, store, logger}
|
||||
if err := ks.validConfig(); err != nil {
|
||||
logger.Fatal(err)
|
||||
logger.Panic(err)
|
||||
return nil
|
||||
}
|
||||
return ks
|
||||
|
@ -89,6 +89,12 @@ func (ts *KeystoreTestSuite) BeforeTest(_, testName string) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidConfig(t *testing.T) {
|
||||
assert.Panics(t, func() {
|
||||
NewKeystore(nil, encryptorOpt)
|
||||
})
|
||||
}
|
||||
|
||||
func (ts *KeystoreTestSuite) TestKeystore_Encryptor() {
|
||||
err := ts.keystore.Put(testName, privateKey)
|
||||
ts.NoError(err)
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
const (
|
||||
logName = "bolt"
|
||||
storeName = "chest.db"
|
||||
storeExt = ".db"
|
||||
)
|
||||
|
||||
// boltStore is an implementation the Storage interface for bbolt
|
||||
@ -33,7 +34,7 @@ func NewStore(path string, opt ...storage.StoreOption) storage.Storage {
|
||||
opts := storage.ApplyOptions(storage.DefaultStoreOptions, opt...)
|
||||
logger := log.Named(opts.Logger(), logName)
|
||||
if path == "" {
|
||||
logger.Fatal("store path required")
|
||||
logger.Panic("store path required")
|
||||
}
|
||||
return &boltStore{path: path, opts: opts, log: logger}
|
||||
}
|
||||
@ -297,26 +298,38 @@ func ensureDBPath(path string) (string, error) {
|
||||
return "", errors.New("path not found")
|
||||
}
|
||||
// does the path exist?
|
||||
_, err := os.Stat(path)
|
||||
info, err := os.Stat(path)
|
||||
exists := !os.IsNotExist(err)
|
||||
// this is some kind of actual error
|
||||
if err != nil && exists {
|
||||
return "", err
|
||||
}
|
||||
if !exists {
|
||||
// make sure the directory path exists
|
||||
if err = os.MkdirAll(path, 0700); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if exists && info.Mode().IsDir() {
|
||||
// if we have a directory, then append our default name
|
||||
path = filepath.Join(path, storeName)
|
||||
}
|
||||
// is the path a directory?
|
||||
d, err := os.Stat(path)
|
||||
ext := filepath.Ext(path)
|
||||
if ext == "" {
|
||||
path += storeExt
|
||||
}
|
||||
dir, _ := filepath.Split(path)
|
||||
// make sure the directory path exists
|
||||
if err = os.MkdirAll(dir, 0700); err != nil {
|
||||
return "", err
|
||||
}
|
||||
_, err = os.Stat(path)
|
||||
exists = !os.IsNotExist(err)
|
||||
// this is some kind of actual error
|
||||
if err != nil && exists {
|
||||
return "", err
|
||||
}
|
||||
if exists {
|
||||
return path, nil
|
||||
}
|
||||
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if !d.Mode().IsDir() {
|
||||
return path, nil
|
||||
}
|
||||
// if we have a directory, then append our default name
|
||||
path = filepath.Join(path, storeName)
|
||||
defer f.Close()
|
||||
return path, nil
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ func NewStore(path string, opt ...storage.StoreOption) storage.Storage {
|
||||
opts := storage.ApplyOptions(storage.DefaultStoreOptions, opt...)
|
||||
logger := log.Named(opts.Logger(), logName)
|
||||
if path == "" {
|
||||
logger.Fatal("store path required")
|
||||
logger.Panic("store path required")
|
||||
}
|
||||
return &nutsDBStore{path: path, opts: opts, log: logger}
|
||||
}
|
||||
|
@ -94,6 +94,12 @@ func (ts *storeTestSuite) BeforeTest(_, testName string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (ts *storeTestSuite) TestInvalidPath() {
|
||||
ts.Panics(func() {
|
||||
ts.storeFunc("")
|
||||
})
|
||||
}
|
||||
|
||||
// TestStorePut
|
||||
func (ts *storeTestSuite) TestStorePut() {
|
||||
for i, test := range putTests {
|
||||
|
Loading…
Reference in New Issue
Block a user