Skip to content

Commit 0ffbe25

Browse files
committed
temporarily include parent_path field from previous pr for tests
1 parent 5221f63 commit 0ffbe25

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by Django 5.1.9 on 2025-06-19 21:19
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('scanpipe', '0072_discovereddependency_uuid_unique'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='codebaseresource',
15+
name='parent_path',
16+
field=models.CharField(blank=True, help_text="The path of the resource's parent directory. Set to None for top-level (root) resources. Used to efficiently retrieve a directory's contents.", max_length=2000, null=True),
17+
),
18+
migrations.AddIndex(
19+
model_name='codebaseresource',
20+
index=models.Index(fields=['project', 'parent_path'], name='scanpipe_co_project_008448_idx'),
21+
),
22+
]
23+
24+

scanpipe/models.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def delete(self, *args, **kwargs):
229229
Note that projects with queued or running pipeline runs cannot be deleted.
230230
See the `_raise_if_run_in_progress` method.
231231
The following if statements should not be triggered unless the `.delete()`
232-
method is directly call from an instance of this class.
232+
method is directly call from a instance of this class.
233233
"""
234234
with suppress(redis.exceptions.ConnectionError, AttributeError):
235235
if self.status == self.Status.RUNNING:
@@ -2685,6 +2685,18 @@ class CodebaseResource(
26852685
'Eg.: "/usr/bin/bash" for a path of "tarball-extract/rootfs/usr/bin/bash"'
26862686
),
26872687
)
2688+
2689+
parent_path = models.CharField(
2690+
max_length=2000,
2691+
null=True,
2692+
blank=True,
2693+
help_text=_(
2694+
"The path of the resource's parent directory. "
2695+
"Set to None for top-level (root) resources. "
2696+
"Used to efficiently retrieve a directory's contents."
2697+
),
2698+
)
2699+
26882700
status = models.CharField(
26892701
blank=True,
26902702
max_length=50,
@@ -2772,6 +2784,7 @@ class Meta:
27722784
models.Index(fields=["compliance_alert"]),
27732785
models.Index(fields=["is_binary"]),
27742786
models.Index(fields=["is_text"]),
2787+
models.Index(fields=["project", "parent_path"]),
27752788
]
27762789
constraints = [
27772790
models.UniqueConstraint(
@@ -2784,6 +2797,11 @@ class Meta:
27842797
def __str__(self):
27852798
return self.path
27862799

2800+
def save(self, *args, **kwargs):
2801+
if self.path and not self.parent_path:
2802+
self.parent_path = self.parent_directory()
2803+
super().save(*args, **kwargs)
2804+
27872805
@property
27882806
def location_path(self):
27892807
"""Return the location of the resource as a Path instance."""
@@ -2851,7 +2869,8 @@ def get_path_segments_with_subpath(self):
28512869

28522870
def parent_directory(self):
28532871
"""Return the parent path for this CodebaseResource or None."""
2854-
return parent_directory(self.path, with_trail=False)
2872+
parent_path = parent_directory(str(self.path), with_trail=False)
2873+
return parent_path or None
28552874

28562875
def has_parent(self):
28572876
"""

0 commit comments

Comments
 (0)