Clear have_bitfield on error
This commit is contained in:
parent
b7ed850918
commit
c697809e50
8 changed files with 88 additions and 32 deletions
|
|
@ -196,6 +196,14 @@ impl BitVFactory for JsonSessionPersistenceStore {
|
|||
Ok(Some(MmapBitV::new(f)?.into_dyn()))
|
||||
}
|
||||
|
||||
async fn clear(&self, id: TorrentIdOrHash) -> anyhow::Result<()> {
|
||||
let h = self.to_hash(id).await?;
|
||||
let filename = self.bitv_filename(&h);
|
||||
tokio::fs::remove_file(&filename)
|
||||
.await
|
||||
.with_context(|| format!("error removing {filename:?}"))
|
||||
}
|
||||
|
||||
async fn store_initial_check(
|
||||
&self,
|
||||
id: TorrentIdOrHash,
|
||||
|
|
|
|||
|
|
@ -313,4 +313,31 @@ impl BitVFactory for PostgresSessionStorage {
|
|||
bf.flush()?;
|
||||
Ok(bf.into_dyn())
|
||||
}
|
||||
|
||||
async fn clear(&self, id: TorrentIdOrHash) -> anyhow::Result<()> {
|
||||
macro_rules! exec {
|
||||
($q:expr, $v:expr) => {
|
||||
sqlx::query($q)
|
||||
.bind($v)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.context($q)
|
||||
.context("error executing query")?
|
||||
};
|
||||
}
|
||||
|
||||
match id {
|
||||
TorrentIdOrHash::Id(id) => {
|
||||
let id: i32 = id.try_into()?;
|
||||
exec!("UPDATE torrents SET have_bitfield = NULL WHERE id = $1", id);
|
||||
}
|
||||
TorrentIdOrHash::Hash(h) => {
|
||||
exec!(
|
||||
"UPDATE torrents SET have_bitfield = NULL WHERE info_hash = $1",
|
||||
&h.0[..]
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue