From c45283db6ee8f706001c194c220135b701ef7cef Mon Sep 17 00:00:00 2001 From: Alexander Ioannidis Date: Thu, 24 Aug 2017 14:35:47 +0200 Subject: [PATCH] storage: allow default checksum implementation * Adds an optional parameter to `XRootDFileStorage.checksum` for forcing execution of the default checksum implementation. Signed-off-by: Alexander Ioannidis --- invenio_xrootd/storage.py | 8 +++++++- tests/test_storage.py | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/invenio_xrootd/storage.py b/invenio_xrootd/storage.py index 44dfdbf..60d2d0a 100644 --- a/invenio_xrootd/storage.py +++ b/invenio_xrootd/storage.py @@ -73,13 +73,19 @@ def _get_fs(self, create_dir=True, query=None): return (fs, filename) - def checksum(self, chunk_size=None, progress_callback=None): + def checksum(self, chunk_size=None, progress_callback=None, + use_default_impl=False): """Compute checksum of file. Queries the XRootD server to get checksum if possible, otherwise falls back to default Python implementation. The checksum algorithm used will be the one configured on the XRootD server. """ + if use_default_impl: + return super(XRootDFileStorage, self).checksum( + chunk_size=chunk_size, + progress_callback=progress_callback, + ) try: fs, path = self._get_fs() if not hasattr(fs, 'xrd_checksum'): diff --git a/tests/test_storage.py b/tests/test_storage.py index b0858e7..82181a0 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -73,6 +73,8 @@ def test_checksum_fallback(xrd_storage, eos_storage, file_md5): def test_checksum_xrd(xrd_storage_mocked, file_md5): """Test checksum.""" assert xrd_storage_mocked.checksum() == 'adler32:{0}'.format(file_md5) + assert xrd_storage_mocked.checksum( + use_default_impl=True) == 'md5:{0}'.format(file_md5) def test_checksum_xrd_overwrite(app, xrd_storage_mocked, file_md5):