rename user-id to instance-uid

This commit is contained in:
Tamo 2021-10-26 13:57:41 +02:00 committed by marin postma
parent 6b34318274
commit 76a4f86e0c
No known key found for this signature in database
GPG Key ID: 6088B7721C3E39F9
3 changed files with 14 additions and 9 deletions

View File

@ -20,22 +20,27 @@ fn config_user_id_path(db_path: &Path) -> Option<PathBuf> {
db_path db_path
.canonicalize() .canonicalize()
.ok() .ok()
.map(|path| path.join("user-id").display().to_string().replace("/", "-")) .map(|path| {
path.join("instance-uid")
.display()
.to_string()
.replace("/", "-")
})
.zip(MEILISEARCH_CONFIG_PATH.as_ref()) .zip(MEILISEARCH_CONFIG_PATH.as_ref())
.map(|(filename, config_path)| config_path.join(filename)) .map(|(filename, config_path)| config_path.join(filename))
} }
/// Look for the user-id in the `data.ms` or in `~/.config/MeiliSearch/path-to-db-user-id` /// Look for the instance-uid in the `data.ms` or in `~/.config/MeiliSearch/path-to-db-instance-uid`
fn find_user_id(db_path: &Path) -> Option<String> { fn find_user_id(db_path: &Path) -> Option<String> {
fs::read_to_string(db_path.join("user-id")) fs::read_to_string(db_path.join("instance-uid"))
.ok() .ok()
.or_else(|| fs::read_to_string(&config_user_id_path(db_path)?).ok()) .or_else(|| fs::read_to_string(&config_user_id_path(db_path)?).ok())
} }
#[cfg(all(not(debug_assertions), feature = "analytics"))] #[cfg(all(not(debug_assertions), feature = "analytics"))]
/// Write the user-id in the `data.ms` and in `~/.config/MeiliSearch/path-to-db-user-id`. Ignore the errors. /// Write the instance-uid in the `data.ms` and in `~/.config/MeiliSearch/path-to-db-instance-uid`. Ignore the errors.
fn write_user_id(db_path: &Path, user_id: &str) { fn write_user_id(db_path: &Path, user_id: &str) {
let _ = fs::write(db_path.join("user-id"), user_id.as_bytes()); let _ = fs::write(db_path.join("instance-uid"), user_id.as_bytes());
if let Some((meilisearch_config_path, user_id_path)) = MEILISEARCH_CONFIG_PATH if let Some((meilisearch_config_path, user_id_path)) = MEILISEARCH_CONFIG_PATH
.as_ref() .as_ref()
.zip(config_user_id_path(db_path)) .zip(config_user_id_path(db_path))

View File

@ -1,8 +1,8 @@
use std::{fs, path::Path}; use std::{fs, path::Path};
/// Copy the `user-id` contained in one db to another. Ignore all errors. /// Copy the `instance-uid` contained in one db to another. Ignore all errors.
pub fn copy_user_id(src: &Path, dst: &Path) { pub fn copy_user_id(src: &Path, dst: &Path) {
if let Ok(user_id) = fs::read_to_string(src.join("user-id")) { if let Ok(user_id) = fs::read_to_string(src.join("instance-uid")) {
let _ = fs::write(dst.join("user-id"), &user_id); let _ = fs::write(dst.join("instance-uid"), &user_id);
} }
} }

View File

@ -169,7 +169,7 @@ impl IndexControllerBuilder {
let dump_path = self let dump_path = self
.dump_dst .dump_dst
.ok_or_else(|| anyhow::anyhow!("Missing dump directory path"))?; .ok_or_else(|| anyhow::anyhow!("Missing dump directory path"))?;
let analytics_path = db_path.as_ref().join("user-id"); let analytics_path = db_path.as_ref().join("instance-uid");
let dump_handle = dump_actor::DumpActorHandleImpl::new( let dump_handle = dump_actor::DumpActorHandleImpl::new(
dump_path, dump_path,
analytics_path, analytics_path,