Browse Source

change config_paths var name to used_config_paths to avoid collisions

Divyansh Singh 2 years ago
parent
commit
b10148844b
3 changed files with 30 additions and 13 deletions
  1. 22 6
      borgmatic/actions/create.py
  2. 3 1
      borgmatic/borg/create.py
  3. 5 6
      borgmatic/commands/borgmatic.py

+ 22 - 6
borgmatic/actions/create.py

@@ -2,6 +2,8 @@ import json
 import os
 import logging
 
+import importlib_metadata
+
 import borgmatic.borg.create
 import borgmatic.config.validate
 import borgmatic.hooks.command
@@ -17,19 +19,31 @@ def create_borgmatic_manifest(location, config_paths, dry_run):
     '''
     Create a borgmatic manifest file to store the paths to the configuration files used to create
     the archive.
-    '''    
+    '''
     if dry_run:
         return
-    
-    borgmatic_source_directory = location.get('borgmatic_source_directory') if location.get('borgmatic_source_directory') else DEFAULT_BORGMATIC_SOURCE_DIRECTORY
 
-    borgmatic_manifest_path = os.path.expanduser(os.path.join(borgmatic_source_directory, 'bootstrap', 'configs-list.json'))
+    borgmatic_source_directory = (
+        location.get('borgmatic_source_directory')
+        if location.get('borgmatic_source_directory')
+        else DEFAULT_BORGMATIC_SOURCE_DIRECTORY
+    )
+
+    borgmatic_manifest_path = os.path.expanduser(
+        os.path.join(borgmatic_source_directory, 'bootstrap', 'configs-list.json')
+    )
 
     if not os.path.exists(borgmatic_manifest_path):
         os.makedirs(os.path.dirname(borgmatic_manifest_path), exist_ok=True)
 
     with open(borgmatic_manifest_path, 'w') as f:
-        json.dump(config_paths, f)
+        json.dump(
+            {
+                'borgmatic_version': importlib_metadata.version('borgmatic'),
+                'config_paths': config_paths,
+            },
+            f,
+        )
 
 
 def run_create(
@@ -81,7 +95,9 @@ def run_create(
         location,
         global_arguments.dry_run,
     )
-    create_borgmatic_manifest(location, global_arguments.config_paths, global_arguments.dry_run)
+    create_borgmatic_manifest(
+        location, global_arguments.used_config_paths, global_arguments.dry_run
+    )
     stream_processes = [process for processes in active_dumps.values() for process in processes]
 
     json_output = borgmatic.borg.create.create_archive(

+ 3 - 1
borgmatic/borg/create.py

@@ -351,7 +351,9 @@ def create_archive(
     sources = deduplicate_directories(
         map_directories_to_devices(
             expand_directories(
-                tuple(location_config.get('source_directories', ())) + borgmatic_source_directories + tuple(global_arguments.config_paths)
+                tuple(location_config.get('source_directories', ()))
+                + borgmatic_source_directories
+                + tuple(global_arguments.used_config_paths)
             )
         ),
         additional_directory_devices=map_directories_to_devices(

+ 5 - 6
borgmatic/commands/borgmatic.py

@@ -45,10 +45,10 @@ logger = logging.getLogger(__name__)
 LEGACY_CONFIG_PATH = '/etc/borgmatic/config'
 
 
-def run_configuration(config_filename, config, arguments, used_config_paths):
+def run_configuration(config_filename, config, arguments):
     '''
-    Given a config filename, the corresponding parsed config dict, command-line arguments as a
-    dict from subparser name to a namespace of parsed arguments, and a list of paths of all configs used, execute the defined create, prune,
+    Given a config filename, the corresponding parsed config dict, and command-line arguments as a
+    dict from subparser name to a namespace of parsed arguments, execute the defined create, prune,
     compact, check, and/or other actions.
 
     Yield a combination of:
@@ -61,7 +61,6 @@ def run_configuration(config_filename, config, arguments, used_config_paths):
         for section_name in ('location', 'storage', 'retention', 'consistency', 'hooks')
     )
     global_arguments = arguments['global']
-    global_arguments.config_paths = used_config_paths
 
     local_path = location.get('local_path', 'borg')
     remote_path = location.get('remote_path')
@@ -645,9 +644,8 @@ def collect_configuration_run_summary_logs(configs, arguments):
 
     # Execute the actions corresponding to each configuration file.
     json_results = []
-    used_config_paths = list(configs.keys())
     for config_filename, config in configs.items():
-        results = list(run_configuration(config_filename, config, arguments, used_config_paths))
+        results = list(run_configuration(config_filename, config, arguments))
         error_logs = tuple(result for result in results if isinstance(result, logging.LogRecord))
 
         if error_logs:
@@ -729,6 +727,7 @@ def main():  # pragma: no cover
         sys.exit(0)
 
     config_filenames = tuple(collect.collect_config_filenames(global_arguments.config_paths))
+    global_arguments.used_config_paths = list(config_filenames)
     configs, parse_logs = load_configurations(
         config_filenames, global_arguments.overrides, global_arguments.resolve_env
     )