From 92c333c0717b4735ee1586a66949caa2df7bb151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Tue, 18 Mar 2014 22:04:08 +0100 Subject: [PATCH] Add a method to detect out of date binary extension modules --- attic/archiver.py | 3 ++- attic/chunker.pyx | 2 ++ attic/crypto.pyx | 3 ++- attic/hashindex.pyx | 2 ++ attic/helpers.py | 15 +++++++++++++++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/attic/archiver.py b/attic/archiver.py index 4037ce6f0..a2e3c3950 100644 --- a/attic/archiver.py +++ b/attic/archiver.py @@ -16,7 +16,7 @@ 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 @@ def preprocess_args(self, args): 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) diff --git a/attic/chunker.pyx b/attic/chunker.pyx index 40541d36a..6fa208989 100644 --- a/attic/chunker.pyx +++ b/attic/chunker.pyx @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +API_VERSION = 1 + from libc.stdlib cimport free cdef extern from "_chunker.c": diff --git a/attic/crypto.pyx b/attic/crypto.pyx index c9361c0dd..b842f8f7f 100644 --- a/attic/crypto.pyx +++ b/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) diff --git a/attic/hashindex.pyx b/attic/hashindex.pyx index 53afbe338..e3740a8f5 100644 --- a/attic/hashindex.pyx +++ b/attic/hashindex.pyx @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- import os +API_VERSION = 1 + cdef extern from "_hashindex.c": ctypedef struct HashIndex: diff --git a/attic/helpers.py b/attic/helpers.py index 953d23279..84dcfe418 100644 --- a/attic/helpers.py +++ b/attic/helpers.py @@ -13,6 +13,10 @@ 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 @@ def get_message(self): 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 @@ def release(self): 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