Skip to content

Commit

Permalink
[client] Fix source content change error when diffing remote runs
Browse files Browse the repository at this point in the history
When diffing two runs from a command-line client, a
`The following source file contents changed since the latest analysis:`
error is shown instead of the diff.

To reproduce the problem we just have to remove the project folder after
storage or use the --trim-path-prefix option during storage and then
just run the diff command with two remote runs.
  • Loading branch information
csordasmarton committed Feb 18, 2021
1 parent 6626d77 commit f3998ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
22 changes: 13 additions & 9 deletions web/client/codechecker_client/cmd_line_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,16 +1208,24 @@ def print_reports(client,
# Convert all the reports to the common Report
# type for printing and formatting to various formats.
converted_reports = []
changed_files = set()
for report in reports:
if not isinstance(report, Report):
r = report_type_converter.reportData_to_report(report)
if source_line_contents:
source_line = convert.from_b64(
r.source_line = convert.from_b64(
source_line_contents[report.fileId][report.line])
r.source_line = source_line
converted_reports.append(r)
else:
if not os.path.exists(report.file_path):
changed_files.add(report.file_path)
continue

report.source_line = util.get_line(report.file_path,
report.line)

converted_reports.append(report)

reports = converted_reports

repo_dir = os.environ.get('CC_REPO_DIR')
Expand Down Expand Up @@ -1265,20 +1273,16 @@ def print_reports(client,
file_stats = defaultdict(int)
severity_stats = defaultdict(int)

changed_files = set()
for report in reports:
if report.source_line is None:
continue

severity = context.severity_map.get(report.check_name,
'UNSPECIFIED')
file_name = report.file_path
checked_file = file_name \
+ ':' + str(report.line) + ":" + str(report.col)
check_msg = report.description
source_line = None
if os.path.exists(file_name):
source_line = util.get_line(file_name, report.line)
if source_line is None:
changed_files.add(file_name)
continue

rows.append((severity,
checked_file,
Expand Down
4 changes: 4 additions & 0 deletions web/tests/functional/diff_remote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ def setup_package():
# Export the test configuration to the workspace.
env.export_test_cfg(TEST_WORKSPACE, test_config)

# Remove report directories which are not used anymore.
shutil.rmtree(test_proj_path_base)
shutil.rmtree(test_proj_path_new)


def teardown_package():
"""Clean up after the test."""
Expand Down

0 comments on commit f3998ed

Please sign in to comment.