Skip to content

Commit e19b544

Browse files
committed
Store filenames with extensions in name field #467
* Update scancode-toolkit to 31.0.0rc3 #447 * Update expected test results Signed-off-by: Jono Yang <[email protected]>
1 parent 6a8be49 commit e19b544

13 files changed

+598
-485
lines changed

CHANGELOG.rst

+7
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ v31.0.0 (next)
5656

5757
https://github.com/nexB/scancode.io/issues/413
5858

59+
- CodebaseResource.name now contains both the bare file name with extension, as
60+
opposed to just the bare file name without extension.
61+
https://github.com/nexB/scancode.io/issues/467
62+
63+
- Using a name stripped from its extension was something that was not used in
64+
other AboutCode project or tools.
65+
5966
v30.2.0 (2021-12-17)
6067
--------------------
6168

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 4.0.6 on 2022-07-27 16:23
2+
3+
from django.db import migrations
4+
5+
6+
def concat_codebaseresource_name_and_extension(apps, schema_editor):
7+
CodebaseResource = apps.get_model('scanpipe', 'CodebaseResource')
8+
for cb in CodebaseResource.objects.filter(extension__isnull=False).iterator():
9+
name = cb.name
10+
extension = cb.extension
11+
# The scan_package pipeline was putting the extension in the name field
12+
# whereas the scan_codebase pipeline did not put the extension in the
13+
# name field
14+
if not name.endswith(extension):
15+
cb.name = f"{name}{extension}"
16+
cb.save()
17+
18+
19+
class Migration(migrations.Migration):
20+
21+
dependencies = [
22+
('scanpipe', '0019_codebaseresource_package_data_discovereddependency'),
23+
]
24+
25+
operations = [
26+
migrations.RunPython(concat_codebaseresource_name_and_extension),
27+
]

scanpipe/models.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ class Type(models.TextChoices):
14281428
name = models.CharField(
14291429
max_length=255,
14301430
blank=True,
1431-
help_text=_("File or directory name of this resource."),
1431+
help_text=_("File or directory name of this resource with its extension."),
14321432
)
14331433
extension = models.CharField(
14341434
max_length=100,
@@ -1775,6 +1775,14 @@ def for_packages(self):
17751775
"""
17761776
return [str(package) for package in self.discovered_packages.all()]
17771777

1778+
def for_packages_append(self, package_uid):
1779+
if not package_uid:
1780+
return
1781+
package = DiscoveredPackage.objects.get(package_uid=package_uid)
1782+
if package not in self.discovered_packages.all():
1783+
self.discovered_packages.add(package)
1784+
self.save()
1785+
17781786

17791787
class DiscoveredPackageQuerySet(PackageURLQuerySetMixin, ProjectRelatedQuerySet):
17801788
pass

scanpipe/pipes/scancode.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def get_resource_info(location):
139139
file_info.update(
140140
{
141141
"type": resource_type,
142-
"name": fileutils.file_base_name(location),
142+
"name": fileutils.file_name(location),
143143
"extension": fileutils.file_extension(location),
144144
}
145145
)

0 commit comments

Comments
 (0)