Selaa lähdekoodia

Add a method to detect out of date binary extension modules

Jonas Borgström 11 vuotta sitten
vanhempi
sitoutus
92c333c071
5 muutettua tiedostoa jossa 23 lisäystä ja 2 poistoa
  1. 2 1
      attic/archiver.py
  2. 2 0
      attic/chunker.pyx
  3. 2 1
      attic/crypto.pyx
  4. 2 0
      attic/hashindex.pyx
  5. 15 0
      attic/helpers.py

+ 2 - 1
attic/archiver.py

@@ -16,7 +16,7 @@ from attic.key import key_creator
 from attic.helpers import Error, location_validator, format_time, \
     format_file_mode, ExcludePattern, exclude_path, adjust_patterns, to_localtime, \
     get_cache_dir, get_keys_dir, format_timedelta, prune_within, prune_split, \
-    Manifest, remove_surrogates, update_excludes, format_archive
+    Manifest, remove_surrogates, update_excludes, format_archive, check_extension_modules
 from attic.remote import RepositoryServer, RemoteRepository
 
 
@@ -399,6 +399,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
         return args
 
     def run(self, args=None):
+        check_extension_modules()
         keys_dir = get_keys_dir()
         if not os.path.exists(keys_dir):
             os.makedirs(keys_dir)

+ 2 - 0
attic/chunker.pyx

@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+API_VERSION = 1
+
 from libc.stdlib cimport free
 
 cdef extern from "_chunker.c":

+ 2 - 1
attic/crypto.pyx

@@ -3,10 +3,11 @@
 This could be replaced by PyCrypto or something similar when the performance
 of their PBKDF2 implementation is comparable to the OpenSSL version.
 """
-
 from libc.string cimport memcpy
 from libc.stdlib cimport malloc, free
 
+API_VERSION = 1
+
 cdef extern from "openssl/rand.h":
     int  RAND_bytes(unsigned char *buf,int num)
 

+ 2 - 0
attic/hashindex.pyx

@@ -1,6 +1,8 @@
 # -*- coding: utf-8 -*-
 import os
 
+API_VERSION = 1
+
 
 cdef extern from "_hashindex.c":
     ctypedef struct HashIndex:

+ 15 - 0
attic/helpers.py

@@ -13,6 +13,10 @@ from fnmatch import translate
 from operator import attrgetter
 import fcntl
 
+import attic.hashindex
+import attic.chunker
+import attic.crypto
+
 
 class Error(Exception):
     """Error base class"""
@@ -23,6 +27,10 @@ class Error(Exception):
         return 'Error: ' + type(self).__doc__.format(*self.args)
 
 
+class ExtensionModuleError(Error):
+    """The Attic binary extension modules does not seem to be properly installed"""
+
+
 class UpgradableLock:
 
     class LockUpgradeFailed(Error):
@@ -52,6 +60,13 @@ class UpgradableLock:
         self.fd.close()
 
 
+def check_extension_modules():
+    if (attic.hashindex.API_VERSION != 1 or
+        attic.chunker.API_VERSION != 1 or
+        attic.crypto.API_VERSION != 1):
+        raise ExtensionModuleError
+
+
 class Manifest:
 
     MANIFEST_ID = b'\0' * 32