Skip to content

Commit 864cb92

Browse files
authored
fix(rust/driver_manager): modify SYSTEM path behavior on macOS (#3252)
Replicates the change in #3250 to the Rust Driver Manager. Follow-on to #3247 Modifies the behavior of GetSearchPaths so macOS doesn't follow other Unix-likes but instead uses the more conventional /Library/Application Support/ADBC. /etc/ isn't really a thing on macOS. Tested manually by debugging the test with and without `/Library/Application Support/ADBC` existing and verifying the right branch gets hit. I'm not too worried exercising this in CI but we could.
1 parent 5f301d3 commit 864cb92

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

rust/driver_manager/src/lib.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,23 @@ fn user_config_dir() -> Option<PathBuf> {
17531753
}
17541754
}
17551755

1756+
fn system_config_dir() -> Option<PathBuf> {
1757+
#[cfg(target_os = "macos")]
1758+
{
1759+
Some(PathBuf::from("/Library/Application Support/ADBC"))
1760+
}
1761+
1762+
#[cfg(all(unix, not(target_os = "macos")))]
1763+
{
1764+
Some(PathBuf::from("/etc/adbc"))
1765+
}
1766+
1767+
#[cfg(not(unix))]
1768+
{
1769+
None
1770+
}
1771+
}
1772+
17561773
fn get_search_paths(lvls: LoadFlags) -> Vec<PathBuf> {
17571774
let mut result = Vec::new();
17581775
if lvls & LOAD_FLAG_SEARCH_ENV != 0 {
@@ -1774,9 +1791,10 @@ fn get_search_paths(lvls: LoadFlags) -> Vec<PathBuf> {
17741791
// system level for windows is to search the registry keys
17751792
#[cfg(not(windows))]
17761793
if lvls & LOAD_FLAG_SEARCH_SYSTEM != 0 {
1777-
let system_config_dir = PathBuf::from("/etc/adbc");
1778-
if system_config_dir.exists() {
1779-
result.push(system_config_dir);
1794+
if let Some(path) = system_config_dir() {
1795+
if path.exists() {
1796+
result.push(path);
1797+
}
17801798
}
17811799
}
17821800

@@ -2184,7 +2202,11 @@ mod tests {
21842202
#[test]
21852203
#[cfg_attr(not(windows), ignore)]
21862204
fn test_get_search_paths() {
2205+
#[cfg(target_os = "macos")]
2206+
let system_path = PathBuf::from("/Library/Application Support/ADBC");
2207+
#[cfg(not(target_os = "macos"))]
21872208
let system_path = PathBuf::from("/etc/adbc");
2209+
21882210
let search_paths = get_search_paths(LOAD_FLAG_SEARCH_SYSTEM);
21892211
if system_path.exists() {
21902212
assert_eq!(search_paths, vec![system_path]);

0 commit comments

Comments
 (0)