diff --git a/src/backup/chunk_store.rs b/src/backup/chunk_store.rs index 4be684e83..03c431981 100644 --- a/src/backup/chunk_store.rs +++ b/src/backup/chunk_store.rs @@ -271,6 +271,9 @@ impl ChunkStore { min_atime -= 300; // add 5 mins gap for safety for entry in self.get_chunk_iterator(true)? { + + tools::fail_on_shutdown()?; + let (dirfd, entry) = match entry { Ok(entry) => (entry.parent_fd(), entry), Err(_) => continue, // ignore errors diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index cfd7c36af..994cea878 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -209,6 +209,9 @@ impl DataStore { let image_list = self.list_images()?; for path in image_list { + + tools::fail_on_shutdown()?; + if let Some(ext) = path.extension() { if ext == "fidx" { let index = self.open_fixed_reader(&path)?; diff --git a/src/backup/dynamic_index.rs b/src/backup/dynamic_index.rs index 2087b58c0..7bd26f9f8 100644 --- a/src/backup/dynamic_index.rs +++ b/src/backup/dynamic_index.rs @@ -149,6 +149,9 @@ impl DynamicIndexReader { pub fn mark_used_chunks(&self, _status: &mut GarbageCollectionStatus) -> Result<(), Error> { for pos in 0..self.index_entries { + + tools::fail_on_shutdown()?; + let digest = self.chunk_digest(pos); if let Err(err) = self.store.touch_chunk(digest) { bail!("unable to access chunk {}, required by {:?} - {}", diff --git a/src/backup/fixed_index.rs b/src/backup/fixed_index.rs index fc7d0a3ff..7d0cf0928 100644 --- a/src/backup/fixed_index.rs +++ b/src/backup/fixed_index.rs @@ -147,6 +147,8 @@ impl FixedIndexReader { for pos in 0..index_count { + tools::fail_on_shutdown()?; + let digest = self.index_digest(pos).unwrap(); if let Err(err) = self.store.touch_chunk(digest) { bail!("unable to access chunk {}, required by {:?} - {}", diff --git a/src/tools.rs b/src/tools.rs index 52640f731..156ba1f71 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -557,3 +557,10 @@ pub fn request_shutdown() { pub fn shutdown_requested() -> bool { unsafe { SHUTDOWN_REQUESTED } } + +pub fn fail_on_shutdown() -> Result<(), Error> { + if shutdown_requested() { + bail!("Server shutdown requested - aborting task"); + } + Ok(()) +}