algorithms: rename crc32 to checksums

This commit is contained in:
Marian Beermann 2017-05-31 23:17:27 +02:00
parent 0221e31058
commit 6c91a750d1
6 changed files with 36 additions and 35 deletions

View File

@ -55,7 +55,7 @@ crypto_ll_source = 'src/borg/crypto/low_level.pyx'
chunker_source = 'src/borg/algorithms/chunker.pyx'
hashindex_source = 'src/borg/hashindex.pyx'
item_source = 'src/borg/item.pyx'
crc32_source = 'src/borg/algorithms/crc32.pyx'
checksums_source = 'src/borg/algorithms/checksums.pyx'
platform_posix_source = 'src/borg/platform/posix.pyx'
platform_linux_source = 'src/borg/platform/linux.pyx'
platform_darwin_source = 'src/borg/platform/darwin.pyx'
@ -67,7 +67,7 @@ cython_sources = [
chunker_source,
hashindex_source,
item_source,
crc32_source,
checksums_source,
platform_posix_source,
platform_linux_source,
@ -92,8 +92,9 @@ try:
'src/borg/algorithms/chunker.c', 'src/borg/algorithms/buzhash.c',
'src/borg/hashindex.c', 'src/borg/_hashindex.c',
'src/borg/item.c',
'src/borg/algorithms/crc32.c',
'src/borg/algorithms/checksums.c',
'src/borg/algorithms/crc32_dispatch.c', 'src/borg/algorithms/crc32_clmul.c', 'src/borg/algorithms/crc32_slice_by_8.c',
'src/borg/algorithms/xxh64/xxhash.h', 'src/borg/algorithms/xxh64/xxhash.c',
'src/borg/platform/posix.c',
'src/borg/platform/linux.c',
'src/borg/platform/freebsd.c',
@ -111,14 +112,14 @@ except ImportError:
chunker_source = chunker_source.replace('.pyx', '.c')
hashindex_source = hashindex_source.replace('.pyx', '.c')
item_source = item_source.replace('.pyx', '.c')
crc32_source = crc32_source.replace('.pyx', '.c')
checksums_source = checksums_source.replace('.pyx', '.c')
platform_posix_source = platform_posix_source.replace('.pyx', '.c')
platform_linux_source = platform_linux_source.replace('.pyx', '.c')
platform_freebsd_source = platform_freebsd_source.replace('.pyx', '.c')
platform_darwin_source = platform_darwin_source.replace('.pyx', '.c')
from distutils.command.build_ext import build_ext
if not on_rtd and not all(os.path.exists(path) for path in [
compress_source, crypto_ll_source, chunker_source, hashindex_source, item_source, crc32_source,
compress_source, crypto_ll_source, chunker_source, hashindex_source, item_source, checksums_source,
platform_posix_source, platform_linux_source, platform_freebsd_source, platform_darwin_source]):
raise ImportError('The GIT version of Borg needs Cython. Install Cython or use a released version.')
@ -568,23 +569,23 @@ class build_man(Command):
write(option.ljust(padding), desc)
def rm(file):
try:
os.unlink(file)
print('rm', file)
except FileNotFoundError:
pass
class Clean(clean):
def run(self):
super().run()
for source in cython_sources:
genc = source.replace('.pyx', '.c')
try:
os.unlink(genc)
print('rm', genc)
except FileNotFoundError:
pass
rm(genc)
compiled_glob = source.replace('.pyx', '.cpython*')
for compiled in glob(compiled_glob):
try:
os.unlink(compiled)
print('rm', compiled)
except FileNotFoundError:
pass
for compiled in sorted(glob(compiled_glob)):
rm(compiled)
cmdclass = {
'build_ext': build_ext,
@ -602,7 +603,7 @@ if not on_rtd:
Extension('borg.hashindex', [hashindex_source]),
Extension('borg.item', [item_source]),
Extension('borg.algorithms.chunker', [chunker_source]),
Extension('borg.algorithms.crc32', [crc32_source]),
Extension('borg.algorithms.checksums', [checksums_source]),
]
if not sys.platform.startswith(('win32', )):
ext_modules.append(Extension('borg.platform.posix', [platform_posix_source]))

View File

@ -25,11 +25,11 @@ cdef extern from "xxh64/xxhash.c":
XXH_OK,
XXH_ERROR
XXH64_hash_t XXH64 (const void* input, size_t length, unsigned long long seed);
XXH64_hash_t XXH64(const void* input, size_t length, unsigned long long seed);
XXH_errorcode XXH64_reset (XXH64_state_t* statePtr, unsigned long long seed);
XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length);
XXH64_hash_t XXH64_digest (const XXH64_state_t* statePtr);
XXH_errorcode XXH64_reset(XXH64_state_t* statePtr, unsigned long long seed);
XXH_errorcode XXH64_update(XXH64_state_t* statePtr, const void* input, size_t length);
XXH64_hash_t XXH64_digest(const XXH64_state_t* statePtr);
void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash);
XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src);

