Explorar el Código

When getting all ZFS dataset mount points, deduplicate and filter out "none".

Dan Helfman hace 3 meses
padre
commit
bcc463688a
Se han modificado 4 ficheros con 33 adiciones y 5 borrados
  1. 3 0
      NEWS
  2. 11 2
      borgmatic/hooks/data_source/zfs.py
  3. 1 1
      pyproject.toml
  4. 18 2
      tests/unit/hooks/data_source/test_zfs.py

+ 3 - 0
NEWS

@@ -1,3 +1,6 @@
+1.9.13.dev0
+ * 
+
 1.9.12
  * #1005: Fix the credential hooks to avoid using Python 3.12+ string features. Now borgmatic will
    work with Python 3.9, 3.10, and 3.11 again.

+ 11 - 2
borgmatic/hooks/data_source/zfs.py

@@ -134,7 +134,16 @@ def get_all_dataset_mount_points(zfs_command):
         )
     )
 
-    return tuple(sorted(line.rstrip() for line in list_output.splitlines()))
+    return tuple(
+        sorted(
+            {
+                mount_point
+                for line in list_output.splitlines()
+                for mount_point in (line.rstrip(),)
+                if mount_point != 'none'
+            }
+        )
+    )
 
 
 def snapshot_dataset(zfs_command, full_snapshot_name):  # pragma: no cover
@@ -411,7 +420,7 @@ def remove_data_source_dumps(hook_config, config, borgmatic_runtime_directory, d
                     continue
 
         if not dry_run:
-            shutil.rmtree(snapshots_directory)
+            shutil.rmtree(snapshots_directory, ignore_errors=True)
 
     # Destroy snapshots.
     full_snapshot_names = get_all_snapshots(zfs_command)

+ 1 - 1
pyproject.toml

@@ -1,6 +1,6 @@
 [project]
 name = "borgmatic"
-version = "1.9.12"
+version = "1.9.13.dev0"
 authors = [
   { name="Dan Helfman", email="witten@torsion.org" },
 ]

+ 18 - 2
tests/unit/hooks/data_source/test_zfs.py

@@ -220,11 +220,27 @@ def test_get_datasets_to_backup_with_invalid_list_output_raises():
         module.get_datasets_to_backup('zfs', patterns=(Pattern('/foo'), Pattern('/bar')))
 
 
-def test_get_all_dataset_mount_points_does_not_filter_datasets():
+def test_get_all_dataset_mount_points_omits_none():
     flexmock(module.borgmatic.execute).should_receive(
         'execute_command_and_capture_output'
     ).and_return(
-        '/dataset\n/other',
+        '/dataset\nnone\n/other',
+    )
+    flexmock(module.borgmatic.hooks.data_source.snapshot).should_receive(
+        'get_contained_patterns'
+    ).and_return((Pattern('/dataset'),))
+
+    assert module.get_all_dataset_mount_points('zfs') == (
+        ('/dataset'),
+        ('/other'),
+    )
+
+
+def test_get_all_dataset_mount_points_omits_duplicates():
+    flexmock(module.borgmatic.execute).should_receive(
+        'execute_command_and_capture_output'
+    ).and_return(
+        '/dataset\n/other\n/dataset\n/other',
     )
     flexmock(module.borgmatic.hooks.data_source.snapshot).should_receive(
         'get_contained_patterns'