Bring back hash_alias_key

This commit is contained in:
asonix 2023-07-25 20:30:22 -05:00
parent c30c01f0bb
commit 2a59a6492a
2 changed files with 11 additions and 4 deletions

View file

@ -591,7 +591,7 @@ async fn do_download_backgrounded<R: FullRepo + 'static, S: Store + 'static>(
} }
/// Delete aliases and files /// Delete aliases and files
#[tracing::instrument(name = "Deleting file", skip(repo))] #[tracing::instrument(name = "Deleting file", skip(repo, config))]
async fn delete<R: FullRepo>( async fn delete<R: FullRepo>(
repo: web::Data<R>, repo: web::Data<R>,
config: web::Data<Configuration>, config: web::Data<Configuration>,

View file

@ -1182,6 +1182,12 @@ impl HashRepo for SledRepo {
} }
} }
fn hash_alias_key(hash: &IVec, alias: &IVec) -> Vec<u8> {
let mut v = hash.to_vec();
v.extend_from_slice(&alias);
v
}
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl AliasRepo for SledRepo { impl AliasRepo for SledRepo {
#[tracing::instrument(level = "trace", skip(self))] #[tracing::instrument(level = "trace", skip(self))]
@ -1208,7 +1214,8 @@ impl AliasRepo for SledRepo {
aliases.insert(&alias, &alias)?; aliases.insert(&alias, &alias)?;
alias_hashes.insert(&alias, &hash)?; alias_hashes.insert(&alias, &hash)?;
hash_aliases.insert(&hash, &alias)?;
hash_aliases.insert(hash_alias_key(&hash, &alias), &alias)?;
alias_delete_tokens.insert(&alias, &delete_token)?; alias_delete_tokens.insert(&alias, &delete_token)?;
Ok(Ok(())) Ok(Ok(()))
@ -1266,7 +1273,7 @@ impl AliasRepo for SledRepo {
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
async fn cleanup(&self, alias: &Alias) -> Result<(), RepoError> { async fn cleanup(&self, alias: &Alias) -> Result<(), RepoError> {
let alias: sled::IVec = alias.to_bytes().into(); let alias: IVec = alias.to_bytes().into();
let aliases = self.aliases.clone(); let aliases = self.aliases.clone();
let alias_hashes = self.alias_hashes.clone(); let alias_hashes = self.alias_hashes.clone();
@ -1278,7 +1285,7 @@ impl AliasRepo for SledRepo {
|(aliases, alias_hashes, hash_aliases, alias_delete_tokens)| { |(aliases, alias_hashes, hash_aliases, alias_delete_tokens)| {
aliases.remove(&alias)?; aliases.remove(&alias)?;
if let Some(hash) = alias_hashes.remove(&alias)? { if let Some(hash) = alias_hashes.remove(&alias)? {
hash_aliases.remove(hash)?; hash_aliases.remove(hash_alias_key(&hash, &alias))?;
} }
alias_delete_tokens.remove(&alias)?; alias_delete_tokens.remove(&alias)?;
Ok(()) Ok(())