Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

[R4R] change file permission and add error handling #167

Merged
merged 2 commits into from
Apr 20, 2022
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
4 changes: 2 additions & 2 deletions abci/types/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (writer *SnapshotWriter) Write(hash SHA256Sum, chunk []byte) error {
return err
}
toWrite := filepath.Join(path, fmt.Sprintf("%x", hash))
return os.WriteFile(toWrite, chunk, 0644)
return os.WriteFile(toWrite, chunk, 0600)
}

func (writer *SnapshotWriter) WriteManifest(manifest []byte) error {
Expand All @@ -165,7 +165,7 @@ func (writer *SnapshotWriter) WriteManifest(manifest []byte) error {
return err
}
toWrite := filepath.Join(path, manifestFileName)
return os.WriteFile(toWrite, manifest, 0644)
return os.WriteFile(toWrite, manifest, 0600)
}

func (writer *SnapshotWriter) Finalize() error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/tendermint/commands/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,5 @@ func WriteConfigVals(dir string, vals map[string]string) error {
data += fmt.Sprintf("%s = \"%s\"\n", k, v)
}
cfile := filepath.Join(dir, "config.toml")
return os.WriteFile(cfile, []byte(data), 0666)
return os.WriteFile(cfile, []byte(data), 0600)
}
8 changes: 4 additions & 4 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func WriteConfigFile(configFilePath string, config *Config) {
panic(err)
}

cmn.MustWriteFile(configFilePath, buffer.Bytes(), 0644)
cmn.MustWriteFile(configFilePath, buffer.Bytes(), 0600)
}

// Note: any changes to the comments/variables/mapstructure
Expand Down Expand Up @@ -507,11 +507,11 @@ func ResetTestRootWithChainID(testName string, chainID string) *Config {
chainID = "tendermint_test"
}
testGenesis := fmt.Sprintf(testGenesisFmt, chainID)
cmn.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644)
cmn.MustWriteFile(genesisFilePath, []byte(testGenesis), 0600)
}
// we always overwrite the priv val
cmn.MustWriteFile(privKeyFilePath, []byte(testPrivValidatorKey), 0644)
cmn.MustWriteFile(privStateFilePath, []byte(testPrivValidatorState), 0644)
cmn.MustWriteFile(privKeyFilePath, []byte(testPrivValidatorKey), 0600)
cmn.MustWriteFile(privStateFilePath, []byte(testPrivValidatorState), 0600)

config := TestConfig().SetRoot(rootDir)
return config
Expand Down
2 changes: 1 addition & 1 deletion libs/cli/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func WriteConfigVals(dir string, vals map[string]string) error {
data += fmt.Sprintf("%s = \"%s\"\n", k, v)
}
cfile := filepath.Join(dir, "config.toml")
return os.WriteFile(cfile, []byte(data), 0666)
return os.WriteFile(cfile, []byte(data), 0600)
}

// RunWithArgs executes the given command with the specified command line args
Expand Down
2 changes: 1 addition & 1 deletion p2p/conn/secret_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func TestDeriveSecretsAndChallengeGolden(t *testing.T) {
if *update {
t.Logf("Updating golden test vector file %s", goldenFilepath)
data := createGoldenTestVectors(t)
cmn.WriteFile(goldenFilepath, []byte(data), 0644)
cmn.WriteFile(goldenFilepath, []byte(data), 0600)
}
f, err := os.Open(goldenFilepath)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion p2p/pex/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (a *addrBook) saveToFile(filePath string) {
a.Logger.Error("Failed to save AddrBook to file", "err", err)
return
}
err = cmn.WriteFileAtomic(filePath, jsonBytes, 0644)
err = cmn.WriteFileAtomic(filePath, jsonBytes, 0600)
if err != nil {
a.Logger.Error("Failed to save AddrBook to file", "file", filePath, "err", err)
}
Expand Down
14 changes: 11 additions & 3 deletions scripts/json2wal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,21 @@ func main() {
if err != nil {
panic(fmt.Errorf("failed to open WAL file: %v", err))
}
defer f.Close()
defer func() {
if err := f.Close(); err != nil {
fmt.Printf("Error closing file: %s\n", f.Name())
}
}()

walFile, err := os.OpenFile(os.Args[2], os.O_EXCL|os.O_WRONLY|os.O_CREATE, 0666)
walFile, err := os.OpenFile(os.Args[2], os.O_EXCL|os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
panic(fmt.Errorf("failed to open WAL file: %v", err))
}
defer walFile.Close()
defer func() {
if err := walFile.Close(); err != nil {
fmt.Printf("Error closing file: %s\n", walFile.Name())
}
}()

// the length of tendermint/wal/MsgInfo in the wal.json may exceed the defaultBufSize(4096) of bufio
// because of the byte array in BlockPart
Expand Down
2 changes: 1 addition & 1 deletion tools/tm-signer-harness/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func extractKey(tmhome, outputPath string) {
stateFile := filepath.Join(internal.ExpandPath(tmhome), "data", "priv_validator_state.json")
fpv := privval.LoadFilePV(keyFile, stateFile)
pkb := [64]byte(fpv.Key.PrivKey.(ed25519.PrivKeyEd25519))
if err := os.WriteFile(internal.ExpandPath(outputPath), pkb[:32], 0644); err != nil {
if err := os.WriteFile(internal.ExpandPath(outputPath), pkb[:32], 0600); err != nil {
logger.Info("Failed to write private key", "output", outputPath, "err", err)
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (genDoc *GenesisDoc) SaveAs(file string) error {
if err != nil {
return err
}
return cmn.WriteFile(file, genDocBytes, 0644)
return cmn.WriteFile(file, genDocBytes, 0600)
}

// ValidatorHash returns the hash of the validator set contained in the GenesisDoc
Expand Down