Replace OpenOptions::new with File::options to be readable (#3059)

## Issue Addressed

Closes #3049 

This PR updates widely but this replace is safe as `File::options()` is equivelent to `OpenOptions::new()`.
ref: https://doc.rust-lang.org/stable/src/std/fs.rs.html#378-380
This commit is contained in:
Akihito Nakano
2022-03-07 06:30:18 +00:00
parent cbda0a2f0a
commit 4186d117af
16 changed files with 40 additions and 41 deletions

View File

@@ -4,7 +4,7 @@ use deposit_contract::{encode_eth1_tx_data, Error as DepositError};
use eth2_keystore::{Error as KeystoreError, Keystore, KeystoreBuilder, PlainText};
use filesystem::create_with_600_perms;
use rand::{distributions::Alphanumeric, Rng};
use std::fs::{create_dir_all, OpenOptions};
use std::fs::{create_dir_all, File};
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use types::{ChainSpec, DepositData, Hash256, Keypair, Signature};
@@ -197,7 +197,7 @@ impl<'a> Builder<'a> {
return Err(Error::DepositDataAlreadyExists(path));
} else {
let hex = format!("0x{}", hex::encode(&deposit_data));
OpenOptions::new()
File::options()
.write(true)
.read(true)
.create(true)
@@ -214,7 +214,7 @@ impl<'a> Builder<'a> {
if path.exists() {
return Err(Error::DepositAmountAlreadyExists(path));
} else {
OpenOptions::new()
File::options()
.write(true)
.read(true)
.create(true)
@@ -267,7 +267,7 @@ fn write_keystore_to_file(path: PathBuf, keystore: &Keystore) -> Result<(), Erro
if path.exists() {
Err(Error::KeystoreAlreadyExists(path))
} else {
let file = OpenOptions::new()
let file = File::options()
.write(true)
.read(true)
.create_new(true)

View File

@@ -6,7 +6,7 @@ use deposit_contract::decode_eth1_tx_data;
use derivative::Derivative;
use eth2_keystore::{Error as KeystoreError, Keystore, PlainText};
use lockfile::{Lockfile, LockfileError};
use std::fs::{read, write, OpenOptions};
use std::fs::{read, write, File};
use std::io;
use std::path::{Path, PathBuf};
use tree_hash::TreeHash;
@@ -211,7 +211,7 @@ pub fn unlock_keypair<P: AsRef<Path>>(
password_dir: P,
) -> Result<Keypair, Error> {
let keystore = Keystore::from_json_reader(
&mut OpenOptions::new()
&mut File::options()
.read(true)
.create(false)
.open(keystore_path)
@@ -236,7 +236,7 @@ pub fn unlock_keypair_from_password_path(
password_path: &Path,
) -> Result<Keypair, Error> {
let keystore = Keystore::from_json_reader(
&mut OpenOptions::new()
&mut File::options()
.read(true)
.create(false)
.open(keystore_path)