Skip to content

Commit

Permalink
import_file test failing on macos #564
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Jul 31, 2023
1 parent be70104 commit 740ab5c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
16 changes: 11 additions & 5 deletions server/src/appstate.rs
Expand Up @@ -7,7 +7,7 @@ use atomic_lib::{
atomic_url::Routes,
commit::CommitResponse,
email::SmtpConfig,
Storelike,
Db, Storelike,
};

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

/// Initializes the Store and sets the default agent.
pub fn init_store(config: &Config) -> AtomicServerResult<Db> {
let store = atomic_lib::Db::init(&config.store_path, &config.server_url)?;

tracing::info!("Setting default agent");
set_default_agent(config, &store)?;
Ok(store)
}

/// Creates the AppState (the server's context available in Handlers).
/// Initializes or opens a store on disk.
/// Creates a new agent, if necessary.
Expand All @@ -43,7 +52,7 @@ pub async fn init(config: Config) -> AtomicServerResult<AppState> {
}

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

if let Some(host) = &config.opts.smpt_host {
store
Expand All @@ -61,9 +70,6 @@ pub async fn init(config: Config) -> AtomicServerResult<AppState> {
.map_err(|e| format!("Failed to populate default store. {}", e))?;
}

tracing::info!("Setting default agent");
set_default_agent(&config, &store)?;

// Initialize search constructs
tracing::info!("Starting search service");
let search_state =
Expand Down
13 changes: 6 additions & 7 deletions server/src/bin.rs
Expand Up @@ -50,8 +50,8 @@ async fn main_wrapped() -> errors::AtomicServerResult<()> {
pt
}
};
let appstate = appstate::init(config.clone()).await?;
let outstr = appstate.store.export(!e.only_internal)?;
let store = appstate::init_store(&config)?;
let outstr = store.export(!e.only_internal)?;
std::fs::create_dir_all(path.parent().unwrap())
.map_err(|e| format!("Failed to create directory {:?}. {}", path, e))?;
let mut file = File::create(&path)
Expand All @@ -66,12 +66,11 @@ async fn main_wrapped() -> errors::AtomicServerResult<()> {
std::fs::read_to_string(path)?
};

let appstate = appstate::init(config.clone()).await?;
let store = appstate::init_store(&config)?;
let importer_subject = if let Some(i) = &import_opts.parent {
i.into()
} else {
appstate
.store
store
.get_self_url()
.expect("No self URL")
.set_route(Routes::Import)
Expand All @@ -86,10 +85,10 @@ async fn main_wrapped() -> errors::AtomicServerResult<()> {
} else {
atomic_lib::parse::SaveOpts::Commit
},
signer: Some(appstate.store.get_default_agent()?),
signer: Some(store.get_default_agent()?),
};
println!("Importing...");
appstate.store.import(&readstring, &parse_opts)?;
store.import(&readstring, &parse_opts)?;

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

0 comments on commit 740ab5c

Please sign in to comment.