refactor: move inline cfg-gated platform imports to top-level use statements (#1564)

Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
This commit is contained in:
Pranav Agarkar
2026-05-12 20:11:07 -07:00
committed by GitHub
co-authored by Steven Enamakel
parent 18962eba6c
commit 59bbf67e4e
4 changed files with 11 additions and 5 deletions
+3 -2
View File
@@ -32,6 +32,9 @@ use std::io::Write as _;
use std::path::Path;
use std::sync::OnceLock;
#[cfg(unix)]
use std::os::unix::fs::{OpenOptionsExt as _, PermissionsExt as _};
use axum::http::{header, Method, StatusCode};
use axum::middleware::Next;
use axum::response::{IntoResponse, Response};
@@ -189,7 +192,6 @@ fn write_token_file(path: &Path, token: &str) -> anyhow::Result<()> {
#[cfg(unix)]
{
use std::os::unix::fs::OpenOptionsExt as _;
let mut file = std::fs::OpenOptions::new()
.write(true)
.create(true)
@@ -238,7 +240,6 @@ mod tests {
#[cfg(unix)]
#[test]
fn token_file_has_owner_only_permissions() {
use std::os::unix::fs::PermissionsExt as _;
let tmp = std::env::temp_dir().join(format!("core-auth-perms-{}", std::process::id()));
std::fs::create_dir_all(&tmp).unwrap();
let path = tmp.join("core.token");
+3 -1
View File
@@ -5,6 +5,9 @@ use std::fs;
use std::path::PathBuf;
use std::process::{Command, Stdio};
#[cfg(windows)]
use std::os::windows::process::CommandExt;
pub(crate) const SERVICE_LABEL: &str = "com.openhuman.core";
pub(crate) const LEGACY_SERVICE_LABEL: &str = "com.openhuman.daemon";
pub(crate) const LEGACY_APP_LABEL: &str = "com.openhuman.app";
@@ -107,7 +110,6 @@ pub(crate) fn xml_escape(input: &str) -> String {
/// console — visible to users (#1475 follow-up to #731 + #1338).
#[cfg(windows)]
fn no_window(cmd: &mut Command) {
use std::os::windows::process::CommandExt;
cmd.creation_flags(0x0800_0000); // CREATE_NO_WINDOW
}
+2 -1
View File
@@ -3,6 +3,8 @@
use crate::openhuman::config::Config;
use anyhow::Result;
use std::fs;
// File is `#[cfg(windows)]`-gated at the module level — no per-item guard needed.
use std::os::windows::process::CommandExt;
use std::path::PathBuf;
use std::process::Command;
@@ -131,7 +133,6 @@ pub(crate) fn uninstall(config: &Config) -> Result<ServiceStatus> {
}
fn is_task_exists_windows(task_name: &str) -> Result<bool> {
use std::os::windows::process::CommandExt;
let result = Command::new("schtasks")
.args(["/Query", "/TN", task_name])
.creation_flags(0x0800_0000) // CREATE_NO_WINDOW
+3 -1
View File
@@ -4,6 +4,9 @@
use std::io::Write;
use std::path::PathBuf;
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt as _;
use crate::openhuman::config::UpdateRestartStrategy;
use crate::openhuman::update::types::{GitHubAsset, GitHubRelease, UpdateApplyResult, UpdateInfo};
@@ -265,7 +268,6 @@ pub async fn download_and_stage_with_version(
// Set executable permission on Unix.
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
std::fs::set_permissions(&tmp_path, std::fs::Permissions::from_mode(0o755))
.map_err(|e| format!("failed to set executable permission: {e}"))?;
}