2020-12-08 23:18:27 -08:00
|
|
|
use {
|
2021-01-21 13:16:40 -08:00
|
|
|
clap::{value_t, value_t_or_exit, App, Arg},
|
2020-12-15 11:06:03 -08:00
|
|
|
fd_lock::FdLock,
|
2021-01-21 13:16:40 -08:00
|
|
|
solana_clap_utils::{
|
|
|
|
input_parsers::{pubkey_of, pubkeys_of},
|
|
|
|
input_validators::{
|
2021-01-21 18:34:51 -08:00
|
|
|
is_pubkey, is_pubkey_or_keypair, is_slot, is_url_or_moniker,
|
|
|
|
normalize_to_url_if_moniker,
|
2021-01-21 13:16:40 -08:00
|
|
|
},
|
|
|
|
},
|
2021-02-05 22:39:23 -08:00
|
|
|
solana_client::rpc_client::RpcClient,
|
2020-12-08 23:18:27 -08:00
|
|
|
solana_core::rpc::JsonRpcConfig,
|
2020-12-11 20:03:15 -08:00
|
|
|
solana_faucet::faucet::{run_local_faucet_with_port, FAUCET_PORT},
|
2020-12-08 23:18:27 -08:00
|
|
|
solana_sdk::{
|
2020-12-11 20:03:15 -08:00
|
|
|
account::Account,
|
2021-02-05 22:39:23 -08:00
|
|
|
clock::Slot,
|
|
|
|
native_token::sol_to_lamports,
|
2020-12-11 20:03:15 -08:00
|
|
|
pubkey::Pubkey,
|
2020-12-08 23:18:27 -08:00
|
|
|
rpc_port,
|
2020-12-11 20:03:15 -08:00
|
|
|
signature::{read_keypair_file, write_keypair_file, Keypair, Signer},
|
|
|
|
system_program,
|
2020-12-08 23:18:27 -08:00
|
|
|
},
|
2021-02-05 22:39:23 -08:00
|
|
|
solana_validator::{
|
|
|
|
dashboard::Dashboard, record_start, redirect_stderr_to_file, test_validator::*,
|
|
|
|
},
|
2020-12-08 23:18:27 -08:00
|
|
|
std::{
|
2021-01-21 13:16:40 -08:00
|
|
|
collections::HashSet,
|
2020-12-15 11:06:03 -08:00
|
|
|
fs, io,
|
2020-12-11 20:03:15 -08:00
|
|
|
net::{IpAddr, Ipv4Addr, SocketAddr},
|
2020-12-15 11:06:03 -08:00
|
|
|
path::{Path, PathBuf},
|
2020-12-08 23:18:27 -08:00
|
|
|
process::exit,
|
2020-12-11 20:03:15 -08:00
|
|
|
sync::mpsc::channel,
|
2021-02-05 22:39:23 -08:00
|
|
|
time::{SystemTime, UNIX_EPOCH},
|
2020-12-08 23:18:27 -08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
enum Output {
|
|
|
|
None,
|
|
|
|
Log,
|
|
|
|
Dashboard,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let default_rpc_port = rpc_port::DEFAULT_RPC_PORT.to_string();
|
|
|
|
|
2020-12-11 20:03:15 -08:00
|
|
|
let matches = App::new("solana-test-validator")
|
|
|
|
.about("Test Validator")
|
2020-12-08 23:18:27 -08:00
|
|
|
.version(solana_version::version!())
|
|
|
|
.arg({
|
|
|
|
let arg = Arg::with_name("config_file")
|
|
|
|
.short("C")
|
|
|
|
.long("config")
|
|
|
|
.value_name("PATH")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Configuration file to use");
|
|
|
|
if let Some(ref config_file) = *solana_cli_config::CONFIG_FILE {
|
|
|
|
arg.default_value(&config_file)
|
|
|
|
} else {
|
|
|
|
arg
|
|
|
|
}
|
|
|
|
})
|
2021-01-21 13:16:40 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("json_rpc_url")
|
|
|
|
.short("u")
|
|
|
|
.long("url")
|
|
|
|
.value_name("URL_OR_MONIKER")
|
|
|
|
.takes_value(true)
|
|
|
|
.validator(is_url_or_moniker)
|
|
|
|
.help(
|
|
|
|
"URL for Solana's JSON RPC or moniker (or their first letter): \
|
|
|
|
[mainnet-beta, testnet, devnet, localhost]",
|
|
|
|
),
|
|
|
|
)
|
2020-12-08 23:18:27 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("mint_address")
|
|
|
|
.long("mint")
|
|
|
|
.value_name("PUBKEY")
|
|
|
|
.validator(is_pubkey)
|
|
|
|
.takes_value(true)
|
2020-12-11 20:03:15 -08:00
|
|
|
.help(
|
|
|
|
"Address of the mint account that will receive tokens \
|
2021-01-21 13:16:40 -08:00
|
|
|
created at genesis. If the ledger already exists then \
|
|
|
|
this parameter is silently ignored [default: client keypair]",
|
2020-12-11 20:03:15 -08:00
|
|
|
),
|
2020-12-08 23:18:27 -08:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("ledger_path")
|
|
|
|
.short("l")
|
|
|
|
.long("ledger")
|
|
|
|
.value_name("DIR")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
|
|
|
.default_value("test-ledger")
|
|
|
|
.help("Use DIR as ledger location"),
|
|
|
|
)
|
2020-12-15 11:06:03 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("reset")
|
|
|
|
.short("r")
|
|
|
|
.long("reset")
|
|
|
|
.takes_value(false)
|
|
|
|
.help(
|
|
|
|
"Reset the ledger to genesis if it exists. \
|
|
|
|
By default the validator will resume an existing ledger (if present)",
|
|
|
|
),
|
|
|
|
)
|
2020-12-08 23:18:27 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("quiet")
|
|
|
|
.short("q")
|
|
|
|
.long("quiet")
|
|
|
|
.takes_value(false)
|
|
|
|
.conflicts_with("log")
|
2020-12-11 20:03:15 -08:00
|
|
|
.help("Quiet mode: suppress normal output"),
|
2020-12-08 23:18:27 -08:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("log")
|
|
|
|
.long("log")
|
|
|
|
.takes_value(false)
|
|
|
|
.conflicts_with("quiet")
|
2020-12-11 20:03:15 -08:00
|
|
|
.help("Log mode: stream the validator log"),
|
2020-12-08 23:18:27 -08:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("rpc_port")
|
|
|
|
.long("rpc-port")
|
|
|
|
.value_name("PORT")
|
|
|
|
.takes_value(true)
|
|
|
|
.default_value(&default_rpc_port)
|
|
|
|
.validator(solana_validator::port_validator)
|
|
|
|
.help("Use this port for JSON RPC and the next port for the RPC websocket"),
|
|
|
|
)
|
2020-12-11 20:03:15 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("bpf_program")
|
|
|
|
.long("bpf-program")
|
|
|
|
.value_name("ADDRESS BPF_PROGRAM.SO")
|
|
|
|
.takes_value(true)
|
|
|
|
.number_of_values(2)
|
|
|
|
.multiple(true)
|
2021-01-21 13:16:40 -08:00
|
|
|
.help(
|
|
|
|
"Add a BPF program to the genesis configuration. \
|
|
|
|
If the ledger already exists then this parameter is silently ignored",
|
|
|
|
),
|
|
|
|
)
|
2021-02-09 11:02:04 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("no_bpf_jit")
|
|
|
|
.long("no-bpf-jit")
|
|
|
|
.takes_value(false)
|
|
|
|
.help("Disable the just-in-time compiler and instead use the interpreter for BPF"),
|
|
|
|
)
|
2021-01-21 13:16:40 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("clone_account")
|
|
|
|
.long("clone")
|
|
|
|
.short("c")
|
|
|
|
.value_name("ADDRESS")
|
|
|
|
.takes_value(true)
|
|
|
|
.validator(is_pubkey_or_keypair)
|
|
|
|
.multiple(true)
|
|
|
|
.requires("json_rpc_url")
|
|
|
|
.help(
|
|
|
|
"Copy an account from the cluster referenced by the --url argument the \
|
|
|
|
genesis configuration. \
|
|
|
|
If the ledger already exists then this parameter is silently ignored",
|
|
|
|
),
|
2020-12-11 20:03:15 -08:00
|
|
|
)
|
2021-01-21 18:34:51 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("warp_slot")
|
|
|
|
.required(false)
|
|
|
|
.long("warp-slot")
|
|
|
|
.short("w")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("WARP_SLOT")
|
|
|
|
.validator(is_slot)
|
|
|
|
.min_values(0)
|
|
|
|
.max_values(1)
|
|
|
|
.help(
|
|
|
|
"Warp the ledger to WARP_SLOT after starting the validator. \
|
|
|
|
If no slot is provided then the current slot of the cluster \
|
|
|
|
referenced by the --url argument will be used",
|
|
|
|
),
|
|
|
|
)
|
2020-12-08 23:18:27 -08:00
|
|
|
.get_matches();
|
|
|
|
|
|
|
|
let cli_config = if let Some(config_file) = matches.value_of("config_file") {
|
|
|
|
solana_cli_config::Config::load(config_file).unwrap_or_default()
|
|
|
|
} else {
|
|
|
|
solana_cli_config::Config::default()
|
|
|
|
};
|
|
|
|
|
2021-01-21 18:34:51 -08:00
|
|
|
let cluster_rpc_client = value_t!(matches, "json_rpc_url", String)
|
|
|
|
.map(normalize_to_url_if_moniker)
|
|
|
|
.map(RpcClient::new);
|
2021-01-21 13:16:40 -08:00
|
|
|
|
2020-12-08 23:18:27 -08:00
|
|
|
let mint_address = pubkey_of(&matches, "mint_address").unwrap_or_else(|| {
|
2020-12-24 10:43:57 -08:00
|
|
|
read_keypair_file(&cli_config.keypair_path)
|
2020-12-16 17:46:19 -08:00
|
|
|
.unwrap_or_else(|_| Keypair::new())
|
2020-12-08 23:18:27 -08:00
|
|
|
.pubkey()
|
|
|
|
});
|
|
|
|
|
|
|
|
let ledger_path = value_t_or_exit!(matches, "ledger_path", PathBuf);
|
2020-12-15 11:06:03 -08:00
|
|
|
let reset_ledger = matches.is_present("reset");
|
2020-12-08 23:18:27 -08:00
|
|
|
let output = if matches.is_present("quiet") {
|
|
|
|
Output::None
|
|
|
|
} else if matches.is_present("log") {
|
|
|
|
Output::Log
|
|
|
|
} else {
|
|
|
|
Output::Dashboard
|
|
|
|
};
|
2020-12-11 20:03:15 -08:00
|
|
|
let rpc_port = value_t_or_exit!(matches, "rpc_port", u16);
|
|
|
|
let faucet_addr = Some(SocketAddr::new(
|
2020-12-30 22:17:24 -08:00
|
|
|
IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
|
2020-12-11 20:03:15 -08:00
|
|
|
FAUCET_PORT,
|
|
|
|
));
|
2021-02-09 11:02:04 -08:00
|
|
|
let bpf_jit = !matches.is_present("no_bpf_jit");
|
2020-12-08 23:18:27 -08:00
|
|
|
|
2020-12-11 20:03:15 -08:00
|
|
|
let mut programs = vec![];
|
|
|
|
if let Some(values) = matches.values_of("bpf_program") {
|
|
|
|
let values: Vec<&str> = values.collect::<Vec<_>>();
|
|
|
|
for address_program in values.chunks(2) {
|
|
|
|
match address_program {
|
|
|
|
[address, program] => {
|
|
|
|
let address = address.parse::<Pubkey>().unwrap_or_else(|err| {
|
2021-01-28 12:11:53 -08:00
|
|
|
println!("Error: invalid address {}: {}", address, err);
|
2020-12-11 20:03:15 -08:00
|
|
|
exit(1);
|
|
|
|
});
|
2020-12-08 23:18:27 -08:00
|
|
|
|
2020-12-11 20:03:15 -08:00
|
|
|
let program_path = PathBuf::from(program);
|
|
|
|
if !program_path.exists() {
|
2021-01-28 12:11:53 -08:00
|
|
|
println!(
|
2020-12-11 20:03:15 -08:00
|
|
|
"Error: program file does not exist: {}",
|
|
|
|
program_path.display()
|
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
}
|
2020-12-08 23:18:27 -08:00
|
|
|
|
2020-12-11 20:03:15 -08:00
|
|
|
programs.push(ProgramInfo {
|
|
|
|
program_id: address,
|
|
|
|
loader: solana_sdk::bpf_loader::id(),
|
|
|
|
program_path,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
2020-12-08 23:18:27 -08:00
|
|
|
}
|
|
|
|
|
2021-01-21 13:16:40 -08:00
|
|
|
let clone_accounts: HashSet<_> = pubkeys_of(&matches, "clone_account")
|
|
|
|
.map(|v| v.into_iter().collect())
|
|
|
|
.unwrap_or_default();
|
|
|
|
|
2021-01-21 18:34:51 -08:00
|
|
|
let warp_slot = if matches.is_present("warp_slot") {
|
|
|
|
Some(match matches.value_of("warp_slot") {
|
|
|
|
Some(_) => value_t_or_exit!(matches, "warp_slot", Slot),
|
|
|
|
None => {
|
|
|
|
cluster_rpc_client.as_ref().unwrap_or_else(|_| {
|
2021-01-28 12:11:53 -08:00
|
|
|
println!("The --url argument must be provided if --warp-slot/-w is used without an explicit slot");
|
2021-01-21 18:34:51 -08:00
|
|
|
exit(1);
|
|
|
|
|
|
|
|
}).get_slot()
|
|
|
|
.unwrap_or_else(|err| {
|
2021-01-28 12:11:53 -08:00
|
|
|
println!("Unable to get current cluster slot: {}", err);
|
2021-01-21 18:34:51 -08:00
|
|
|
exit(1);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2020-12-15 10:52:22 -08:00
|
|
|
if !ledger_path.exists() {
|
|
|
|
fs::create_dir(&ledger_path).unwrap_or_else(|err| {
|
2021-01-28 12:11:53 -08:00
|
|
|
println!(
|
2020-12-15 10:52:22 -08:00
|
|
|
"Error: Unable to create directory {}: {}",
|
|
|
|
ledger_path.display(),
|
|
|
|
err
|
|
|
|
);
|
|
|
|
exit(1);
|
2020-12-15 11:06:03 -08:00
|
|
|
});
|
2020-12-15 10:52:22 -08:00
|
|
|
}
|
|
|
|
|
2020-12-15 11:06:03 -08:00
|
|
|
let mut ledger_fd_lock = FdLock::new(fs::File::open(&ledger_path).unwrap());
|
2020-12-15 10:52:22 -08:00
|
|
|
let _ledger_lock = ledger_fd_lock.try_lock().unwrap_or_else(|_| {
|
2021-01-28 12:11:53 -08:00
|
|
|
println!(
|
2021-02-05 22:39:23 -08:00
|
|
|
"Error: Unable to lock {} directory. Check if another validator is running",
|
2020-12-15 10:52:22 -08:00
|
|
|
ledger_path.display()
|
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
});
|
|
|
|
|
2020-12-15 11:06:03 -08:00
|
|
|
if reset_ledger {
|
|
|
|
remove_directory_contents(&ledger_path).unwrap_or_else(|err| {
|
2021-01-28 12:11:53 -08:00
|
|
|
println!("Error: Unable to remove {}: {}", ledger_path.display(), err);
|
2020-12-15 11:06:03 -08:00
|
|
|
exit(1);
|
|
|
|
})
|
|
|
|
}
|
2021-01-11 11:38:55 -08:00
|
|
|
solana_runtime::snapshot_utils::remove_tmp_snapshot_archives(&ledger_path);
|
2020-12-15 11:06:03 -08:00
|
|
|
|
2020-12-08 23:18:27 -08:00
|
|
|
let validator_log_symlink = ledger_path.join("validator.log");
|
|
|
|
let logfile = if output != Output::Log {
|
|
|
|
let validator_log_with_timestamp = format!(
|
|
|
|
"validator-{}.log",
|
|
|
|
SystemTime::now()
|
|
|
|
.duration_since(UNIX_EPOCH)
|
|
|
|
.unwrap()
|
|
|
|
.as_millis()
|
|
|
|
);
|
|
|
|
|
2020-12-11 20:03:15 -08:00
|
|
|
let _ = fs::remove_file(&validator_log_symlink);
|
2020-12-08 23:18:27 -08:00
|
|
|
symlink::symlink_file(&validator_log_with_timestamp, &validator_log_symlink).unwrap();
|
|
|
|
|
|
|
|
Some(
|
|
|
|
ledger_path
|
|
|
|
.join(validator_log_with_timestamp)
|
|
|
|
.into_os_string()
|
|
|
|
.into_string()
|
|
|
|
.unwrap(),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
2021-01-28 12:11:53 -08:00
|
|
|
let _logger_thread = redirect_stderr_to_file(logfile);
|
2020-12-08 23:18:27 -08:00
|
|
|
|
2020-12-11 20:03:15 -08:00
|
|
|
let faucet_lamports = sol_to_lamports(1_000_000.);
|
|
|
|
let faucet_keypair_file = ledger_path.join("faucet-keypair.json");
|
|
|
|
if !faucet_keypair_file.exists() {
|
|
|
|
write_keypair_file(&Keypair::new(), faucet_keypair_file.to_str().unwrap()).unwrap_or_else(
|
|
|
|
|err| {
|
2021-01-28 12:11:53 -08:00
|
|
|
println!(
|
2020-12-11 20:03:15 -08:00
|
|
|
"Error: Failed to write {}: {}",
|
|
|
|
faucet_keypair_file.display(),
|
|
|
|
err
|
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2021-02-05 22:39:23 -08:00
|
|
|
|
2020-12-11 20:03:15 -08:00
|
|
|
let faucet_keypair =
|
|
|
|
read_keypair_file(faucet_keypair_file.to_str().unwrap()).unwrap_or_else(|err| {
|
2021-01-28 12:11:53 -08:00
|
|
|
println!(
|
2020-12-11 20:03:15 -08:00
|
|
|
"Error: Failed to read {}: {}",
|
|
|
|
faucet_keypair_file.display(),
|
|
|
|
err
|
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
});
|
2021-02-05 22:39:23 -08:00
|
|
|
let faucet_pubkey = faucet_keypair.pubkey();
|
|
|
|
|
|
|
|
if let Some(faucet_addr) = &faucet_addr {
|
|
|
|
let (sender, receiver) = channel();
|
|
|
|
run_local_faucet_with_port(faucet_keypair, sender, None, faucet_addr.port());
|
|
|
|
let _ = receiver.recv().expect("run faucet").unwrap_or_else(|err| {
|
|
|
|
println!("Error: failed to start faucet: {}", err);
|
|
|
|
exit(1);
|
|
|
|
});
|
|
|
|
}
|
2020-12-11 20:03:15 -08:00
|
|
|
|
2021-02-05 22:39:23 -08:00
|
|
|
record_start(
|
|
|
|
&ledger_path,
|
|
|
|
Some(&SocketAddr::new(
|
|
|
|
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
|
|
|
|
rpc_port,
|
|
|
|
)),
|
|
|
|
)
|
|
|
|
.unwrap_or_else(|err| println!("Error: failed to record validator start: {}", err));
|
|
|
|
|
|
|
|
let dashboard = if output == Output::Dashboard {
|
|
|
|
Some(Dashboard::new(&ledger_path, Some(&validator_log_symlink)).unwrap())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
2021-01-14 21:19:08 -08:00
|
|
|
|
2020-12-08 23:18:27 -08:00
|
|
|
let test_validator = {
|
2021-01-21 13:16:40 -08:00
|
|
|
let mut genesis = TestValidatorGenesis::default();
|
|
|
|
genesis
|
2021-01-14 21:19:08 -08:00
|
|
|
.ledger_path(&ledger_path)
|
2020-12-11 20:03:15 -08:00
|
|
|
.add_account(
|
2021-02-05 22:39:23 -08:00
|
|
|
faucet_pubkey,
|
2020-12-11 20:03:15 -08:00
|
|
|
Account::new(faucet_lamports, 0, &system_program::id()),
|
|
|
|
)
|
|
|
|
.rpc_config(JsonRpcConfig {
|
|
|
|
enable_validator_exit: true,
|
|
|
|
enable_rpc_transaction_history: true,
|
2021-02-01 14:34:40 -08:00
|
|
|
enable_cpi_and_log_storage: true,
|
2020-12-11 20:03:15 -08:00
|
|
|
faucet_addr,
|
|
|
|
..JsonRpcConfig::default()
|
|
|
|
})
|
2021-02-09 11:02:04 -08:00
|
|
|
.bpf_jit(bpf_jit)
|
2020-12-11 20:03:15 -08:00
|
|
|
.rpc_port(rpc_port)
|
2021-01-21 13:16:40 -08:00
|
|
|
.add_programs_with_path(&programs);
|
|
|
|
|
|
|
|
if !clone_accounts.is_empty() {
|
2021-01-21 18:34:51 -08:00
|
|
|
genesis.clone_accounts(
|
|
|
|
clone_accounts,
|
|
|
|
cluster_rpc_client
|
|
|
|
.as_ref()
|
|
|
|
.expect("bug: --url argument missing?"),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(warp_slot) = warp_slot {
|
|
|
|
genesis.warp_slot(warp_slot);
|
2021-01-21 13:16:40 -08:00
|
|
|
}
|
|
|
|
genesis.start_with_mint_address(mint_address)
|
2021-02-05 22:39:23 -08:00
|
|
|
};
|
2020-12-08 23:18:27 -08:00
|
|
|
|
2021-02-05 22:39:23 -08:00
|
|
|
match test_validator {
|
|
|
|
Ok(_test_validator) => match dashboard {
|
|
|
|
Some(dashboard) => dashboard.run(),
|
|
|
|
None => std::thread::park(),
|
|
|
|
},
|
|
|
|
Err(err) => {
|
|
|
|
drop(dashboard);
|
|
|
|
println!("Error: failed to start validator: {}", err);
|
2021-01-28 12:11:53 -08:00
|
|
|
exit(1);
|
2020-12-08 23:18:27 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-15 11:06:03 -08:00
|
|
|
|
|
|
|
fn remove_directory_contents(ledger_path: &Path) -> Result<(), io::Error> {
|
|
|
|
for entry in fs::read_dir(&ledger_path)? {
|
|
|
|
let entry = entry?;
|
|
|
|
if entry.metadata()?.is_file() {
|
|
|
|
fs::remove_file(&entry.path())?
|
|
|
|
} else {
|
|
|
|
fs::remove_dir_all(&entry.path())?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|