Folders and files are now deleted more comprehensively

This commit is contained in:
Igor Katson 2024-06-21 13:18:30 +01:00
parent 7147f16042
commit ace4bed0c6
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
13 changed files with 253 additions and 103 deletions

View file

@ -14,7 +14,10 @@ use std::{
use parking_lot::Mutex;
use crate::storage::{StorageFactory, StorageFactoryExt, TorrentStorage};
use crate::{
storage::{StorageFactory, StorageFactoryExt, TorrentStorage},
ManagedTorrentInfo,
};
#[derive(Clone)]
pub struct SlowStorageFactory<U> {
@ -32,9 +35,9 @@ impl<U: StorageFactory> SlowStorageFactory<U> {
impl<U: StorageFactory + Clone> StorageFactory for SlowStorageFactory<U> {
type Storage = SlowStorage<U::Storage>;
fn init_storage(&self, info: &crate::ManagedTorrentInfo) -> anyhow::Result<Self::Storage> {
fn create(&self, info: &crate::ManagedTorrentInfo) -> anyhow::Result<Self::Storage> {
Ok(SlowStorage {
underlying: self.underlying_factory.init_storage(info)?,
underlying: self.underlying_factory.create(info)?,
pwrite_all_bufread: Mutex::new(Box::new(
BufReader::new(
File::open(
@ -108,4 +111,12 @@ impl<U: TorrentStorage> TorrentStorage for SlowStorage<U> {
fn take(&self) -> anyhow::Result<Box<dyn TorrentStorage>> {
anyhow::bail!("not implemented")
}
fn remove_directory_if_empty(&self, path: &std::path::Path) -> anyhow::Result<()> {
self.underlying.remove_directory_if_empty(path)
}
fn init(&mut self, meta: &ManagedTorrentInfo) -> anyhow::Result<()> {
self.underlying.init(meta)
}
}

View file

@ -2,7 +2,10 @@
A storage middleware that logs the time underlying storage operations took.
*/
use crate::storage::{StorageFactory, StorageFactoryExt, TorrentStorage};
use crate::{
storage::{StorageFactory, StorageFactoryExt, TorrentStorage},
ManagedTorrentInfo,
};
#[derive(Clone)]
pub struct TimingStorageFactory<U> {
@ -22,10 +25,10 @@ impl<U> TimingStorageFactory<U> {
impl<U: StorageFactory + Clone> StorageFactory for TimingStorageFactory<U> {
type Storage = TimingStorage<U::Storage>;
fn init_storage(&self, info: &crate::ManagedTorrentInfo) -> anyhow::Result<Self::Storage> {
fn create(&self, info: &crate::ManagedTorrentInfo) -> anyhow::Result<Self::Storage> {
Ok(TimingStorage {
name: self.name.clone(),
underlying: self.underlying_factory.init_storage(info)?,
underlying: self.underlying_factory.create(info)?,
})
}
@ -96,4 +99,12 @@ impl<U: TorrentStorage> TorrentStorage for TimingStorage<U> {
name: self.name.clone(),
}))
}
fn remove_directory_if_empty(&self, path: &std::path::Path) -> anyhow::Result<()> {
self.underlying.remove_directory_if_empty(path)
}
fn init(&mut self, meta: &ManagedTorrentInfo) -> anyhow::Result<()> {
self.underlying.init(meta)
}
}

View file

@ -14,7 +14,7 @@ use parking_lot::RwLock;
use crate::{
storage::{StorageFactory, StorageFactoryExt, TorrentStorage},
FileInfos,
FileInfos, ManagedTorrentInfo,
};
#[derive(Clone, Copy)]
@ -35,7 +35,7 @@ impl<U> WriteThroughCacheStorageFactory<U> {
impl<U: StorageFactory + Clone> StorageFactory for WriteThroughCacheStorageFactory<U> {
type Storage = WriteThroughCacheStorage<U::Storage>;
fn init_storage(&self, info: &crate::ManagedTorrentInfo) -> anyhow::Result<Self::Storage> {
fn create(&self, info: &crate::ManagedTorrentInfo) -> anyhow::Result<Self::Storage> {
let pieces = self
.max_cache_bytes
.div_ceil(info.lengths.default_piece_length() as u64)
@ -44,7 +44,7 @@ impl<U: StorageFactory + Clone> StorageFactory for WriteThroughCacheStorageFacto
let lru = RwLock::new(LruCache::new(pieces));
Ok(WriteThroughCacheStorage {
lru,
underlying: self.underlying.init_storage(info)?,
underlying: self.underlying.create(info)?,
lengths: info.lengths,
file_infos: info.file_infos.clone(),
})
@ -116,4 +116,12 @@ impl<U: TorrentStorage> TorrentStorage for WriteThroughCacheStorage<U> {
file_infos: self.file_infos.clone(),
}))
}
fn remove_directory_if_empty(&self, path: &std::path::Path) -> anyhow::Result<()> {
self.underlying.remove_directory_if_empty(path)
}
fn init(&mut self, meta: &ManagedTorrentInfo) -> anyhow::Result<()> {
self.underlying.init(meta)
}
}