Browse Source

Add a method to detect out of date binary extension modules

Jonas Borgström 11 năm trước cách đây
mục cha
commit
92c333c071

+ 2 - 1
attic/archiver.py

@@ -16,7 +16,7 @@ from attic.key import key_creator
 from attic.helpers import Error, location_validator, format_time, \
 from attic.helpers import Error, location_validator, format_time, \
     format_file_mode, ExcludePattern, exclude_path, adjust_patterns, to_localtime, \
     format_file_mode, ExcludePattern, exclude_path, adjust_patterns, to_localtime, \
     get_cache_dir, get_keys_dir, format_timedelta, prune_within, prune_split, \
     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
 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
         return args
 
 
     def run(self, args=None):
     def run(self, args=None):
+        check_extension_modules()
         keys_dir = get_keys_dir()
         keys_dir = get_keys_dir()
         if not os.path.exists(keys_dir):
         if not os.path.exists(keys_dir):
             os.makedirs(keys_dir)
             os.makedirs(keys_dir)

+ 2 - 0
attic/chunker.pyx

@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 # -*- coding: utf-8 -*-
 
 
+API_VERSION = 1
+
 from libc.stdlib cimport free
 from libc.stdlib cimport free
 
 
 cdef extern from "_chunker.c":
 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
 This could be replaced by PyCrypto or something similar when the performance
 of their PBKDF2 implementation is comparable to the OpenSSL version.
 of their PBKDF2 implementation is comparable to the OpenSSL version.
 """
 """
-
 from libc.string cimport memcpy
 from libc.string cimport memcpy
 from libc.stdlib cimport malloc, free
 from libc.stdlib cimport malloc, free
 
 
+API_VERSION = 1
+
 cdef extern from "openssl/rand.h":
 cdef extern from "openssl/rand.h":
     int  RAND_bytes(unsigned char *buf,int num)
     int  RAND_bytes(unsigned char *buf,int num)
 
 

+ 2 - 0
attic/hashindex.pyx

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

+ 15 - 0
attic/helpers.py

@@ -13,6 +13,10 @@ from fnmatch import translate
 from operator import attrgetter
 from operator import attrgetter
 import fcntl
 import fcntl
 
 
+import attic.hashindex
+import attic.chunker
+import attic.crypto
+
 
 
 class Error(Exception):
 class Error(Exception):
     """Error base class"""
     """Error base class"""
@@ -23,6 +27,10 @@ class Error(Exception):
         return 'Error: ' + type(self).__doc__.format(*self.args)
         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 UpgradableLock:
 
 
     class LockUpgradeFailed(Error):
     class LockUpgradeFailed(Error):
@@ -52,6 +60,13 @@ class UpgradableLock:
         self.fd.close()
         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:
 class Manifest:
 
 
     MANIFEST_ID = b'\0' * 32
     MANIFEST_ID = b'\0' * 32