View File

@ -33,7 +33,7 @@ import msgpack
import borg
from . import __version__
from . import helpers
from .algorithms.crc32 import crc32
from .algorithms.checksums import crc32
from .archive import Archive, ArchiveChecker, ArchiveRecreater, Statistics, is_special
from .archive import BackupOSError, backup_io
from .cache import Cache, assert_secure

View File

@ -6,7 +6,7 @@ from hmac import compare_digest
from ..helpers import IntegrityError
from ..logger import create_logger
from ..algorithms.crc32 import StreamingXXH64
from ..algorithms.checksums import StreamingXXH64
logger = create_logger()

View File

@ -23,7 +23,7 @@ from .locking import Lock, LockError, LockErrorT
from .logger import create_logger
from .lrucache import LRUCache
from .platform import SaveFile, SyncFile, sync_dir, safe_fadvise
from .algorithms.crc32 import crc32
from .algorithms.checksums import crc32
logger = create_logger(__name__)

View File

@ -4,12 +4,12 @@ from binascii import unhexlify
import pytest
from ..algorithms import crc32
from ..algorithms import checksums
from ..helpers import bin_to_hex
crc32_implementations = [crc32.crc32_slice_by_8]
if crc32.have_clmul:
crc32_implementations.append(crc32.crc32_clmul)
crc32_implementations = [checksums.crc32_slice_by_8]
if checksums.have_clmul:
crc32_implementations.append(checksums.crc32_clmul)
@pytest.mark.parametrize('implementation', crc32_implementations)
@ -24,16 +24,16 @@ def test_crc32(implementation):
def test_xxh64():
assert bin_to_hex(crc32.xxh64(b'test', 123)) == '2b81b9401bef86cf'
assert bin_to_hex(crc32.xxh64(b'test')) == '4fdcca5ddb678139'
assert bin_to_hex(crc32.xxh64(unhexlify('6f663f01c118abdea553373d5eae44e7dac3b6829b46b9bbeff202b6c592c22d724'
'fb3d25a347cca6c5b8f20d567e4bb04b9cfa85d17f691590f9a9d32e8ccc9102e9d'
'cf8a7e6716280cd642ce48d03fdf114c9f57c20d9472bb0f81c147645e6fa3d331'))) == \
'35d5d2f545d9511a'
assert bin_to_hex(checksums.xxh64(b'test', 123)) == '2b81b9401bef86cf'
assert bin_to_hex(checksums.xxh64(b'test')) == '4fdcca5ddb678139'
assert bin_to_hex(checksums.xxh64(unhexlify(
'6f663f01c118abdea553373d5eae44e7dac3b6829b46b9bbeff202b6c592c22d724'
'fb3d25a347cca6c5b8f20d567e4bb04b9cfa85d17f691590f9a9d32e8ccc9102e9d'
'cf8a7e6716280cd642ce48d03fdf114c9f57c20d9472bb0f81c147645e6fa3d331'))) == '35d5d2f545d9511a'
def test_streaming_xxh64():
hasher = crc32.StreamingXXH64(123)
hasher = checksums.StreamingXXH64(123)
hasher.update(b'te')
hasher.update(b'st')
assert bin_to_hex(hasher.digest()) == hasher.hexdigest() == '2b81b9401bef86cf'