Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve AD32 checksum calculation; Fix #4879 #4880

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/rucio/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
import errno
import getpass
import hashlib
import io
import json
import logging
import mmap
import os
import os.path
import re
Expand All @@ -59,6 +61,7 @@
import time
import zlib
from enum import Enum
from functools import partial
from uuid import uuid4 as uuid
from xml.etree import ElementTree

Expand Down Expand Up @@ -239,13 +242,16 @@ def adler32(file):
adler = 1

try:
with open(file, 'rb') as openFile:
for line in openFile:
adler = zlib.adler32(line, adler)
with open(file, 'r+b') as f:
# memory map the file
m = mmap.mmap(f.fileno(), 0)
# partial block reads at slightly increased buffer sizes
for block in iter(partial(m.read, io.DEFAULT_BUFFER_SIZE), b''):
adler = zlib.adler32(block, adler)
except Exception as e:
raise Exception('FATAL - could not get Adler32 checksum of file %s - %s' % (file, e))

# backflip on 32bit
# backflip on 32bit -- can be removed once everything is fully migrated to 64bit
if adler < 0:
adler = adler + 2 ** 32

Expand Down