Skip to content

Commit

Permalink
style: improve impl
Browse files Browse the repository at this point in the history
  • Loading branch information
saying121 committed Nov 16, 2024
1 parent 82103cd commit 115b622
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
55 changes: 36 additions & 19 deletions crates/decrypt-cookies/src/browser/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ use std::path::PathBuf;
#[derive(Debug)]
#[derive(thiserror::Error)]
pub enum BuilderError {
#[error("No such file: {0:?}")]
NoFile(PathBuf),
#[error("File operation failed: {path:?}")]
FileOp {
#[source]
source: std::io::Error,
path: PathBuf,
},
#[error("Create dir failed: {0:?}")]
CreateDir(PathBuf),
#[error(transparent)]
Ini(#[from] ini::Error),
#[error("Ini operation failed: {path:?}")]
Ini {
#[source]
source: ini::Error,
path: PathBuf,
},
#[error("Profile {0} missing `Name` properties")]
ProfilePath(String),
#[error("Install {0} missing `Default` properties")]
Expand Down Expand Up @@ -83,14 +91,14 @@ macro_rules! chromium_copy_temp {
let key_cp = fs::copy(&key, &key_temp);

let (ck, lg, k) = join!(cookies_cp, login_cp, key_cp);
if ck.is_err() {
return Err(BuilderError::NoFile(cookies));
if let Err(e) = ck {
return Err(BuilderError::FileOp { source: e, path: cookies });
}
if lg.is_err() {
return Err(BuilderError::NoFile(login_data));
if let Err(e) = lg {
return Err(BuilderError::FileOp { source: e, path: login_data });
}
if k.is_err() {
return Err(BuilderError::NoFile(key));
if let Err(e) = k {
return Err(BuilderError::FileOp { source: e, path: key });
}

Ok(TempPaths {
Expand Down Expand Up @@ -153,14 +161,23 @@ macro_rules! firefox_copy_temp {
let key_cp = fs::copy(&key, &key_temp);

let (ck, lg, k) = join!(cookies_cp, login_cp, key_cp);
if ck.is_err() {
return Err($crate::browser::builder::BuilderError::NoFile(cookies));
if let Err(e) = ck {
return Err($crate::browser::builder::BuilderError::FileOp {
source: e,
path: cookies,
});
}
if lg.is_err() {
return Err($crate::browser::builder::BuilderError::NoFile(login_data));
if let Err(e) = lg {
return Err($crate::browser::builder::BuilderError::FileOp {
source: e,
path: login_data,
});
}
if k.is_err() {
return Err($crate::browser::builder::BuilderError::NoFile(key));
if let Err(e) = k {
return Err($crate::browser::builder::BuilderError::FileOp {
source: e,
path: key,
});
}

Ok($crate::browser::builder::TempPaths {
Expand All @@ -175,9 +192,9 @@ macro_rules! firefox_copy_temp {
pub(crate) fn firefox_profile(mut base: PathBuf, profile: Option<&str>) -> Result<PathBuf> {
let ini_path = base.join("profiles.ini");

let Ok(ini_file) = ini::Ini::load_from_file(&ini_path)
else {
return Err(BuilderError::NoFile(ini_path));
let ini_file = match ini::Ini::load_from_file(&ini_path) {
Ok(v) => v,
Err(e) => return Err(BuilderError::Ini { source: e, path: ini_path }),
};
for (sec, prop) in ini_file {
let Some(sec) = sec
Expand Down
6 changes: 3 additions & 3 deletions crates/decrypt-cookies/src/browser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ macro_rules! chromium_common {
pub const BASE: &'static str = $base;
pub const NAME: &'static str = stringify!($browser);
/// sqlite3
pub const COOKIES: &str = concatcp!($browser::BASE, "/", $cookies);
pub const LOGIN_DATA: &str = concatcp!($browser::BASE, "/", $login_data);
pub const KEY: &str = concatcp!($browser::BASE, "/", $key);
pub const COOKIES: &str = concatcp!($browser::BASE, std::path::MAIN_SEPARATOR, $cookies);
pub const LOGIN_DATA: &str = concatcp!($browser::BASE, std::path::MAIN_SEPARATOR, $login_data);
pub const KEY: &str = concatcp!($browser::BASE, std::path::MAIN_SEPARATOR, $key);
$(
pub const SAFE_STORAGE: &str = concatcp!($safe_name, " Safe Storage");
#[cfg(target_os = "macos")]
Expand Down

0 comments on commit 115b622

Please sign in to comment.