Skip to content

Commit ecc78cd

Browse files
committed
fix(platform): use cross-platform hostname helper for Windows builds
Replace direct nix::unistd::gethostname() calls with a platform helper that uses COMPUTERNAME env var on Windows and nix on Unix.
1 parent d0673d4 commit ecc78cd

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

‎crates/vger-core/src/commands/backup.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,9 +1732,7 @@ pub fn run_with_progress(
17321732
let time_end = Utc::now();
17331733

17341734
// Build snapshot metadata
1735-
let hostname = nix::unistd::gethostname()
1736-
.map(|h| h.to_string_lossy().to_string())
1737-
.unwrap_or_else(|_| "unknown".into());
1735+
let hostname = crate::platform::hostname();
17381736
let username = std::env::var("USER").unwrap_or_else(|_| "unknown".into());
17391737

17401738
let snapshot_meta = SnapshotMeta {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
pub mod fs;
22
pub mod shell;
3+
4+
/// Return the system hostname, or `"unknown"` if it cannot be determined.
5+
pub fn hostname() -> String {
6+
#[cfg(unix)]
7+
{
8+
nix::unistd::gethostname()
9+
.map(|h| h.to_string_lossy().to_string())
10+
.unwrap_or_else(|_| "unknown".into())
11+
}
12+
13+
#[cfg(windows)]
14+
{
15+
std::env::var("COMPUTERNAME").unwrap_or_else(|_| "unknown".into())
16+
}
17+
}

‎crates/vger-core/src/repo/lock.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ impl LockGuard {
3939

4040
/// Acquire an advisory lock on the repository.
4141
pub fn acquire_lock(storage: &dyn StorageBackend) -> Result<LockGuard> {
42-
let hostname = nix::unistd::gethostname()
43-
.map(|h| h.to_string_lossy().to_string())
44-
.unwrap_or_else(|_| "unknown".into());
42+
let hostname = crate::platform::hostname();
4543
let pid = std::process::id() as u64;
4644

4745
// Prefer backend-native lock APIs when available (e.g. REST server locks).

0 commit comments

Comments
 (0)