Skip to content

Commit 4ca1027

Browse files
authored
Merge pull request #396 from OP-TED/feature/TED-1045
Updated mapping_suite files hasher
2 parents 20b3cc1 + 6231bf9 commit 4ca1027

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

ted_sws/mapping_suite_processor/adapters/mapping_suite_hasher.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
""" """
99
import hashlib
1010
import pathlib
11+
import re
1112
from typing import Tuple, List, Union
1213

1314
from ted_sws.data_manager.adapters.mapping_suite_repository import MS_TRANSFORM_FOLDER_NAME, \
@@ -35,7 +36,10 @@ def _hash_a_file(file_path: pathlib.Path) -> Tuple[str, str]:
3536
"""
3637
Return a tuple of the relative file path and the file hash.
3738
"""
38-
hashed_line = hashlib.sha256(file_path.read_bytes()).hexdigest()
39+
# remove new-lines to align content generated on different operating systems
40+
new_line_pattern = re.compile(b'\r\n|\r|\n')
41+
file_content = re.sub(new_line_pattern, b'', file_path.read_bytes())
42+
hashed_line = hashlib.sha256(file_content).hexdigest()
3943
relative_path = str(file_path).replace(str(self.mapping_suite_path), "")
4044
return relative_path, hashed_line
4145

tests/test_data/package_F03_demo/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
]
2323
}
2424
},
25-
"mapping_suite_hash_digest": "0d02071125d6fe9d2b1e862902dae254beb253046038dfe9ddb0b5b792524b8f"
25+
"mapping_suite_hash_digest": "4b30cc45f45e4134394f571ac612b48efa8738cab77b9aad0290b779a5232c8f"
2626
}

0 commit comments

Comments
 (0)