|
| 1 | +import logging |
1 | 2 | import os |
2 | 3 | from typing import List, Optional |
3 | 4 |
|
|
6 | 7 | from cycode.cli.files_collector.sca.base_restore_dependencies import BaseRestoreDependencies |
7 | 8 | from cycode.cli.models import Document |
8 | 9 |
|
9 | | -GO_PROJECT_FILE_EXTENSIONS = ['.mod'] |
| 10 | +GO_PROJECT_FILE_EXTENSIONS = ['.mod', '.sum'] |
10 | 11 | GO_RESTORE_FILE_NAME = 'go.mod.graph' |
11 | 12 | BUILD_GO_FILE_NAME = 'go.mod' |
| 13 | +BUILD_GO_LOCK_FILE_NAME = 'go.sum' |
12 | 14 |
|
13 | 15 |
|
14 | 16 | class RestoreGoDependencies(BaseRestoreDependencies): |
15 | 17 | def __init__(self, context: click.Context, is_git_diff: bool, command_timeout: int) -> None: |
16 | 18 | super().__init__(context, is_git_diff, command_timeout, create_output_file_manually=True) |
17 | 19 |
|
| 20 | + def try_restore_dependencies(self, document: Document) -> Optional[Document]: |
| 21 | + manifest_exists = os.path.isfile(self.get_working_directory(document) + os.sep + BUILD_GO_FILE_NAME) |
| 22 | + lock_exists = os.path.isfile(self.get_working_directory(document) + os.sep + BUILD_GO_LOCK_FILE_NAME) |
| 23 | + |
| 24 | + if not manifest_exists or not lock_exists: |
| 25 | + logging.info('No manifest go.mod file found' if not manifest_exists else 'No manifest go.sum file found') |
| 26 | + |
| 27 | + manifest_files_exists = manifest_exists & lock_exists |
| 28 | + |
| 29 | + if not manifest_files_exists: |
| 30 | + return None |
| 31 | + |
| 32 | + return super().try_restore_dependencies(document) |
| 33 | + |
18 | 34 | def is_project(self, document: Document) -> bool: |
19 | 35 | return any(document.path.endswith(ext) for ext in GO_PROJECT_FILE_EXTENSIONS) |
20 | 36 |
|
|
0 commit comments