mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 04:17:10 +02:00
store the email file in the global config directory instead of the local data.ms so it's shared between all instances
This commit is contained in:
parent
204cf423b2
commit
765e76857f
2 changed files with 15 additions and 7 deletions
|
@ -45,7 +45,7 @@ macro_rules! empty_analytics {
|
||||||
/// `~/.config/Meilisearch` on *NIX or *BSD.
|
/// `~/.config/Meilisearch` on *NIX or *BSD.
|
||||||
/// `~/Library/ApplicationSupport` on macOS.
|
/// `~/Library/ApplicationSupport` on macOS.
|
||||||
/// `%APPDATA` (= `C:\Users%USERNAME%\AppData\Roaming`) on windows.
|
/// `%APPDATA` (= `C:\Users%USERNAME%\AppData\Roaming`) on windows.
|
||||||
static MEILISEARCH_CONFIG_PATH: Lazy<Option<PathBuf>> =
|
pub static MEILISEARCH_CONFIG_PATH: Lazy<Option<PathBuf>> =
|
||||||
Lazy::new(|| AppDirs::new(Some("Meilisearch"), false).map(|appdir| appdir.config_dir));
|
Lazy::new(|| AppDirs::new(Some("Meilisearch"), false).map(|appdir| appdir.config_dir));
|
||||||
|
|
||||||
fn config_user_id_path(db_path: &Path) -> Option<PathBuf> {
|
fn config_user_id_path(db_path: &Path) -> Option<PathBuf> {
|
||||||
|
|
|
@ -12,7 +12,7 @@ use actix_web::web::Data;
|
||||||
use actix_web::HttpServer;
|
use actix_web::HttpServer;
|
||||||
use index_scheduler::IndexScheduler;
|
use index_scheduler::IndexScheduler;
|
||||||
use is_terminal::IsTerminal;
|
use is_terminal::IsTerminal;
|
||||||
use meilisearch::analytics::Analytics;
|
use meilisearch::analytics::{Analytics, MEILISEARCH_CONFIG_PATH};
|
||||||
use meilisearch::option::LogMode;
|
use meilisearch::option::LogMode;
|
||||||
use meilisearch::search_queue::SearchQueue;
|
use meilisearch::search_queue::SearchQueue;
|
||||||
use meilisearch::{
|
use meilisearch::{
|
||||||
|
@ -132,12 +132,14 @@ async fn try_main() -> anyhow::Result<()> {
|
||||||
let (index_scheduler, auth_controller) = setup_meilisearch(&opt)?;
|
let (index_scheduler, auth_controller) = setup_meilisearch(&opt)?;
|
||||||
|
|
||||||
// We ask users their emails just after the data.ms is created
|
// We ask users their emails just after the data.ms is created
|
||||||
let skip_email_path = opt.db_path.join(SKIP_EMAIL_FILENAME);
|
let skip_email_path = MEILISEARCH_CONFIG_PATH.as_ref().map(|conf| conf.join(SKIP_EMAIL_FILENAME));
|
||||||
|
// If the config path does not exist, it means the user don't have a home directory
|
||||||
|
let skip_email = skip_email_path.as_ref().map_or(true, |path| path.exists());
|
||||||
opt.contact_email = match opt.contact_email.as_ref().map(|email| email.as_deref()) {
|
opt.contact_email = match opt.contact_email.as_ref().map(|email| email.as_deref()) {
|
||||||
Some(Some("false")) | None if !skip_email_path.exists() => {
|
Some(Some("false")) | None if !skip_email => {
|
||||||
prompt_for_contact_email().await.map(Some)?
|
prompt_for_contact_email().await.map(Some)?
|
||||||
}
|
}
|
||||||
Some(Some(email)) if !skip_email_path.exists() => Some(Some(email.to_string())),
|
Some(Some(email)) if !skip_email => Some(Some(email.to_string())),
|
||||||
_otherwise => None,
|
_otherwise => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -146,8 +148,14 @@ async fn try_main() -> anyhow::Result<()> {
|
||||||
// We spawn a task to register the email and create the skip email
|
// We spawn a task to register the email and create the skip email
|
||||||
// file to avoid blocking the Meilisearch launch further.
|
// file to avoid blocking the Meilisearch launch further.
|
||||||
let _ = tokio::spawn(async move {
|
let _ = tokio::spawn(async move {
|
||||||
if let Err(e) = tokio::fs::File::create_new(skip_email_path).await {
|
if let Some(skip_email_path) = skip_email_path {
|
||||||
eprintln!("Failed to create skip email file: {e}");
|
// If the analytics are disabled the directory might not exist at all
|
||||||
|
if let Err(e) = tokio::fs::create_dir_all(skip_email_path.parent().unwrap()).await {
|
||||||
|
eprintln!("Failed to create skip email file: {e}");
|
||||||
|
}
|
||||||
|
if let Err(e) = tokio::fs::File::create_new(skip_email_path).await {
|
||||||
|
eprintln!("Failed to create skip email file: {e}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Err(err) = register_contact_email(&email).await {
|
if let Err(err) = register_contact_email(&email).await {
|
||||||
eprintln!("Failed to register email: {}", err);
|
eprintln!("Failed to register email: {}", err);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue