mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-12 04:55:43 +02:00
Merge pull request #5878 from halseth/filter-ascii-bbolt-name
kvdb/bolt_compact: filter out non-ASCII from bucket name before printing
This commit is contained in:
@@ -589,6 +589,9 @@ messages directly. There is no routing/path finding involved.
|
|||||||
* [Do not error log when an invoice that has been canceled and GC'd is expired](
|
* [Do not error log when an invoice that has been canceled and GC'd is expired](
|
||||||
https://github.com/lightningnetwork/lnd/pull/5913)
|
https://github.com/lightningnetwork/lnd/pull/5913)
|
||||||
|
|
||||||
|
* [Don't print bucket names with special characters when compacting](
|
||||||
|
https://github.com/lightningnetwork/lnd/pull/5878)
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
The [code contribution guidelines have been updated to mention the new
|
The [code contribution guidelines have been updated to mention the new
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
package kvdb
|
package kvdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@@ -219,7 +220,8 @@ func (cmd *compacter) walk(db *bbolt.DB, walkFn walkFunc) error {
|
|||||||
return tx.ForEach(func(name []byte, b *bbolt.Bucket) error {
|
return tx.ForEach(func(name []byte, b *bbolt.Bucket) error {
|
||||||
// This will log the top level buckets only to give the
|
// This will log the top level buckets only to give the
|
||||||
// user some sense of progress.
|
// user some sense of progress.
|
||||||
log.Debugf("Compacting top level bucket %s", name)
|
log.Debugf("Compacting top level bucket '%s'",
|
||||||
|
LoggableKeyName(name))
|
||||||
|
|
||||||
return cmd.walkBucket(
|
return cmd.walkBucket(
|
||||||
b, nil, name, nil, b.Sequence(), walkFn,
|
b, nil, name, nil, b.Sequence(), walkFn,
|
||||||
@@ -228,6 +230,30 @@ func (cmd *compacter) walk(db *bbolt.DB, walkFn walkFunc) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoggableKeyName returns a printable name of the given key.
|
||||||
|
func LoggableKeyName(key []byte) string {
|
||||||
|
strKey := string(key)
|
||||||
|
if hasSpecialChars(strKey) {
|
||||||
|
return hex.EncodeToString(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
return strKey
|
||||||
|
}
|
||||||
|
|
||||||
|
// hasSpecialChars returns true if any of the characters in the given string
|
||||||
|
// cannot be printed.
|
||||||
|
func hasSpecialChars(s string) bool {
|
||||||
|
for _, b := range s {
|
||||||
|
if !(b >= 'a' && b <= 'z') && !(b >= 'A' && b <= 'Z') &&
|
||||||
|
!(b >= '0' && b <= '9') && b != '-' && b != '_' {
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// walkBucket recursively walks through a bucket.
|
// walkBucket recursively walks through a bucket.
|
||||||
func (cmd *compacter) walkBucket(b *bbolt.Bucket, keyPath [][]byte, k, v []byte,
|
func (cmd *compacter) walkBucket(b *bbolt.Bucket, keyPath [][]byte, k, v []byte,
|
||||||
seq uint64, fn walkFunc) error {
|
seq uint64, fn walkFunc) error {
|
||||||
|
Reference in New Issue
Block a user