Skip to content

Commit ed8fe5e

Browse files
Merge branch 'trunk' into Issue_12549_FixAtomsGenerationLowdash
2 parents ab3f6d3 + 9af3d6e commit ed8fe5e

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ test --test_env=JRUBY_OPTS="--dev"
105105

106106
test:windows --test_env=PATH
107107
test:windows --test_env=LOCALAPPDATA
108+
test:windows --test_env=PROCESSOR_ARCHITECTURE
108109
test:windows --test_env=PROGRAMFILES="C:\\Program Files"
109110
test:windows --test_env=PROGRAMFILES(X86)="C:\\Program Files (x86)"
110111

rust/src/config.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
use crate::config::OS::{LINUX, MACOS, WINDOWS};
1919
use crate::shell::run_shell_command_by_os;
2020
use crate::{
21-
default_cache_folder, format_one_arg, path_to_string, Command, REQUEST_TIMEOUT_SEC,
22-
UNAME_COMMAND,
21+
default_cache_folder, format_one_arg, path_to_string, Command, ENV_PROCESSOR_ARCHITECTURE,
22+
REQUEST_TIMEOUT_SEC, UNAME_COMMAND,
2323
};
2424
use crate::{ARCH_AMD64, ARCH_ARM64, ARCH_X86, TTL_SEC, WMIC_COMMAND_OS};
2525
use anyhow::anyhow;
@@ -69,11 +69,14 @@ impl ManagerConfig {
6969

7070
let self_os = OS;
7171
let self_arch = if WINDOWS.is(self_os) {
72-
let wmic_command = Command::new_single(WMIC_COMMAND_OS.to_string());
73-
let wmic_output = run_shell_command_by_os(self_os, wmic_command).unwrap_or_default();
74-
if wmic_output.contains("32") {
72+
let mut architecture = env::var(ENV_PROCESSOR_ARCHITECTURE).unwrap_or_default();
73+
if architecture.is_empty() {
74+
let get_os_command = Command::new_single(WMIC_COMMAND_OS.to_string());
75+
architecture = run_shell_command_by_os(self_os, get_os_command).unwrap_or_default();
76+
}
77+
if architecture.contains("32") {
7578
ARCH_X86.to_string()
76-
} else if wmic_output.contains("ARM") {
79+
} else if architecture.contains("ARM") {
7780
ARCH_ARM64.to_string()
7881
} else {
7982
ARCH_AMD64.to_string()

rust/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ pub const SINGLE_QUOTE: &str = "'";
9494
pub const ENV_PROGRAM_FILES: &str = "PROGRAMFILES";
9595
pub const ENV_PROGRAM_FILES_X86: &str = "PROGRAMFILES(X86)";
9696
pub const ENV_LOCALAPPDATA: &str = "LOCALAPPDATA";
97+
pub const ENV_PROCESSOR_ARCHITECTURE: &str = "PROCESSOR_ARCHITECTURE";
9798
pub const ENV_X86: &str = " (x86)";
9899
pub const ARCH_X86: &str = "x86";
99100
pub const ARCH_AMD64: &str = "amd64";
100101
pub const ARCH_ARM64: &str = "arm64";
101-
pub const ENV_PROCESSOR_ARCHITECTURE: &str = "PROCESSOR_ARCHITECTURE";
102102
pub const TTL_SEC: u64 = 3600;
103103
pub const UNAME_COMMAND: &str = "uname -{}";
104104
pub const ESCAPE_COMMAND: &str = r#"printf %q "{}""#;

rust/src/lock.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,15 @@ impl Lock {
5353

5454
log.debug(format!("Acquiring lock: {}", path.display()));
5555
file.lock_exclusive().unwrap_or_default();
56-
57-
LOCK_PATH.with(|option| {
58-
*option.borrow_mut() = Some(lock_folder.to_path_buf());
59-
});
56+
set_lock_path(Some(path.to_path_buf()));
6057

6158
Ok(Self { file, path })
6259
}
6360

6461
pub fn release(&mut self) {
6562
fs::remove_file(&self.path).unwrap_or_default();
6663
self.file.unlock().unwrap_or_default();
67-
68-
LOCK_PATH.with(|option| {
69-
*option.borrow_mut() = None;
70-
});
64+
set_lock_path(None);
7165
}
7266

7367
pub fn exists(&mut self) -> bool {
@@ -76,14 +70,21 @@ impl Lock {
7670
}
7771

7872
pub fn clear_lock_if_required() {
79-
let mut lock_path: Option<PathBuf> = None;
80-
LOCK_PATH.with(|option| {
81-
let optional_path = &*option.borrow();
82-
if optional_path.is_some() {
83-
lock_path = Some(optional_path.as_ref().unwrap().to_path_buf());
84-
}
85-
});
73+
let lock_path = get_lock_path();
8674
if lock_path.is_some() {
87-
fs::remove_dir_all(lock_path.unwrap()).unwrap_or_default();
75+
let lock = lock_path.unwrap();
76+
if lock.exists() {
77+
fs::remove_dir_all(lock.parent().unwrap()).unwrap_or_default();
78+
}
8879
}
8980
}
81+
82+
fn set_lock_path(path: Option<PathBuf>) {
83+
LOCK_PATH.with(|lock_path| {
84+
*lock_path.borrow_mut() = path;
85+
});
86+
}
87+
88+
fn get_lock_path() -> Option<PathBuf> {
89+
LOCK_PATH.with(|lock_path| lock_path.borrow().clone())
90+
}

0 commit comments

Comments
 (0)