Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions scanpipe/pipes/d2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1556,9 +1556,17 @@ def scan_ignored_to_files(project, logger=None):
.to_codebase()
.filter(status=flag.IGNORED_FROM_CONFIG)
)

# Capture the specific files id
scan_file_ids = list(scan_files.values_list("id", flat=True))

if not scan_file_ids:
return

scancode.scan_for_files(project, scan_files, progress_logger=logger)

project.codebaseresources.files().to_codebase().filter(status=flag.SCANNED).update(
# Revert to the original status value
project.codebaseresources.filter(id__in=scan_file_ids, status=flag.SCANNED).update(
status=flag.IGNORED_FROM_CONFIG
)

Expand All @@ -1573,9 +1581,17 @@ def scan_unmapped_to_files(project, logger=None):
.to_codebase()
.filter(status=flag.REQUIRES_REVIEW)
)

# Capture the specific files id
scan_file_ids = list(scan_files.values_list("id", flat=True))

if not scan_file_ids:
return

scancode.scan_for_files(project, scan_files, progress_logger=logger)

project.codebaseresources.files().to_codebase().filter(status=flag.SCANNED).update(
# Revert to the original status value
project.codebaseresources.filter(id__in=scan_file_ids, status=flag.SCANNED).update(
status=flag.REQUIRES_REVIEW
)

Expand Down
28 changes: 18 additions & 10 deletions scanpipe/tests/pipes/test_d2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1530,14 +1530,18 @@ def test_scanpipe_pipes_d2d_scan_ignored_to_files(self):
)
foo_java.update(status=flag.IGNORED_FROM_CONFIG)

# Create another file that is already scanned but should not be
# reverted
other_scanned = make_resource_file(
self.project1, "to/other_scanned.txt", status=flag.SCANNED
)

d2d.scan_ignored_to_files(self.project1)
foo_java.refresh_from_db()
other_scanned.refresh_from_db()

expected = self.project1.codebaseresources.filter(
status=flag.IGNORED_FROM_CONFIG
).count()

self.assertEqual(1, expected)
self.assertEqual(flag.IGNORED_FROM_CONFIG, foo_java.status)
self.assertEqual(flag.SCANNED, other_scanned.status)

def test_scan_unmapped_to_files(self):
to_dir = (
Expand All @@ -1558,14 +1562,18 @@ def test_scan_unmapped_to_files(self):
)
foo_java.update(status=flag.REQUIRES_REVIEW)

# Create another file that is already scanned but should not be
# reverted
other_scanned = make_resource_file(
self.project1, "to/other_scanned.txt", status=flag.SCANNED
)

d2d.scan_unmapped_to_files(self.project1)
foo_java.refresh_from_db()
other_scanned.refresh_from_db()

expected = self.project1.codebaseresources.filter(
status=flag.REQUIRES_REVIEW
).count()

self.assertEqual(1, expected)
self.assertEqual(flag.REQUIRES_REVIEW, foo_java.status)
self.assertEqual(flag.SCANNED, other_scanned.status)

def test_flag_deployed_from_resources_with_missing_license(self):
from_dir = (
Expand Down