debug log belongs in cache directory not config directory (#179)

* log files are now written to cache dir instead of config dir

* lint

* fmt
This commit is contained in:
Christian Visintin
2023-05-09 15:32:42 +02:00
committed by GitHub
parent 9bf23b3f6b
commit 9009002b6e
26 changed files with 96 additions and 160 deletions

View File

@@ -5,16 +5,12 @@
// Ext
use magic_crypt::MagicCryptTrait;
/// ### aes128_b64_crypt
///
/// Crypt a string using AES128; output is returned as a BASE64 string
pub fn aes128_b64_crypt(key: &str, input: &str) -> String {
let crypter = new_magic_crypt!(key, 128);
crypter.encrypt_str_to_base64(input)
}
/// ### aes128_b64_decrypt
///
/// Decrypt a string using AES128
pub fn aes128_b64_decrypt(key: &str, secret: &str) -> Result<String, magic_crypt::MagicCryptError> {
let crypter = new_magic_crypt!(key, 128);

View File

@@ -7,8 +7,6 @@ use std::fs::OpenOptions;
use std::io;
use std::path::Path;
/// ### open_file
///
/// Open file provided as parameter
pub fn open_file<P>(filename: P, create: bool, write: bool, append: bool) -> io::Result<File>
where

View File

@@ -10,8 +10,6 @@ use std::time::{Duration, SystemTime};
use tuirealm::tui::style::Color;
use unicode_width::UnicodeWidthStr;
/// ### fmt_pex
///
/// Convert permissions bytes of permissions value into ls notation (e.g. rwx,-wx,--x)
pub fn fmt_pex(pex: UnixPexClass) -> String {
format!(
@@ -31,16 +29,12 @@ pub fn fmt_pex(pex: UnixPexClass) -> String {
)
}
/// ### instant_to_str
///
/// Format a `Instant` into a time string
pub fn fmt_time(time: SystemTime, fmt: &str) -> String {
let datetime: DateTime<Local> = time.into();
format!("{}", datetime.format(fmt))
}
/// ### fmt_millis
///
/// Format duration as {secs}.{millis}
pub fn fmt_millis(duration: Duration) -> String {
let seconds: u128 = duration.as_millis() / 1000;
@@ -48,16 +42,12 @@ pub fn fmt_millis(duration: Duration) -> String {
format!("{}.{:0width$}", seconds, millis, width = 3)
}
/// ### elide_path
///
/// Elide a path if longer than width
/// In this case, the path is formatted to {ANCESTOR[0]}/…/{PARENT[0]}/{BASENAME}
pub fn fmt_path_elide(p: &Path, width: usize) -> String {
fmt_path_elide_ex(p, width, 0)
}
/// ### fmt_path_elide_ex
///
/// Elide a path if longer than width
/// In this case, the path is formatted to {ANCESTOR[0]}/…/{PARENT[0]}/{BASENAME}
/// This function allows to specify an extra length to consider to elide path
@@ -90,8 +80,6 @@ pub fn fmt_path_elide_ex(p: &Path, width: usize, extra_len: usize) -> String {
}
}
/// ### fmt_color
///
/// Format color
pub fn fmt_color(color: &Color) -> String {
match color {
@@ -258,15 +246,11 @@ pub fn fmt_color(color: &Color) -> String {
}
}
/// ### shadow_password
///
/// Return a string with the same length of input string, but each character is replaced by '*'
pub fn shadow_password(s: &str) -> String {
(0..s.len()).map(|_| '*').collect()
}
/// ### fmt_bytes
///
/// Format bytes
pub fn fmt_bytes(v: u64) -> String {
if v >= 1125899906842624 {

View File

@@ -68,8 +68,6 @@ static BYTESIZE_REGEX: Lazy<Regex> = lazy_regex!(r"(:?([0-9])+)( )*(:?[KMGTP])?B
// -- remote opts
/// ### parse_remote_opt
///
/// Parse remote option string. Returns in case of success a RemoteOptions struct
/// For ssh if username is not provided, current user will be used.
/// In case of error, message is returned
@@ -115,8 +113,6 @@ pub fn parse_remote_opt(s: &str) -> Result<FileTransferParams, String> {
}
}
/// ### parse_remote_opt_protocol
///
/// Parse protocol from CLI option. In case of success, return the protocol to be used and the remaining arguments
fn parse_remote_opt_protocol(
s: &str,
@@ -147,8 +143,6 @@ fn parse_remote_opt_protocol(
}
}
/// ### parse_generic_remote_opt
///
/// Parse generic remote options
fn parse_generic_remote_opt(
s: &str,
@@ -202,8 +196,6 @@ fn parse_generic_remote_opt(
}
}
/// ### parse_s3_remote_opt
///
/// Parse remote options for s3 protocol
fn parse_s3_remote_opt(s: &str) -> Result<FileTransferParams, String> {
match REMOTE_S3_OPT_REGEX.captures(s) {
@@ -229,8 +221,6 @@ fn parse_s3_remote_opt(s: &str) -> Result<FileTransferParams, String> {
}
}
/// ### parse_semver
///
/// Parse semver string
pub fn parse_semver(haystack: &str) -> Option<String> {
match SEMVER_REGEX.captures(haystack) {
@@ -239,8 +229,6 @@ pub fn parse_semver(haystack: &str) -> Option<String> {
}
}
/// ### parse_color
///
/// Parse color from string into a `Color` enum.
///
/// Color may be in different format:
@@ -300,8 +288,6 @@ impl FromStr for ByteUnit {
}
}
/// ### parse_bytesize
///
/// Parse bytes repr (e.g. `24 MB`) into `ByteSize`
pub fn parse_bytesize<S: AsRef<str>>(bytes: S) -> Option<ByteSize> {
match BYTESIZE_REGEX.captures(bytes.as_ref()) {

View File

@@ -4,8 +4,6 @@
use std::path::{Component, Path, PathBuf};
/// ### absolutize
///
/// Absolutize target path if relative.
/// For example:
///
@@ -24,8 +22,6 @@ pub fn absolutize(wrkdir: &Path, target: &Path) -> PathBuf {
}
}
/// ### diff_paths
///
/// This function will get the difference from path `path` to `base`. Basically will remove `base` from `path`
///
/// For example:
@@ -127,24 +123,21 @@ mod test {
#[test]
fn should_tell_whether_path_is_child_of() {
assert_eq!(
is_child_of(Path::new("/home/foo/foo.txt"), Path::new("/home"),),
true
);
assert_eq!(
is_child_of(Path::new("/home/foo/foo.txt"), Path::new("/home/foo/"),),
true
);
assert_eq!(
is_child_of(
Path::new("/home/foo/foo.txt"),
Path::new("/home/foo/foo.txt"),
),
true
);
assert_eq!(
is_child_of(Path::new("/home/foo/foo.txt"), Path::new("/tmp"),),
false
);
assert!(is_child_of(
Path::new("/home/foo/foo.txt"),
Path::new("/home"),
));
assert!(is_child_of(
Path::new("/home/foo/foo.txt"),
Path::new("/home/foo/"),
));
assert!(is_child_of(
Path::new("/home/foo/foo.txt"),
Path::new("/home/foo/foo.txt"),
));
assert!(!is_child_of(
Path::new("/home/foo/foo.txt"),
Path::new("/tmp"),
));
}
}

View File

@@ -33,8 +33,6 @@ pub fn create_sample_file_with_content(content: impl std::fmt::Display) -> Named
tmpfile
}
/// ### make_file_at
///
/// Make a file with `name` at specified path
pub fn make_file_at(dir: &Path, filename: &str) -> std::io::Result<PathBuf> {
let mut p: PathBuf = PathBuf::from(dir);
@@ -47,8 +45,6 @@ pub fn make_file_at(dir: &Path, filename: &str) -> std::io::Result<PathBuf> {
Ok(p)
}
/// ### make_dir_at
///
/// Make a directory in `dir`
pub fn make_dir_at(dir: &Path, dirname: &str) -> std::io::Result<()> {
let mut p: PathBuf = PathBuf::from(dir);
@@ -69,8 +65,6 @@ pub fn make_fsentry<P: AsRef<Path>>(path: P, is_dir: bool) -> File {
}
}
/// ### create_file_ioers
///
/// Open a file with two handlers, the first is to read, the second is to write
pub fn create_file_ioers(p: &Path) -> (StdFile, StdFile) {
(