Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
c3d04d3b
Unverified
Commit
c3d04d3b
authored
Sep 04, 2023
by
Adrian Sutton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-program: Recreate preimage data dir if required
parent
8b9acddf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
2 deletions
+32
-2
disk.go
op-program/host/kvstore/disk.go
+16
-1
disk_test.go
op-program/host/kvstore/disk_test.go
+16
-1
No files found.
op-program/host/kvstore/disk.go
View file @
c3d04d3b
...
@@ -37,7 +37,7 @@ func (d *DiskKV) pathKey(k common.Hash) string {
...
@@ -37,7 +37,7 @@ func (d *DiskKV) pathKey(k common.Hash) string {
func
(
d
*
DiskKV
)
Put
(
k
common
.
Hash
,
v
[]
byte
)
error
{
func
(
d
*
DiskKV
)
Put
(
k
common
.
Hash
,
v
[]
byte
)
error
{
d
.
Lock
()
d
.
Lock
()
defer
d
.
Unlock
()
defer
d
.
Unlock
()
f
,
err
:=
o
s
.
CreateTemp
(
d
.
path
,
k
.
String
()
+
".txt.*"
)
f
,
err
:=
o
penTempFile
(
d
.
path
,
k
.
String
()
+
".txt.*"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to open temp file for pre-image %s: %w"
,
k
,
err
)
return
fmt
.
Errorf
(
"failed to open temp file for pre-image %s: %w"
,
k
,
err
)
}
}
...
@@ -57,6 +57,21 @@ func (d *DiskKV) Put(k common.Hash, v []byte) error {
...
@@ -57,6 +57,21 @@ func (d *DiskKV) Put(k common.Hash, v []byte) error {
return
nil
return
nil
}
}
func
openTempFile
(
dir
string
,
nameTemplate
string
)
(
*
os
.
File
,
error
)
{
f
,
err
:=
os
.
CreateTemp
(
dir
,
nameTemplate
)
// Directory has been deleted out from underneath us. Recreate it.
if
errors
.
Is
(
err
,
os
.
ErrNotExist
)
{
if
mkdirErr
:=
os
.
MkdirAll
(
dir
,
0777
);
mkdirErr
!=
nil
{
return
nil
,
errors
.
Join
(
fmt
.
Errorf
(
"failed to create directory %v: %w"
,
dir
,
mkdirErr
),
err
)
}
f
,
err
=
os
.
CreateTemp
(
dir
,
nameTemplate
)
}
if
err
!=
nil
{
return
nil
,
err
}
return
f
,
nil
}
func
(
d
*
DiskKV
)
Get
(
k
common
.
Hash
)
([]
byte
,
error
)
{
func
(
d
*
DiskKV
)
Get
(
k
common
.
Hash
)
([]
byte
,
error
)
{
d
.
RLock
()
d
.
RLock
()
defer
d
.
RUnlock
()
defer
d
.
RUnlock
()
...
...
op-program/host/kvstore/disk_test.go
View file @
c3d04d3b
package
kvstore
package
kvstore
import
"testing"
import
(
"path/filepath"
"testing"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/require"
)
func
TestDiskKV
(
t
*
testing
.
T
)
{
func
TestDiskKV
(
t
*
testing
.
T
)
{
tmp
:=
t
.
TempDir
()
// automatically removed by testing cleanup
tmp
:=
t
.
TempDir
()
// automatically removed by testing cleanup
kv
:=
NewDiskKV
(
tmp
)
kv
:=
NewDiskKV
(
tmp
)
kvTest
(
t
,
kv
)
kvTest
(
t
,
kv
)
}
}
func
TestCreateMissingDirectory
(
t
*
testing
.
T
)
{
tmp
:=
t
.
TempDir
()
dir
:=
filepath
.
Join
(
tmp
,
"data"
)
kv
:=
NewDiskKV
(
dir
)
val
:=
[]
byte
{
1
,
2
,
3
,
4
}
key
:=
crypto
.
Keccak256Hash
(
val
)
require
.
NoError
(
t
,
kv
.
Put
(
key
,
val
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment