Skip to content

Commit

Permalink
Merge branch 'main' into CM-31107-new-cli-endpoints-should-be-applied…
Browse files Browse the repository at this point in the history
…-to-sca-scans-only
  • Loading branch information
MarshalX authored Jan 10, 2024
2 parents afe9965 + 9fcd4ca commit 0a15990
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions process_executable_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import hashlib
import os
import platform
import shutil
from pathlib import Path
from string import Template
from typing import List, Tuple, Union

_ARCHIVE_FORMAT = 'zip'
_HASH_FILE_EXT = '.sha256'
_OS_TO_CLI_DIST_TEMPLATE = {
'darwin': Template('cycode-mac$suffix$ext'),
Expand Down Expand Up @@ -130,6 +132,14 @@ def get_cli_hash_path(output_path: Path, is_onedir: bool) -> str:
return os.path.join(output_path, get_cli_hash_filename(is_onedir))


def get_cli_archive_filename(is_onedir: bool) -> str:
return get_cli_file_name(suffix=get_cli_file_suffix(is_onedir))


def get_cli_archive_path(output_path: Path, is_onedir: bool) -> str:
return os.path.join(output_path, get_cli_archive_filename(is_onedir))


def process_executable_file(input_path: Path, is_onedir: bool) -> str:
output_path = input_path.parent
hash_file_path = get_cli_hash_path(output_path, is_onedir)
Expand All @@ -138,6 +148,10 @@ def process_executable_file(input_path: Path, is_onedir: bool) -> str:
hashes = get_hashes_of_every_file_in_the_directory(input_path)
normalized_hashes = normalize_hashes_db(hashes, input_path)
write_hashes_db_to_file(normalized_hashes, hash_file_path)

archived_file_path = get_cli_archive_path(output_path, is_onedir)
shutil.make_archive(archived_file_path, _ARCHIVE_FORMAT, input_path)
shutil.rmtree(input_path)
else:
file_hash = get_hash_of_file(input_path)
write_hash_to_file(file_hash, hash_file_path)
Expand Down

0 comments on commit 0a15990

Please sign in to comment.