mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
don't require a media scan after media deleted inside Anki
This commit is contained in:
parent
6828b98c99
commit
801c5fcc40
1 changed files with 24 additions and 2 deletions
|
@ -95,7 +95,12 @@ impl MediaManager {
|
||||||
where
|
where
|
||||||
S: AsRef<str> + std::fmt::Debug,
|
S: AsRef<str> + std::fmt::Debug,
|
||||||
{
|
{
|
||||||
|
let pre_remove_folder_mtime = mtime_as_i64(&self.media_folder)?;
|
||||||
|
|
||||||
remove_files(&self.media_folder, &filenames)?;
|
remove_files(&self.media_folder, &filenames)?;
|
||||||
|
|
||||||
|
let post_remove_folder_mtime = mtime_as_i64(&self.media_folder)?;
|
||||||
|
|
||||||
ctx.transact(|ctx| {
|
ctx.transact(|ctx| {
|
||||||
for fname in filenames {
|
for fname in filenames {
|
||||||
if let Some(mut entry) = ctx.get_entry(fname.as_ref())? {
|
if let Some(mut entry) = ctx.get_entry(fname.as_ref())? {
|
||||||
|
@ -106,16 +111,33 @@ impl MediaManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut meta = ctx.get_meta()?;
|
||||||
|
if meta.folder_mtime == pre_remove_folder_mtime {
|
||||||
|
// if media db was in sync with folder prior to this add,
|
||||||
|
// we can keep it in sync
|
||||||
|
meta.folder_mtime = post_remove_folder_mtime;
|
||||||
|
ctx.set_meta(&meta)?;
|
||||||
|
} else {
|
||||||
|
// otherwise, leave it alone so that other pending changes
|
||||||
|
// get picked up later
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sync media.
|
/// Sync media.
|
||||||
pub async fn sync_media<F>(&self, progress: F, endpoint: &str, hkey: &str) -> Result<()>
|
pub async fn sync_media<'a, F>(
|
||||||
|
&'a self,
|
||||||
|
progress: F,
|
||||||
|
endpoint: &'a str,
|
||||||
|
hkey: &'a str,
|
||||||
|
log: Logger,
|
||||||
|
) -> Result<()>
|
||||||
where
|
where
|
||||||
F: Fn(&MediaSyncProgress) -> bool,
|
F: Fn(&MediaSyncProgress) -> bool,
|
||||||
{
|
{
|
||||||
let mut syncer = MediaSyncer::new(self, progress, endpoint);
|
let mut syncer = MediaSyncer::new(self, progress, endpoint, log);
|
||||||
syncer.sync(hkey).await
|
syncer.sync(hkey).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue