Skip to content

Commit bfb79dd

Browse files
committed
import_file test failing on macos #564
1 parent f6d0f1b commit bfb79dd

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.
@@ -42,7 +51,7 @@ pub async fn init(config: Config) -> AtomicServerResult<AppState> {
4251
}
4352

4453
tracing::info!("Opening database at {:?}", &config.store_path);
45-
let mut store = atomic_lib::Db::init(&config.store_path, &config.server_url)?;
54+
let mut store = init_store(&config)?;
4655

4756
if let Some(host) = &config.opts.smpt_host {
4857
store
@@ -60,9 +69,6 @@ pub async fn init(config: Config) -> AtomicServerResult<AppState> {
6069
.map_err(|e| format!("Failed to populate default store. {}", e))?;
6170
}
6271

63-
tracing::info!("Setting default agent");
64-
set_default_agent(&config, &store)?;
65-
6672
// Initialize search constructs
6773
tracing::info!("Starting search service");
6874
let search_state =

server/src/bin.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ async fn main_wrapped() -> errors::AtomicServerResult<()> {
4848
pt
4949
}
5050
};
51-
let appstate = appstate::init(config.clone()).await?;
52-
let outstr = appstate.store.export(!e.only_internal)?;
51+
let store = appstate::init_store(&config)?;
52+
let outstr = store.export(!e.only_internal)?;
5353
std::fs::create_dir_all(path.parent().unwrap())
5454
.map_err(|e| format!("Failed to create directory {:?}. {}", path, e))?;
5555
let mut file = File::create(&path)
@@ -64,12 +64,11 @@ async fn main_wrapped() -> errors::AtomicServerResult<()> {
6464
std::fs::read_to_string(path)?
6565
};
6666

67-
let appstate = appstate::init(config.clone()).await?;
67+
let store = appstate::init_store(&config)?;
6868
let importer_subject = if let Some(i) = &import_opts.parent {
6969
i.into()
7070
} else {
71-
appstate
72-
.store
71+
store
7372
.get_self_url()
7473
.expect("No self URL")
7574
.set_route(Routes::Import)
@@ -84,10 +83,10 @@ async fn main_wrapped() -> errors::AtomicServerResult<()> {
8483
} else {
8584
atomic_lib::parse::SaveOpts::Commit
8685
},
87-
signer: Some(appstate.store.get_default_agent()?),
86+
signer: Some(store.get_default_agent()?),
8887
};
8988
println!("Importing...");
90-
appstate.store.import(&readstring, &parse_opts)?;
89+
store.import(&readstring, &parse_opts)?;
9190

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

0 commit comments

Comments
 (0)