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

Support process substitution #574

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 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
151 changes: 137 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ futures = "0.3"

# remove this line when ckb-vm stick the version of ckb-vm-definitions
ckb-vm-definitions = "=0.21.3"
cached = "0.47.0"

[target.'cfg(unix)'.dependencies]
tui = "0.6.0"
Expand Down
36 changes: 28 additions & 8 deletions src/utils/arg_parser.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cached::proc_macro::cached;
use std::fmt::Display;
use std::fs;
use std::io::Read;
Expand All @@ -7,6 +8,9 @@ use std::path::PathBuf;
use std::str::FromStr;
use std::time::Duration;

#[cfg(unix)]
use std::os::unix::fs::FileTypeExt;

use clap::ArgMatches;
use faster_hex::hex_decode;
use url::Url;
Expand Down Expand Up @@ -232,6 +236,15 @@ impl ArgParser<PathBuf> for FilePathParser {
fn parse(&self, input: &str) -> Result<PathBuf, String> {
let path = self.path_parser.parse(input)?;
if path.exists() && !path.is_file() {
#[cfg(unix)]
if path
.metadata()
.map(|m| m.file_type().is_fifo())
.unwrap_or_default()
{
return Ok(path);
}

Err(format!("path <{}> is not file", input))
} else {
Ok(path)
Expand Down Expand Up @@ -293,13 +306,21 @@ impl ArgParser<Vec<u8>> for HexFilePathParser {

pub struct PrivkeyPathParser;

#[cached]
fn cache_read_privkey_file(path: PathBuf) -> Result<String, String> {
let mut content = String::new();
let mut file = fs::File::open(path).map_err(|err| err.to_string())?;
file.read_to_string(&mut content)
.map_err(|err| err.to_string())?;
Ok(content)
}

impl ArgParser<PrivkeyWrapper> for PrivkeyPathParser {
fn parse(&self, input: &str) -> Result<PrivkeyWrapper, String> {
let path: PathBuf = FilePathParser::new(true).parse(input)?;
let mut content = String::new();
let mut file = fs::File::open(path).map_err(|err| err.to_string())?;
file.read_to_string(&mut content)
.map_err(|err| err.to_string())?;

let content = cache_read_privkey_file(path)?;

let privkey_string: String = content
.split_whitespace()
.next()
Expand All @@ -317,10 +338,9 @@ pub struct ExtendedPrivkeyPathParser;
impl ArgParser<MasterPrivKey> for ExtendedPrivkeyPathParser {
fn parse(&self, input: &str) -> Result<MasterPrivKey, String> {
let path: PathBuf = FilePathParser::new(true).parse(input)?;
let mut content = String::new();
let mut file = fs::File::open(path).map_err(|err| err.to_string())?;
file.read_to_string(&mut content)
.map_err(|err| err.to_string())?;

let content = cache_read_privkey_file(path)?;

let lines = content
.split_whitespace()
.map(ToOwned::to_owned)
Expand Down
Loading