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

fix(reset-data): the argument --network-peer-store couldn't work #2950

Merged
merged 1 commit into from
Aug 17, 2021
Merged
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
17 changes: 12 additions & 5 deletions ckb-bin/src/subcommand/reset_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use ckb_app_config::{ExitCode, ResetDataArgs};
pub fn reset_data(args: ResetDataArgs) -> Result<(), ExitCode> {
let mut target_dirs = vec![];
let mut target_files = vec![];
let mut errors_count = 0;

if args.all {
target_dirs.push(args.data_dir);
Expand All @@ -20,7 +21,7 @@ pub fn reset_data(args: ResetDataArgs) -> Result<(), ExitCode> {
}

if args.network_peer_store {
target_files.push(args.network_peer_store_path);
target_dirs.push(args.network_peer_store_path);
}

if args.network_secret_key {
Expand All @@ -33,7 +34,7 @@ pub fn reset_data(args: ResetDataArgs) -> Result<(), ExitCode> {
}
}

if !args.force {
if !args.force && (!target_dirs.is_empty() || !target_files.is_empty()) {
let to_be_deleted_targets = target_dirs
.iter()
.chain(target_files.iter())
Expand All @@ -49,21 +50,27 @@ pub fn reset_data(args: ResetDataArgs) -> Result<(), ExitCode> {

for dir in target_dirs.iter() {
if dir.exists() {
println!("deleting {:?}", dir);
println!("deleting {}", dir.display());
if let Some(e) = fs::remove_dir_all(dir).err() {
eprintln!("{}", e);
errors_count += 1;
}
}
}

for file in target_files.iter() {
if file.exists() {
println!("deleting {:?}", file);
println!("deleting {}", file.display());
if let Some(e) = fs::remove_file(file).err() {
eprintln!("{}", e);
errors_count += 1;
}
}
}

Ok(())
if errors_count == 0 {
Ok(())
} else {
Err(ExitCode::Failure)
}
}