Skip to content

Commit a9c5118

Browse files
committed
temporarily include parent_path field from previous pr for tests
Signed-off-by: Aayush Kumar <aayush214.kumar@gmail.com>
1 parent 17d0fc3 commit a9c5118

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:
@@ -2688,6 +2688,18 @@ class CodebaseResource(
26882688
'Eg.: "/usr/bin/bash" for a path of "tarball-extract/rootfs/usr/bin/bash"'
26892689
),
26902690
)
2691+
2692+
parent_path = models.CharField(
2693+
max_length=2000,
2694+
null=True,
2695+
blank=True,
2696+
help_text=_(
2697+
"The path of the resource's parent directory. "
2698+
"Set to None for top-level (root) resources. "
2699+
"Used to efficiently retrieve a directory's contents."
2700+
),
2701+
)
2702+
26912703
status = models.CharField(
26922704
blank=True,
26932705
max_length=50,
@@ -2781,6 +2793,7 @@ class Meta:
27812793
models.Index(fields=["compliance_alert"]),
27822794
models.Index(fields=["is_binary"]),
27832795
models.Index(fields=["is_text"]),
2796+
models.Index(fields=["project", "parent_path"]),
27842797
]
27852798
constraints = [
27862799
models.UniqueConstraint(
@@ -2793,6 +2806,11 @@ class Meta:
27932806
def __str__(self):
27942807
return self.path
27952808

2809+
def save(self, *args, **kwargs):
2810+
if self.path and not self.parent_path:
2811+
self.parent_path = self.parent_directory()
2812+
super().save(*args, **kwargs)
2813+
27962814
def get_absolute_url(self):
27972815
return reverse("resource_detail", args=[self.project.slug, self.path])
27982816

@@ -2863,7 +2881,8 @@ def get_path_segments_with_subpath(self):
28632881

28642882
def parent_directory(self):
28652883
"""Return the parent path for this CodebaseResource or None."""
2866-
return parent_directory(self.path, with_trail=False)
2884+
parent_path = parent_directory(str(self.path), with_trail=False)
2885+
return parent_path or None
28672886

28682887
def has_parent(self):
28692888
"""

0 commit comments

Comments
 (0)