Skip to content
This repository was archived by the owner on Oct 23, 2022. It is now read-only.

Commit 328d2ab

Browse files
committed
refactor(http): flush write buffer for config file
1 parent 57226e1 commit 328d2ab

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

http/src/config.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ pub fn init(
6363
) -> Result<String, InitializationError> {
6464
use multibase::Base::Base64Pad;
6565
use prost::Message;
66-
use std::io::BufWriter;
66+
use std::fs::OpenOptions;
67+
use std::io::{BufWriter, Write};
6768

6869
if profiles.len() != 1 {
6970
unimplemented!("Multiple profiles are currently unsupported!")
@@ -135,12 +136,20 @@ pub fn init(
135136
let config_file = fs::create_dir_all(&ipfs_path)
136137
.map_err(InitializationError::DirectoryCreationFailed)
137138
.and_then(|_| {
138-
fs::File::create(&config_path).map_err(InitializationError::ConfigCreationFailed)
139+
OpenOptions::new()
140+
.write(true)
141+
.create_new(true)
142+
.open(&config_path)
143+
.map_err(InitializationError::ConfigCreationFailed)
139144
})?;
140145

141-
serde_json::to_writer_pretty(BufWriter::new(config_file), &config_contents)
146+
let mut writer = BufWriter::new(config_file);
147+
148+
serde_json::to_writer_pretty(&mut writer, &config_contents)
142149
.map_err(InitializationError::ConfigWritingFailed)?;
143150

151+
writer.flush().unwrap();
152+
144153
Ok(peer_id)
145154
}
146155

0 commit comments

Comments
 (0)