Skip to content

Commit 1d25624

Browse files
committed
[SP-2587] fix: modify dir hash creation
1 parent 7333c97 commit 1d25624

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/scanoss/scanners/folder_hasher.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
MINIMUM_FILE_COUNT = 8
1717
MINIMUM_CONCATENATED_NAME_LENGTH = 32
18-
MINIMUM_FILE_NAME_LENGTH = 64
18+
MAXIMUM_FILE_NAME_LENGTH = 32
1919

2020

2121
class DirectoryNode:
@@ -140,7 +140,7 @@ def _build_root_node(self, path: str) -> DirectoryNode:
140140
root_node = DirectoryNode(str(root))
141141

142142
all_files = [
143-
f for f in root.rglob('*') if f.is_file() and len(f.name.encode('utf-8')) <= MINIMUM_FILE_NAME_LENGTH
143+
f for f in root.rglob('*') if f.is_file() and len(f.name.encode('utf-8')) <= MAXIMUM_FILE_NAME_LENGTH
144144
]
145145
filtered_files = self.file_filters.get_filtered_files_from_files(all_files, str(root))
146146

@@ -249,11 +249,15 @@ def _hash_calc(self, node: DirectoryNode) -> dict:
249249
ext_without_dot = extension[1:]
250250
extension_map[ext_without_dot] = extension_map.get(ext_without_dot, 0) + 1
251251

252-
last_directory = Path(current_directory).name or Path(self.scan_dir).name
252+
current_directory.removeprefix(self.scan_dir)
253+
parts = current_directory.split(os.path.sep)
254+
for d in parts:
255+
if d in {'', '.', '..'}:
256+
continue
257+
unique_directories.add(d)
253258

254259
processed_hashes.add(key_str)
255260
unique_file_names.add(file_name_without_extension)
256-
unique_directories.add(last_directory)
257261
selected_names.append(file_name)
258262
file_hashes.append(file.key)
259263

0 commit comments

Comments
 (0)