Extract the connector loading part of open_pile
This commit is contained in:
parent
eb9d65b918
commit
ecda1e5359
@ -93,6 +93,32 @@ pub async fn open_pile(
|
|||||||
bail!("Neither yama.cfg nor yama.toml exists; doesn't look like a Yama pile or pile connector.");
|
bail!("Neither yama.cfg nor yama.toml exists; doesn't look like a Yama pile or pile connector.");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Calculate a prefix for the cache name
|
||||||
|
let canon_connector_in_dir = connector_in_dir
|
||||||
|
.canonicalize()
|
||||||
|
.unwrap_or(connector_in_dir.to_owned());
|
||||||
|
let cache_base_name = canon_connector_in_dir
|
||||||
|
.file_name()
|
||||||
|
.map(|f| f.to_string_lossy())
|
||||||
|
.unwrap_or(Cow::Borrowed("_"));
|
||||||
|
|
||||||
|
open_pile_using_connector(
|
||||||
|
&connection_scheme,
|
||||||
|
cache_base_name.as_ref(),
|
||||||
|
keyring,
|
||||||
|
lock_kind,
|
||||||
|
lock_holder,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn open_pile_using_connector(
|
||||||
|
connection_scheme: &PileConnectionScheme,
|
||||||
|
cache_base_name: &str,
|
||||||
|
keyring: Keyring,
|
||||||
|
lock_kind: LockKind,
|
||||||
|
lock_holder: String,
|
||||||
|
) -> eyre::Result<PileWithCache<BoxedWormFileProvider>> {
|
||||||
let wormfileprovider = Arc::new(connection_scheme.connect_to_wormfileprovider().await?);
|
let wormfileprovider = Arc::new(connection_scheme.connect_to_wormfileprovider().await?);
|
||||||
let pile = Pile::open_manual(wormfileprovider, lock_kind, lock_holder, keyring).await?;
|
let pile = Pile::open_manual(wormfileprovider, lock_kind, lock_holder, keyring).await?;
|
||||||
|
|
||||||
@ -102,14 +128,7 @@ pub async fn open_pile(
|
|||||||
connection_scheme.hash(&mut hasher);
|
connection_scheme.hash(&mut hasher);
|
||||||
let u64_hash = hasher.finish();
|
let u64_hash = hasher.finish();
|
||||||
|
|
||||||
let canon_connector_in_dir = connector_in_dir
|
let cache_key = format!("{}-{:016x}.sqlite3", cache_base_name, u64_hash);
|
||||||
.canonicalize()
|
|
||||||
.unwrap_or(connector_in_dir.to_owned());
|
|
||||||
let base_name = canon_connector_in_dir
|
|
||||||
.file_name()
|
|
||||||
.map(|f| f.to_string_lossy())
|
|
||||||
.unwrap_or(Cow::Borrowed("_"));
|
|
||||||
let cache_key = format!("{}-{:016x}.sqlite3", base_name, u64_hash);
|
|
||||||
|
|
||||||
tokio::fs::create_dir_all(&cache_dir).await?;
|
tokio::fs::create_dir_all(&cache_dir).await?;
|
||||||
let cache_file = cache_dir.join(&cache_key);
|
let cache_file = cache_dir.join(&cache_key);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user