diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml index 6ce7dedd0a..470250ed18 100644 --- a/.github/workflows/pr-lint.yml +++ b/.github/workflows/pr-lint.yml @@ -22,7 +22,6 @@ jobs: types: | feat fix - improvement chore docs deps @@ -39,9 +38,9 @@ jobs: TITLE: ${{ github.event.pull_request.title }} run: | title_length=${#TITLE} - if [ $title_length -gt 85 ] + if [ $title_length -gt 72 ] then - echo "PR title is too long (greater than 85 characters)" + echo "PR title is too long (greater than 72 characters)" exit 1 fi diff --git a/mm2src/common/common.rs b/mm2src/common/common.rs index d6e9a45579..3e5bebebeb 100644 --- a/mm2src/common/common.rs +++ b/mm2src/common/common.rs @@ -160,14 +160,14 @@ use std::convert::TryInto; use std::fmt::Write as FmtWrite; use std::fs::File; use std::future::Future as Future03; -use std::io::{self, BufReader, Read, Write}; +use std::io::{BufReader, Read, Write}; use std::iter::Peekable; use std::mem::{forget, zeroed}; use std::num::{NonZeroUsize, TryFromIntError}; use std::ops::{Add, Deref, Div, RangeInclusive}; use std::os::raw::c_void; use std::panic::{set_hook, PanicInfo}; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::ptr::read_volatile; use std::sync::atomic::Ordering; use std::time::{Duration, SystemTime, SystemTimeError}; @@ -790,7 +790,7 @@ pub fn kdf_app_dir() -> Option { } /// Returns path of the coins file. -pub fn kdf_coins_file() -> Result { +pub fn kdf_coins_file() -> PathBuf { #[cfg(not(target_arch = "wasm32"))] let value_from_env = env::var("MM_COINS_PATH").ok(); @@ -801,7 +801,7 @@ pub fn kdf_coins_file() -> Result { } /// Returns path of the config file. -pub fn kdf_config_file() -> Result { +pub fn kdf_config_file() -> PathBuf { #[cfg(not(target_arch = "wasm32"))] let value_from_env = env::var("MM_CONF_PATH").ok(); @@ -817,41 +817,16 @@ pub fn kdf_config_file() -> Result { /// 1- From the environment variable. /// 2- From the current directory where app is called. /// 3- From the root application directory. -fn find_kdf_dependency_file(value_from_env: Option, path_leaf: &str) -> Result { +pub fn find_kdf_dependency_file(value_from_env: Option, path_leaf: &str) -> PathBuf { if let Some(path) = value_from_env { - let path = PathBuf::from(path); - require_file(&path)?; - return Ok(path); + return PathBuf::from(path); } let from_current_dir = PathBuf::from(path_leaf); - - let path = if from_current_dir.exists() { + if from_current_dir.exists() { from_current_dir } else { kdf_app_dir().unwrap_or_default().join(path_leaf) - }; - - require_file(&path)?; - return Ok(path); - - fn require_file(path: &Path) -> Result<(), io::Error> { - if path.is_dir() { - // TODO: use `IsADirectory` variant which is stabilized with 1.83 - return Err(io::Error::new( - io::ErrorKind::InvalidInput, - format!("Expected file but '{}' is a directory.", path.display()), - )); - } - - if !path.exists() { - return Err(io::Error::new( - io::ErrorKind::NotFound, - format!("File '{}' is not present.", path.display()), - )); - } - - Ok(()) } } diff --git a/mm2src/mm2_main/src/mm2.rs b/mm2src/mm2_main/src/mm2.rs index 0166a10623..7ca5a995d1 100644 --- a/mm2src/mm2_main/src/mm2.rs +++ b/mm2src/mm2_main/src/mm2.rs @@ -304,23 +304,22 @@ pub fn mm2_main(version: String, datetime: String) { /// Parses and returns the `first_arg` as JSON. /// Attempts to load the config from `MM2.json` file if `first_arg` is None pub fn get_mm2config(first_arg: Option<&str>) -> Result { + let conf_path = common::kdf_config_file(); + let conf_from_file = slurp(&conf_path); let conf = match first_arg { - Some(s) => s.to_owned(), + Some(s) => s, None => { - let conf_path = common::kdf_config_file().map_err(|e| e.to_string())?; - let conf_from_file = slurp(&conf_path); - if conf_from_file.is_empty() { return ERR!( "Config is not set from command line arg and {} file doesn't exist.", conf_path.display() ); } - try_s!(String::from_utf8(conf_from_file)) + try_s!(std::str::from_utf8(&conf_from_file)) }, }; - let mut conf: Json = match json::from_str(&conf) { + let mut conf: Json = match json::from_str(conf) { Ok(json) => json, // Syntax or io errors may include the conf string in the error message so we don't want to take risks and show these errors internals in the log. // If new variants are added to the Error enum, there can be a risk of exposing the conf string in the error message when updating serde_json so @@ -329,7 +328,7 @@ pub fn get_mm2config(first_arg: Option<&str>) -> Result { }; if conf["coins"].is_null() { - let coins_path = common::kdf_coins_file().map_err(|e| e.to_string())?; + let coins_path = common::kdf_coins_file(); let coins_from_file = slurp(&coins_path); if coins_from_file.is_empty() {