Skip to content

Commit

Permalink
Merge pull request #225 from onflow/leo/finalize-copy-priv-keys
Browse files Browse the repository at this point in the history
Copy changes for updating private keys during finalize
  • Loading branch information
zhangchiqing authored Dec 8, 2020
2 parents c3800a9 + 0cebe30 commit ed87689
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
68 changes: 68 additions & 0 deletions cmd/bootstrap/cmd/copy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package cmd

import (
"fmt"
"io"
"io/ioutil"
"os"
"path"
)

func copyDir(src string, dst string) error {
var err error
var fds []os.FileInfo
var srcinfo os.FileInfo

if srcinfo, err = os.Stat(src); err != nil {
return err
}

if err = os.MkdirAll(dst, srcinfo.Mode()); err != nil {
return err
}

if fds, err = ioutil.ReadDir(src); err != nil {
return err
}
for _, fd := range fds {
srcfp := path.Join(src, fd.Name())
dstfp := path.Join(dst, fd.Name())

if fd.IsDir() {
if err = copyDir(srcfp, dstfp); err != nil {
fmt.Println(err)
}
} else {
if err = copyFile(srcfp, dstfp); err != nil {
fmt.Println(err)
}
}
}
return nil
}

// CopyFile copies a single file from src to dst
func copyFile(src, dst string) error {
var err error
var srcfd *os.File
var dstfd *os.File
var srcinfo os.FileInfo

if srcfd, err = os.Open(src); err != nil {
return err
}
defer srcfd.Close()

if dstfd, err = os.Create(dst); err != nil {
return err
}
defer dstfd.Close()

if _, err = io.Copy(dstfd, srcfd); err != nil {
return err
}
if srcinfo, err = os.Stat(src); err != nil {
return err
}
return os.Chmod(dst, srcinfo.Mode())
}
10 changes: 9 additions & 1 deletion cmd/bootstrap/cmd/finalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"strings"
"time"

"github.com/onflow/cadence"
"github.com/spf13/cobra"

"github.com/onflow/cadence"

"github.com/onflow/flow-go/cmd/bootstrap/run"
model "github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/model/encodable"
Expand Down Expand Up @@ -169,6 +170,13 @@ func finalize(cmd *cobra.Command, args []string) {
constructRootResultAndSeal(flagRootCommit, block, stakingNodes, assignments, clusterQCs, dkgData)
log.Info().Msg("")

log.Info().Msg("copying internal private keys to output folder")
err := copyDir(flagInternalNodePrivInfoDir, filepath.Join(flagOutdir, model.DirPrivateRoot))
if err != nil {
log.Error().Err(err).Msg("could not copy private key files")
}
log.Info().Msg("")

// print count of all nodes
roleCounts := nodeCountByRole(stakingNodes)
for role, count := range roleCounts {
Expand Down

0 comments on commit ed87689

Please sign in to comment.