Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new dirWalk for test purposes #11277

Merged
merged 5 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"context"
"errors"
"fmt"
"io/fs"
"math"
"math/big"
"net"
Expand All @@ -37,6 +36,8 @@ import (
"sync/atomic"
"time"

"github.com/karrick/godirwalk"

"github.com/erigontech/mdbx-go/mdbx"
lru "github.com/hashicorp/golang-lru/arc/v2"
"github.com/holiman/uint256"
Expand All @@ -52,7 +53,6 @@ import (
libcommon "github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/common/datadir"
"github.com/erigontech/erigon-lib/common/dbg"
"github.com/erigontech/erigon-lib/common/dir"
"github.com/erigontech/erigon-lib/common/disk"
"github.com/erigontech/erigon-lib/common/mem"
"github.com/erigontech/erigon-lib/config3"
Expand Down Expand Up @@ -1679,26 +1679,31 @@ func (s *Ethereum) ExecutionModule() *eth1.EthereumExecutionModule {

// RemoveContents is like os.RemoveAll, but preserve dir itself
func RemoveContents(dirname string) error {
d, err := os.Open(dirname)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
// ignore due to windows
_ = os.MkdirAll(dirname, 0o755)
return nil
}
return err
}
defer d.Close()
files, err := dir.ReadDir(dirname)
err := godirwalk.Walk(dirname, &godirwalk.Options{
ErrorCallback: func(s string, err error) godirwalk.ErrorAction {
if os.IsNotExist(err) {
return godirwalk.SkipNode
}
return godirwalk.Halt
},
FollowSymbolicLinks: true,
Unsorted: true,
Callback: func(osPathname string, d *godirwalk.Dirent) error {
if osPathname == dirname {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in future - we can add select ctx.Done() to support Ctrl+C

return nil
}
if d.IsSymlink() {
return nil
}
return os.RemoveAll(filepath.Join(dirname, d.Name()))
},
PostChildrenCallback: nil,
ScratchBuffer: nil,
AllowNonDirectory: false,
})
if err != nil {
return err
}
for _, file := range files {
err = os.RemoveAll(filepath.Join(dirname, file.Name()))
if err != nil {
return err
}
}
return nil
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ require (
github.com/jedib0t/go-pretty/v6 v6.5.9
github.com/json-iterator/go v1.1.12
github.com/julienschmidt/httprouter v1.3.0
github.com/karrick/godirwalk v1.17.0
github.com/klauspost/compress v1.17.8
github.com/libp2p/go-libp2p v0.34.0
github.com/libp2p/go-libp2p-mplex v0.9.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/karrick/godirwalk v1.17.0 h1:b4kY7nqDdioR/6qnbHQyDvmA17u5G1cZ6J+CZXwSWoI=
github.com/karrick/godirwalk v1.17.0/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
Expand Down
Loading