Skip to content

Commit

Permalink
chore(sqlx-postgres): replace dirs with home & etcetera (#2485)
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarshgupta137 authored May 4, 2023
1 parent 200e17b commit 0038786
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 28 deletions.
114 changes: 90 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion sqlx-mysql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ bitflags = { version = "1.3.2", default-features = false }
byteorder = { version = "1.4.3", default-features = false, features = ["std"] }
bytes = "1.1.0"
dotenvy = "0.15.5"
dirs = "4.0.0"
either = "1.6.1"
generic-array = { version = "0.14.4", default-features = false }
hex = "0.4.3"
Expand Down
5 changes: 4 additions & 1 deletion sqlx-postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"
10 changes: 8 additions & 2 deletions sqlx-postgres/src/options/pgpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 0038786

Please sign in to comment.