diff options
-rw-r--r-- | modules/zfssnap/zfssnap.py | 40 |
1 files changed, 3 insertions, 37 deletions
diff --git a/modules/zfssnap/zfssnap.py b/modules/zfssnap/zfssnap.py index 6d9bc6de..7055f308 100644 --- a/modules/zfssnap/zfssnap.py +++ b/modules/zfssnap/zfssnap.py | |||
@@ -25,8 +25,6 @@ from functools import cache | |||
25 | 25 | ||
26 | from math import floor | 26 | from math import floor |
27 | 27 | ||
28 | import asyncio | ||
29 | |||
30 | 28 | ||
31 | @cache | 29 | @cache |
32 | def _now(): | 30 | def _now(): |
@@ -214,31 +212,6 @@ def rename(snapshots, destroy=False, set_is_auto=False): | |||
214 | def autosnap(): | 212 | def autosnap(): |
215 | items = _get_items() | 213 | items = _get_items() |
216 | 214 | ||
217 | recursive, single = set(), set() | ||
218 | |||
219 | for item_name, is_included in items.items(): | ||
220 | if not is_included: | ||
221 | continue | ||
222 | |||
223 | children = {sub_name for sub_name in items if sub_name.startswith(f'{item_name}/')} | ||
224 | is_recursive = all([items[sub_name] for sub_name in children]) | ||
225 | if is_recursive and children: | ||
226 | recursive.add(item_name) | ||
227 | else: | ||
228 | single.add(item_name) | ||
229 | |||
230 | for item_name in recursive | single: | ||
231 | is_covered = any([item_name.startswith(f'{super_name}/') for super_name in recursive]) | ||
232 | if is_covered: | ||
233 | try: | ||
234 | recursive.remove(item_name) | ||
235 | except KeyError: | ||
236 | pass | ||
237 | try: | ||
238 | single.remove(item_name) | ||
239 | except KeyError: | ||
240 | pass | ||
241 | |||
242 | all_snap_names = set() | 215 | all_snap_names = set() |
243 | async def do_snapshot(*snap_items, recursive=False): | 216 | async def do_snapshot(*snap_items, recursive=False): |
244 | nonlocal items, all_snap_names | 217 | nonlocal items, all_snap_names |
@@ -257,17 +230,10 @@ def autosnap(): | |||
257 | _log_cmd(*args) | 230 | _log_cmd(*args) |
258 | subprocess.run(args, check=True) | 231 | subprocess.run(args, check=True) |
259 | 232 | ||
260 | tasks = [] | 233 | |
261 | if single: | 234 | do_snapshot(*items) |
262 | tasks.append(do_snapshot(*single)) | 235 | if not items: |
263 | if recursive: | ||
264 | tasks.append(do_snapshot(*recursive, recursive=True)) | ||
265 | if not tasks: | ||
266 | logger.warning('No snapshots to create') | 236 | logger.warning('No snapshots to create') |
267 | else: | ||
268 | async def run_tasks(): | ||
269 | await asyncio.gather(*tasks) | ||
270 | asyncio.run(run_tasks()) | ||
271 | for snap in all_snap_names: | 237 | for snap in all_snap_names: |
272 | logger.info(f'Created ‘{snap}’') | 238 | logger.info(f'Created ‘{snap}’') |
273 | if all_snap_names: | 239 | if all_snap_names: |