From c80c5ef21f258dfab0f78cf385e1dc064ae1bfe8 Mon Sep 17 00:00:00 2001
From: alaskowski <alaskowski@ethz.ch>
Date: Tue, 7 Mar 2023 09:27:13 +0100
Subject: [PATCH] SSDM-13300: Fixed crc32 checksum calculation

---
 .../src/python/obis/dm/checksum.py            | 20 +++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/app-openbis-command-line/src/python/obis/dm/checksum.py b/app-openbis-command-line/src/python/obis/dm/checksum.py
index 25c16532efb..89d5a2d7b9a 100644
--- a/app-openbis-command-line/src/python/obis/dm/checksum.py
+++ b/app-openbis-command-line/src/python/obis/dm/checksum.py
@@ -13,12 +13,11 @@
 #   limitations under the License.
 #
 import abc
-import ctypes
 import hashlib
 import json
 import os
+import zlib
 
-from .command_result import CommandException
 from .utils import run_shell, cd
 
 
@@ -78,14 +77,19 @@ class ChecksumGenerator(metaclass=abc.ABCMeta):
 
 
 class ChecksumGeneratorCrc32(ChecksumGenerator):
+
+    def _crc32(self, file):
+        with open(file, 'rb') as f:
+            computed_hash = 0
+            for chunk in iter(lambda: f.read(65536), b""):
+                computed_hash = zlib.crc32(chunk, computed_hash)
+            return computed_hash & 0xFFFFFFFF
+
     def _get_checksum(self, file):
-        result = run_shell(['cksum', file])
-        if result.failure():
-            raise CommandException(result)
-        fields = result.output.split(" ")
+        result = self._crc32(file)
         return {
-            'crc32': ctypes.c_int(int(fields[0])).value,
-            'fileLength': int(fields[1]),
+            'crc32': result,
+            'fileLength': os.path.getsize(file),
             'path': file
         }
 
-- 
GitLab