Pārlūkot izejas kodu

refactor: resolved_hf_cache_dir returns PathBuf instead of String

Signals that the return value is a filesystem path, not arbitrary
text.  Updated start_cluster to accept PathBuf throughout.
Alexander Korolev 4 mēneši atpakaļ
vecāks
revīzija
679c256a60
2 mainītis faili ar 12 papildinājumiem un 11 dzēšanām
  1. 6 5
      src/config.rs
  2. 6 6
      src/docker/mod.rs

+ 6 - 5
src/config.rs

@@ -69,16 +69,17 @@ fn default_port() -> u16 {
     30000
 }
 impl Config {
-    pub fn resolved_hf_cache_dir(&self) -> String {
+    pub fn resolved_hf_cache_dir(&self) -> std::path::PathBuf {
         if let Some(ref dir) = self.hf_cache_dir {
-            return dir.clone();
+            return std::path::PathBuf::from(dir);
         }
         let home = if self.ssh_user == "root" {
-            "/root".to_string()
+            "/root"
         } else {
-            format!("/home/{}", self.ssh_user)
+            // Safe to return a temporary String; PathBuf::from copies it
+            return std::path::PathBuf::from(format!("/home/{}/.cache/huggingface", self.ssh_user));
         };
-        format!("{}/.cache/huggingface", home)
+        std::path::PathBuf::from(format!("{}/.cache/huggingface", home))
     }
 }
 #[derive(Clone, Deserialize)]

+ 6 - 6
src/docker/mod.rs

@@ -1,10 +1,9 @@
-use anyhow::{Context, Result};
-use tokio::time::{Duration, sleep};
-use tracing::info;
-
 use crate::config::{Cluster, Config, NcclConfig, Node, Recipe, load_recipe, resolve_cluster};
 use crate::doctor::try_repaired_image;
 use crate::ssh::{run_ssh, run_ssh_follow, run_ssh_with_retry};
+use anyhow::{Context, Result};
+use tokio::time::{Duration, sleep};
+use tracing::info;
 /// Launches containers across the cluster for a recipe.
 pub async fn serve(
     config: &Config,
@@ -261,7 +260,7 @@ async fn start_cluster(
     nccl: &NcclConfig,
     recipe_name: &str,
     recipe: &Recipe,
-    cache_dir: String,
+    cache_dir: std::path::PathBuf,
     keep: bool,
     dry_run: bool,
 ) -> Result<()> {
@@ -289,6 +288,7 @@ async fn start_cluster(
         );
 
         let cd = cache_dir.clone();
+        let cd_s = cd.to_string_lossy().into_owned();
         handles.push(tokio::spawn(async move {
             if !dry {
                 let _ = run_ssh(&config, &node, cleanup, dry).await;
@@ -302,7 +302,7 @@ async fn start_cluster(
                 is_head,
                 pp_size,
                 nnodes,
-                &cd,
+                &cd_s,
                 keep,
                 config.init_port,
             )