Skip to content

Commit

Permalink
handle already exists error
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 committed Jun 13, 2024
1 parent 9b2be42 commit 3c961fd
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lantern_cli/src/daemon/embedding_jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ async fn job_update_processor(
Ok(())
}

async fn create_data_path(logger: Arc<Logger>) -> &'static str {
async fn create_data_path(logger: Arc<Logger>) -> Result<&'static str, anyhow::Error> {
let tmp_path = "/tmp/lantern-daemon";
let data_path = if cfg!(target_os = "macos") {
"/usr/local/var/lantern-daemon"
Expand All @@ -860,11 +860,11 @@ async fn create_data_path(logger: Arc<Logger>) -> &'static str {

let data_path_obj = Path::new(data_path);
if data_path_obj.exists() {
return data_path;
return Ok(data_path);
}

if fs::create_dir(data_path).await.is_ok() {
return data_path;
return Ok(data_path);
}

logger.warn(&format!(
Expand All @@ -873,11 +873,16 @@ async fn create_data_path(logger: Arc<Logger>) -> &'static str {
let tmp_path_obj = Path::new(tmp_path);

if tmp_path_obj.exists() {
return tmp_path;
return Ok(tmp_path);
}

fs::create_dir(tmp_path).await.unwrap();
tmp_path
if let Err(e) = fs::create_dir(tmp_path).await {
match e.kind() {
std::io::ErrorKind::AlreadyExists => {}
_ => anyhow::bail!(e),
}
}
Ok(tmp_path)
}

async fn stop_all_client_jobs(
Expand Down

0 comments on commit 3c961fd

Please sign in to comment.