persist torrent bytes to file on the last step

This commit is contained in:
yggverse 2025-08-08 03:11:53 +03:00
parent 52a4ff2d44
commit 553bffb4f0

View file

@ -41,10 +41,6 @@ impl Preload {
persist_files: Option<HashSet<PathBuf>>, persist_files: Option<HashSet<PathBuf>>,
) -> Result<()> { ) -> Result<()> {
validate_info_hash(info_hash)?; validate_info_hash(info_hash)?;
// persist torrent bytes to file
let t = self.torrent(info_hash);
fs::write(&t, torrent_bytes)?;
log::debug!("persist torrent bytes for `{}`", t.to_string_lossy());
// persist preload files // persist preload files
let mut d = PathBuf::from(&self.root); let mut d = PathBuf::from(&self.root);
d.push(info_hash); d.push(info_hash);
@ -90,6 +86,10 @@ impl Preload {
fs::remove_dir_all(&tmp)?; fs::remove_dir_all(&tmp)?;
log::debug!("clean tmp data `{}`", tmp.to_string_lossy()) log::debug!("clean tmp data `{}`", tmp.to_string_lossy())
} }
// persist torrent bytes to file (on previous operations success)
let t = self.torrent(info_hash);
fs::write(&t, torrent_bytes)?;
log::debug!("persist torrent bytes for `{}`", t.to_string_lossy());
Ok(()) Ok(())
} }