Sfoglia il codice sorgente

Merge pull request #3450 from ThomasWaldmann/borg-delete-removing-security-dir

also delete security dir when deleting a repo, fixes #3427
TW 7 anni fa
parent
commit
1e9c90da2a
2 ha cambiato i file con 9 aggiunte e 1 eliminazioni
  1. 2 1
      src/borg/archiver.py
  2. 7 0
      src/borg/cache.py

+ 2 - 1
src/borg/archiver.py

@@ -38,7 +38,7 @@ from .algorithms.checksums import crc32
 from .archive import Archive, ArchiveChecker, ArchiveRecreater, Statistics, is_special
 from .archive import Archive, ArchiveChecker, ArchiveRecreater, Statistics, is_special
 from .archive import BackupOSError, backup_io
 from .archive import BackupOSError, backup_io
 from .archive import FilesystemObjectProcessors, MetadataCollector, ChunksProcessor
 from .archive import FilesystemObjectProcessors, MetadataCollector, ChunksProcessor
-from .cache import Cache, assert_secure
+from .cache import Cache, assert_secure, SecurityManager
 from .constants import *  # NOQA
 from .constants import *  # NOQA
 from .compress import CompressionSpec
 from .compress import CompressionSpec
 from .crypto.key import key_creator, key_argument_names, tam_required_file, tam_required, RepoKey, PassphraseKey
 from .crypto.key import key_creator, key_argument_names, tam_required_file, tam_required, RepoKey, PassphraseKey
@@ -1108,6 +1108,7 @@ class Archiver:
                 return self.exit_code
                 return self.exit_code
             repository.destroy()
             repository.destroy()
             logger.info("Repository deleted.")
             logger.info("Repository deleted.")
+            SecurityManager.destroy(repository)
         Cache.destroy(repository)
         Cache.destroy(repository)
         logger.info("Cache deleted.")
         logger.info("Cache deleted.")
         return self.exit_code
         return self.exit_code

+ 7 - 0
src/borg/cache.py

@@ -66,6 +66,13 @@ class SecurityManager:
         self.location_file = os.path.join(self.dir, 'location')
         self.location_file = os.path.join(self.dir, 'location')
         self.manifest_ts_file = os.path.join(self.dir, 'manifest-timestamp')
         self.manifest_ts_file = os.path.join(self.dir, 'manifest-timestamp')
 
 
+    @staticmethod
+    def destroy(repository, path=None):
+        """destroy the security dir for ``repository`` or at ``path``"""
+        path = path or get_security_dir(repository.id_str)
+        if os.path.exists(path):
+            shutil.rmtree(path)
+
     def known(self):
     def known(self):
         return os.path.exists(self.key_type_file)
         return os.path.exists(self.key_type_file)