From 784e9ee24d977c99dcb5ba5aef81dae48cb899fb Mon Sep 17 00:00:00 2001 From: Roman Melnikov Date: Wed, 19 Apr 2023 17:46:43 +0800 Subject: [Chore] Handle 'temp_path' as an actual 'Path' instead of 'String' Problem: 'temp_path' and 'lock_path' are handled as 'String'. This can be a problem when the 'temp_path' directory is a symlink on the target system, e.g. this is the case with the default '/tmp' and macOS, where this directory is actually a symlink to '/private/tmp'. Solution: Handle 'temp_path' and 'lock_path' as actual Paths. Also, canonicalize 'temp_path' to avoid canary file path mismatches when checking filesystem events. As a side effect, also update the 'notify' dependency to the latest stable version. --- src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 738fa81..bf1a6dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,10 +12,12 @@ use thiserror::Error; use flexi_logger::*; -pub fn make_lock_path(temp_path: &str, closure: &str) -> String { +use std::path::{Path, PathBuf}; + +pub fn make_lock_path(temp_path: &Path, closure: &str) -> PathBuf { let lock_hash = &closure["/nix/store/".len()..closure.find('-').unwrap_or_else(|| closure.len())]; - format!("{}/deploy-rs-canary-{}", temp_path, lock_hash) + temp_path.join(format!("deploy-rs-canary-{}", lock_hash)) } const fn make_emoji(level: log::Level) -> &'static str { @@ -159,7 +161,7 @@ pub struct CmdOverrides { pub auto_rollback: Option, pub hostname: Option, pub magic_rollback: Option, - pub temp_path: Option, + pub temp_path: Option, pub confirm_timeout: Option, pub sudo: Option, pub dry_activate: bool, -- cgit v1.2.3