Skip to content

Commit aa0dd19

Browse files
committed
import_file test failing on macos #564
1 parent 06bf1ad commit aa0dd19

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

server/src/appstate.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use atomic_lib::{
77
atomic_url::Routes,
88
commit::CommitResponse,
99
email::SmtpConfig,
10-
Storelike,
10+
Db, Storelike,
1111
};
1212

1313
/// The AppState contains all the relevant Context for the server.
@@ -27,6 +27,15 @@ pub struct AppState {
2727
pub search_state: SearchState,
2828
}
2929

30+
/// Initializes the Store and sets the default agent.
31+
pub fn init_store(config: &Config) -> AtomicServerResult<Db> {
32+
let store = atomic_lib::Db::init(&config.store_path, &config.server_url)?;
33+
34+
tracing::info!("Setting default agent");
35+
set_default_agent(config, &store)?;
36+
Ok(store)
37+
}
38+
3039
/// Creates the AppState (the server's context available in Handlers).
3140
/// Initializes or opens a store on disk.
3241
/// Creates a new agent, if necessary.
@@ -43,7 +52,7 @@ pub async fn init(config: Config) -> AtomicServerResult<AppState> {
4352
}
4453

4554
tracing::info!("Opening database at {:?}", &config.store_path);
46-
let mut store = atomic_lib::Db::init(&config.store_path, &config.server_url)?;
55+
let mut store = init_store(&config)?;
4756

4857
if let Some(host) = &config.opts.smpt_host {
4958
store
@@ -64,9 +73,6 @@ pub async fn init(config: Config) -> AtomicServerResult<AppState> {
6473
tracing::info!("Building index finished!");
6574
}
6675

67-
tracing::info!("Setting default agent");
68-
set_default_agent(&config, &store)?;
69-
7076
// Initialize search constructs
7177
tracing::info!("Starting search service");
7278
let search_state =

server/src/bin.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ async fn main_wrapped() -> errors::AtomicServerResult<()> {
5050
pt
5151
}
5252
};
53-
let appstate = appstate::init(config.clone()).await?;
54-
let outstr = appstate.store.export(!e.only_internal)?;
53+
let store = appstate::init_store(&config)?;
54+
let outstr = store.export(!e.only_internal)?;
5555
std::fs::create_dir_all(path.parent().unwrap())
5656
.map_err(|e| format!("Failed to create directory {:?}. {}", path, e))?;
5757
let mut file = File::create(&path)
@@ -66,12 +66,11 @@ async fn main_wrapped() -> errors::AtomicServerResult<()> {
6666
std::fs::read_to_string(path)?
6767
};
6868

69-
let appstate = appstate::init(config.clone()).await?;
69+
let store = appstate::init_store(&config)?;
7070
let importer_subject = if let Some(i) = &import_opts.parent {
7171
i.into()
7272
} else {
73-
appstate
74-
.store
73+
store
7574
.get_self_url()
7675
.expect("No self URL")
7776
.set_route(Routes::Import)
@@ -86,10 +85,10 @@ async fn main_wrapped() -> errors::AtomicServerResult<()> {
8685
} else {
8786
atomic_lib::parse::SaveOpts::Commit
8887
},
89-
signer: Some(appstate.store.get_default_agent()?),
88+
signer: Some(store.get_default_agent()?),
9089
};
9190
println!("Importing...");
92-
appstate.store.import(&readstring, &parse_opts)?;
91+
store.import(&readstring, &parse_opts)?;
9392

9493
println!("Sucesfully imported {:?} to store.", import_opts.file);
9594
Ok(())

0 commit comments

Comments
 (0)