Skip to content

Commit 44e602c

Browse files
committed
uds: precreate netrc file directory
1 parent 1780425 commit 44e602c

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/cli/cmd/login/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -198,23 +198,21 @@ impl LoginSubcommand {
198198
.header("Content-Type", "application/json")
199199
.body(Body::from(add_req_json))?;
200200
let response = uds.send_request(request).await?;
201-
201+
202202
if response.status() != StatusCode::OK {
203203
let body = response.into_body();
204204
let bytes = body.collect().await.unwrap_or_default().to_bytes();
205205
let text: String = String::from_utf8_lossy(&bytes).into();
206-
207-
tracing::warn!(
208-
"failed to update netrc via determinatenixd, falling back to local-file approach: {}", &text
209-
);
206+
207+
tracing::warn!("failed to update netrc via determinate-nixd: {}", &text);
210208
}
211209

212210
token_updated = true;
213211
}
214212

215213
if !token_updated {
216214
tracing::warn!(
217-
"failed to update netrc via determinatenixd, falling back to local-file approach"
215+
"failed to update netrc via determinate-nixd, falling back to local-file approach"
218216
);
219217

220218
// check if user is root or not
@@ -224,7 +222,7 @@ impl LoginSubcommand {
224222

225223
update_netrc_file(&netrc_file_path, &netrc_contents).await?;
226224

227-
// only update user_nix_config if we could not use determinatenixd
225+
// only update user_nix_config if we could not use determinate-nixd
228226
upsert_user_nix_config(
229227
&nix_config_path,
230228
&netrc_file_string,

src/shared/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::path::Path;
22

3-
use color_eyre::eyre::Context as _;
3+
use color_eyre::eyre::{eyre, Context as _};
44
use serde::{Deserialize, Serialize};
55

66
#[derive(Deserialize, Serialize)]
@@ -18,6 +18,12 @@ pub async fn update_netrc_file(
1818
netrc_file_path: &Path,
1919
netrc_contents: &str,
2020
) -> color_eyre::Result<()> {
21+
let parent = netrc_file_path
22+
.parent()
23+
.ok_or(eyre!("failed to determinte netrc parent directory"))?;
24+
25+
std::fs::create_dir_all(&parent).wrap_err("failed to ensure directory existed: {}")?;
26+
2127
tokio::fs::write(netrc_file_path, &netrc_contents)
2228
.await
2329
.wrap_err("failed to update netrc file contents")

0 commit comments

Comments
 (0)