Skip to content

Commit e21ba02

Browse files
committed
Factor out default_path function
1 parent 91de113 commit e21ba02

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

sqlx-postgres/src/options/pgpass.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@ pub fn load_password(
2020
}
2121
}
2222

23-
#[cfg(not(target_os = "windows"))]
24-
let default_file = home::home_dir().map(|path| path.join(".pgpass"));
25-
#[cfg(target_os = "windows")]
26-
let default_file = {
27-
use etcetera::BaseStrategy;
28-
29-
etcetera::base_strategy::Windows::new()
30-
.ok()
31-
.map(|basedirs| basedirs.data_dir().join("postgres").join("pgpass.conf"))
32-
};
33-
load_password_from_file(&default_file?, host, port, username, database)
23+
load_password_from_file(&default_path()?, host, port, username, database)
24+
}
25+
26+
#[cfg(not(target_os = "windows"))]
27+
fn default_path() -> Option<PathBuf> {
28+
home::home_dir().map(|path| path.join(".pgpass"))
29+
}
30+
31+
#[cfg(target_os = "windows")]
32+
fn default_path() -> Option<PathBuf> {
33+
use etcetera::BaseStrategy;
34+
35+
etcetera::base_strategy::Windows::new()
36+
.ok()
37+
.map(|basedirs| basedirs.data_dir().join("postgres").join("pgpass.conf"))
3438
}
3539

3640
/// try to extract a password from a pgpass file

0 commit comments

Comments
 (0)