chore(sqlx-postgres): replace dirs with home & etcetera (#2485)

This commit is contained in:
Utkarsh Gupta
2023-05-05 01:42:54 +05:30
committed by GitHub
parent 200e17bb04
commit 003878698e
4 changed files with 102 additions and 28 deletions

View File

@@ -50,9 +50,9 @@ atoi = "2.0"
base64 = { version = "0.21.0", default-features = false, features = ["std"] }
bitflags = { version = "1.3.2", default-features = false }
byteorder = { version = "1.4.3", default-features = false, features = ["std"] }
dirs = "4.0.0"
dotenvy = { workspace = true }
hex = "0.4.3"
home = "0.5.5"
itoa = "1.0.1"
log = "0.4.17"
memchr = { version = "2.4.1", default-features = false }
@@ -71,3 +71,6 @@ serde_json = { version = "1.0.85", features = ["raw_value"] }
workspace = true
# We use JSON in the driver implementation itself so there's no reason not to enable it here.
features = ["json"]
[target.'cfg(target_os = "windows")'.dependencies]
etcetera = "0.8.0"

View File

@@ -21,9 +21,15 @@ pub fn load_password(
}
#[cfg(not(target_os = "windows"))]
let default_file = dirs::home_dir().map(|path| path.join(".pgpass"));
let default_file = home::home_dir().map(|path| path.join(".pgpass"));
#[cfg(target_os = "windows")]
let default_file = dirs::data_dir().map(|path| path.join("postgres").join("pgpass.conf"));
let default_file = {
use etcetera::BaseStrategy;
etcetera::base_strategy::Windows::new()
.ok()
.map(|basedirs| basedirs.data_dir().join("postgres").join("pgpass.conf"))
};
load_password_from_file(default_file?, host, port, username, database)
}