Skip to content

Commit bdb7518

Browse files
committed
apply minor improvements on build_stamp
Signed-off-by: onur-ozkan <[email protected]>
1 parent 3751652 commit bdb7518

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/bootstrap/src/utils/build_stamp.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ impl BuildStamp {
3434
///
3535
/// By default, stamp will be an empty file named `.stamp` within the specified directory.
3636
pub fn new(dir: &Path) -> Self {
37+
// Avoid using `is_dir()` as the directory may not exist yet.
38+
// It is more appropriate to assert that the path is not a file.
39+
assert!(!dir.is_file(), "can't be a file path");
3740
Self { path: dir.join(".stamp"), stamp: String::new() }
3841
}
3942

@@ -52,7 +55,7 @@ impl BuildStamp {
5255
"prefix can not start or end with '.'"
5356
);
5457

55-
let stamp_filename = self.path.components().last().unwrap().as_os_str().to_str().unwrap();
58+
let stamp_filename = self.path.file_name().unwrap().to_str().unwrap();
5659
let stamp_filename = stamp_filename.strip_prefix('.').unwrap_or(stamp_filename);
5760
self.path.set_file_name(format!(".{prefix}-{stamp_filename}"));
5861

0 commit comments

Comments
 (0)