Skip to content

Commit

Permalink
remove only etl-tmp content, but not dir itself #4816
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Jul 25, 2022
1 parent b231856 commit 9e371fe
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
}

tmpdir := stack.Config().Dirs.Tmp
if err := os.RemoveAll(tmpdir); err != nil { // clean it on startup
if err := RemoveContents(tmpdir); err != nil { // clean it on startup
return nil, fmt.Errorf("clean tmp dir: %s, %w", tmpdir, err)
}

Expand Down Expand Up @@ -912,3 +912,23 @@ func (s *Ethereum) SentryCtx() context.Context {
func (s *Ethereum) SentryControlServer() *sentry.MultiClient {
return s.sentriesClient
}

// RemoveContents is like os.RemoveAll, but preserve dir itself
func RemoveContents(dir string) error {
d, err := os.Open(dir)
if err != nil {
return err
}
defer d.Close()
names, err := d.Readdirnames(-1)
if err != nil {
return err
}
for _, name := range names {
err = os.RemoveAll(filepath.Join(dir, name))
if err != nil {
return err
}
}
return nil
}

0 comments on commit 9e371fe

Please sign in to comment.