Browse Source

transfer: validate archive names before transfer

Thomas Waldmann 2 years ago
parent
commit
ebff12ad41
1 changed files with 14 additions and 1 deletions
  1. 14 1
      src/borg/archiver/transfer_cmd.py

+ 14 - 1
src/borg/archiver/transfer_cmd.py

@@ -5,7 +5,7 @@ from ..archive import Archive
 from ..constants import *  # NOQA
 from ..crypto.key import uses_same_id_hash, uses_same_chunker_secret
 from ..helpers import EXIT_SUCCESS, EXIT_ERROR, Error
-from ..helpers import location_validator, Location
+from ..helpers import location_validator, Location, archivename_validator
 from ..helpers import format_file_size
 from ..manifest import Manifest
 
@@ -39,6 +39,19 @@ class TransferMixIn:
         if not archive_names:
             return EXIT_SUCCESS
 
+        an_errors = []
+        av = archivename_validator()
+        for archive_name in archive_names:
+            try:
+                av(archive_name)
+            except argparse.ArgumentTypeError as err:
+                an_errors.append(str(err))
+        if an_errors:
+            self.print_error("Invalid archive names detected, please rename them before transfer:")
+            for err_msg in an_errors:
+                self.print_error(err_msg)
+            return EXIT_ERROR
+
         from .. import upgrade as upgrade_mod
 
         try: