Skip to content

Commit 264ccad

Browse files
committed
Ensure the status was not updated after scanned #2228
Signed-off-by: Chin Yeung Li <tli@nexb.com>
1 parent a76e0cc commit 264ccad

2 files changed

Lines changed: 42 additions & 16 deletions

File tree

scanpipe/pipes/d2d.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,11 +1556,20 @@ def scan_ignored_to_files(project, logger=None):
15561556
.to_codebase()
15571557
.filter(status=flag.IGNORED_FROM_CONFIG)
15581558
)
1559+
1560+
# Capture the specific files id
1561+
scan_file_ids = list(scan_files.values_list("id", flat=True))
1562+
1563+
if not scan_file_ids:
1564+
return
1565+
15591566
scancode.scan_for_files(project, scan_files, progress_logger=logger)
15601567

1561-
project.codebaseresources.files().to_codebase().filter(status=flag.SCANNED).update(
1562-
status=flag.IGNORED_FROM_CONFIG
1563-
)
1568+
# Revert to the original status value
1569+
project.codebaseresources.filter(
1570+
id__in=scan_file_ids,
1571+
status=flag.SCANNED
1572+
).update(status=flag.IGNORED_FROM_CONFIG)
15641573

15651574

15661575
def scan_unmapped_to_files(project, logger=None):
@@ -1573,11 +1582,20 @@ def scan_unmapped_to_files(project, logger=None):
15731582
.to_codebase()
15741583
.filter(status=flag.REQUIRES_REVIEW)
15751584
)
1585+
1586+
# Capture the specific files id
1587+
scan_file_ids = list(scan_files.values_list("id", flat=True))
1588+
1589+
if not scan_file_ids:
1590+
return
1591+
15761592
scancode.scan_for_files(project, scan_files, progress_logger=logger)
15771593

1578-
project.codebaseresources.files().to_codebase().filter(status=flag.SCANNED).update(
1579-
status=flag.REQUIRES_REVIEW
1580-
)
1594+
# Revert to the original status value
1595+
project.codebaseresources.filter(
1596+
id__in=scan_file_ids,
1597+
status=flag.SCANNED
1598+
).update(status=flag.REQUIRES_REVIEW)
15811599

15821600

15831601
def flag_deployed_from_resources_with_missing_license(project, doc_extensions=None):

scanpipe/tests/pipes/test_d2d.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,14 +1530,18 @@ def test_scanpipe_pipes_d2d_scan_ignored_to_files(self):
15301530
)
15311531
foo_java.update(status=flag.IGNORED_FROM_CONFIG)
15321532

1533+
# Create another file that is already scanned but should not be
1534+
# reverted
1535+
other_scanned = make_resource_file(
1536+
self.project1, "to/other_scanned.txt", status=flag.SCANNED
1537+
)
1538+
15331539
d2d.scan_ignored_to_files(self.project1)
15341540
foo_java.refresh_from_db()
1541+
other_scanned.refresh_from_db()
15351542

1536-
expected = self.project1.codebaseresources.filter(
1537-
status=flag.IGNORED_FROM_CONFIG
1538-
).count()
1539-
1540-
self.assertEqual(1, expected)
1543+
self.assertEqual(flag.IGNORED_FROM_CONFIG, foo_java.status)
1544+
self.assertEqual(flag.SCANNED, other_scanned.status)
15411545

15421546
def test_scan_unmapped_to_files(self):
15431547
to_dir = (
@@ -1558,14 +1562,18 @@ def test_scan_unmapped_to_files(self):
15581562
)
15591563
foo_java.update(status=flag.REQUIRES_REVIEW)
15601564

1565+
# Create another file that is already scanned but should not be
1566+
# reverted
1567+
other_scanned = make_resource_file(
1568+
self.project1, "to/other_scanned.txt", status=flag.SCANNED
1569+
)
1570+
15611571
d2d.scan_unmapped_to_files(self.project1)
15621572
foo_java.refresh_from_db()
1573+
other_scanned.refresh_from_db()
15631574

1564-
expected = self.project1.codebaseresources.filter(
1565-
status=flag.REQUIRES_REVIEW
1566-
).count()
1567-
1568-
self.assertEqual(1, expected)
1575+
self.assertEqual(flag.REQUIRES_REVIEW, foo_java.status)
1576+
self.assertEqual(flag.SCANNED, other_scanned.status)
15691577

15701578
def test_flag_deployed_from_resources_with_missing_license(self):
15711579
from_dir = (

0 commit comments

Comments
 (0)