about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/bootstrap/src/utils/build_stamp.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/bootstrap/src/utils/build_stamp.rs b/src/bootstrap/src/utils/build_stamp.rs
index 7c3935e1db2..79b9951f5fb 100644
--- a/src/bootstrap/src/utils/build_stamp.rs
+++ b/src/bootstrap/src/utils/build_stamp.rs
@@ -34,6 +34,9 @@ impl BuildStamp {
     ///
     /// By default, stamp will be an empty file named `.stamp` within the specified directory.
     pub fn new(dir: &Path) -> Self {
+        // Avoid using `is_dir()` as the directory may not exist yet.
+        // It is more appropriate to assert that the path is not a file.
+        assert!(!dir.is_file(), "can't be a file path");
         Self { path: dir.join(".stamp"), stamp: String::new() }
     }
 
@@ -52,7 +55,7 @@ impl BuildStamp {
             "prefix can not start or end with '.'"
         );
 
-        let stamp_filename = self.path.components().last().unwrap().as_os_str().to_str().unwrap();
+        let stamp_filename = self.path.file_name().unwrap().to_str().unwrap();
         let stamp_filename = stamp_filename.strip_prefix('.').unwrap_or(stamp_filename);
         self.path.set_file_name(format!(".{prefix}-{stamp_filename}"));