Skip to content

Commit

Permalink
limit usage for deprecated function
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen1Plus committed Aug 2, 2024
1 parent c979555 commit faf3aee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
9 changes: 0 additions & 9 deletions src/fsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ use serde_json as json;

pub(crate) mod defs;

/// Ensure that a directory exists, failed if missing parent directories.
#[deprecated]
pub(crate) fn ensure_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
if !path.as_ref().exists() {
fs::create_dir(path)?;
}
Ok(())
}

// An object that represents a file or a whole directory.
// note: can not be root directory
#[derive(Clone, Serialize, Deserialize)]
Expand Down
18 changes: 12 additions & 6 deletions src/fsx/defs.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use std::{path::PathBuf, sync::LazyLock};

use super::ensure_dir;
use std::path::{Path, PathBuf};
use std::sync::LazyLock;
use std::{fs, io};

/// The user's data directory.
static DATA: LazyLock<PathBuf> =
LazyLock::new(|| dirs::data_dir().expect("Failed to find user's data directory"));
/// The user's cache directory.
static CACHE: LazyLock<PathBuf> =
LazyLock::new(|| dirs::cache_dir().expect("Failed to find user's cache directory"));

#[cfg(debug_assertions)]
static TYPORA: LazyLock<PathBuf> = LazyLock::new(|| PathBuf::from("debug-dirs").join("Typora"));
Expand Down Expand Up @@ -55,3 +52,12 @@ pub(crate) fn init() {
ensure_dir(TYTM_MANIFEST.as_path()).expect("Failed to create TyTM manifest directory");
assert!(TYTM_MANIFEST.is_dir());
}

/// Ensure that a directory exists, failed if missing parent directories.
#[deprecated]
fn ensure_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
if !path.as_ref().exists() {
fs::create_dir(path)?;
}
Ok(())
}

0 comments on commit faf3aee

Please sign in to comment.