Skip to content

Commit b2fa79d

Browse files
Oyami-Srkspacekookie
authored andcommitted
fix store function
1 parent e971242 commit b2fa79d

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

examples/simple.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ extern crate confy;
55
#[macro_use]
66
extern crate serde_derive;
77

8+
use std::io::Read;
9+
use confy::ConfyError;
10+
811
#[derive(Debug, Serialize, Deserialize)]
912
struct ConfyConfig {
1013
name: String,
@@ -28,5 +31,27 @@ fn main() -> Result<(), confy::ConfyError> {
2831
println!("The configuration file path is: {:#?}", file);
2932
println!("The configuration is:");
3033
println!("{:#?}", cfg);
34+
println!("The wrote toml file content is:");
35+
let mut content = String::new();
36+
std::fs::File::open(&file)
37+
.expect("Failed to read toml configuration file.")
38+
.read_to_string(&mut content);
39+
println!("{}", content);
40+
let cfg = ConfyConfig {
41+
name: "Test".to_string(),
42+
..cfg
43+
};
44+
confy::store("confy_simple_app",None, &cfg)?;
45+
println!("The updated toml file content is:");
46+
let mut content = String::new();
47+
std::fs::File::open(&file)
48+
.expect("Failed to read toml configuration file.")
49+
.read_to_string(&mut content);
50+
println!("{}", content);
51+
let cfg = ConfyConfig {
52+
name: "Test".to_string(),
53+
..cfg
54+
};
55+
std::fs::remove_dir_all(file.parent().unwrap());
3156
Ok(())
3257
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ pub fn store<'a, T: Serialize>(
266266
cfg: T,
267267
) -> Result<(), ConfyError> {
268268
let path = get_configuration_file_path(app_name, config_name)?;
269-
fs::create_dir_all(&path).map_err(ConfyError::DirectoryCreationFailed)?;
269+
fs::create_dir_all(&path.parent().unwrap()).map_err(ConfyError::DirectoryCreationFailed)?;
270270

271271
store_path(path, cfg)
272272
}

0 commit comments

Comments
 (0)