Skip to content

Commit

Permalink
fix: expand path synchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeidnx authored and mkroening committed Feb 14, 2025
1 parent a59d3fc commit 13449f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion edu-sync-cli/src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Subcommand {
.parse()?
};

let expanded_path = config::expand_path(&self.path).await?;
let expanded_path = config::expand_path(&self.path)?;
let account_config = AccountConfig::new(self.url, token, expanded_path, self.lang).await?;
let mut config = config_task.await??;
let account_name = account_config.to_string();
Expand Down
10 changes: 4 additions & 6 deletions edu-sync/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use thiserror::Error;
use tokio::{
fs::{self, File},
io::AsyncWriteExt,
runtime::Handle,
};
use tracing::warn;

Expand Down Expand Up @@ -108,12 +107,12 @@ impl CourseConfigs {

// Expand Tilde to home folder, create the directory if it does not exist and
// then canonicalize the path.
pub async fn expand_path(path: &Path) -> io::Result<PathBuf> {
pub fn expand_path(path: &Path) -> io::Result<PathBuf> {
let expanded_path = shellexpand::path::tilde(&path);
if !expanded_path.try_exists()? {
fs::create_dir(&expanded_path).await?;
std::fs::create_dir(&expanded_path)?;
}
fs::canonicalize(expanded_path).await
std::fs::canonicalize(expanded_path)
}

// Custom deserializer function to check if the path is absolute and to
Expand All @@ -123,8 +122,7 @@ where
D: Deserializer<'de>,
{
let path = PathBuf::deserialize(deserializer)?;
let expanded_path = Handle::current().block_on(expand_path(&path));
expanded_path.map_err(serde::de::Error::custom)
expand_path(&path).map_err(serde::de::Error::custom)
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down

0 comments on commit 13449f1

Please sign in to comment.