Skip to content

Commit

Permalink
Avoid creating copies of download_info
Browse files Browse the repository at this point in the history
This commit adjusts JsonRepositoryProvider's logic so explicit release keys are
only evaluated, if an `url` is given. As a result `download_info` only contains
valid basic fields, which can be patched into those received from branches or
tags, without creating copies.
  • Loading branch information
deathaxe committed Oct 12, 2023
1 parent 5f4a86e commit e982b5a
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions package_control/providers/json_repository_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,6 @@ def get_libraries(self, invalid_sources=None):
)
)

# Validate date and version
for key in copied_release_keys:
if key in release:
value = release.get(key)
if not value or not isinstance(value, str):
raise InvalidLibraryReleaseKeyError(self.repo_url, info['name'], key)
download_info[key] = value

# Validate libraries
# the key can be used to specify dependencies, upstream via repositories
key = 'libraries' if self.schema_version.major >= 4 else 'dependencies'
Expand Down Expand Up @@ -361,6 +353,13 @@ def get_libraries(self, invalid_sources=None):
# if present, it is an explicit or resolved release
url = release.get('url')
if url:
for key in copied_release_keys:
if key in release:
value = release[key]
if not value or not isinstance(value, str):
raise InvalidLibraryReleaseKeyError(self.repo_url, info['name'], key)
download_info[key] = value

if 'version' not in download_info:
raise ProviderException(
'Missing "version" key in release with explicit "url" of library "{}"'
Expand Down Expand Up @@ -424,9 +423,8 @@ def get_libraries(self, invalid_sources=None):
)

for download in downloads:
new_download = download_info.copy()
new_download.update(download)
info['releases'].append(new_download)
download.update(download_info)
info['releases'].append(download)

# check required library keys
for key in required_library_keys:
Expand Down Expand Up @@ -603,14 +601,6 @@ def get_packages(self, invalid_sources=None):
for release in releases:
download_info = {}

# Validate date and version
for key in copied_release_keys:
if key in release:
value = release.get(key)
if not value or not isinstance(value, str):
raise InvalidPackageReleaseKeyError(self.repo_url, info['name'], key)
download_info[key] = value

# Validate libraries
# the key can be used to specify dependencies, upstream via repositories
key = 'libraries' if self.schema_version.major >= 4 else 'dependencies'
Expand Down Expand Up @@ -657,6 +647,14 @@ def get_packages(self, invalid_sources=None):
# if present, it is an explicit or resolved release
url = release.get('url')
if url:
# Validate date and version
for key in copied_release_keys:
if key in release:
value = release[key]
if not value or not isinstance(value, str):
raise InvalidPackageReleaseKeyError(self.repo_url, info['name'], key)
download_info[key] = value

if 'version' not in download_info:
raise ProviderException(
'Missing "version" key in release with explicit "url" of package "{}"'
Expand Down Expand Up @@ -717,9 +715,8 @@ def get_packages(self, invalid_sources=None):
)

for download in downloads:
new_download = download_info.copy()
new_download.update(download)
info['releases'].append(new_download)
download.update(download_info)
info['releases'].append(download)

elif self.schema_version.major == 2:
# missing key indicates ST2 release; no longer supported
Expand All @@ -735,6 +732,13 @@ def get_packages(self, invalid_sources=None):
# if present, it is an explicit or resolved release
url = release.get('url')
if url:
for key in copied_release_keys:
if key in release:
value = release[key]
if not value or not isinstance(value, str):
raise InvalidPackageReleaseKeyError(self.repo_url, info['name'], key)
download_info[key] = value

if 'version' not in download_info:
raise ProviderException(
'Missing "version" key in release with explicit "url" of package "{}"'
Expand Down Expand Up @@ -773,9 +777,8 @@ def get_packages(self, invalid_sources=None):
)

for download in downloads:
new_download = download_info.copy()
new_download.update(download)
info['releases'].append(new_download)
download.update(download_info)
info['releases'].append(download)

# check required package keys
for key in required_package_keys:
Expand Down

0 comments on commit e982b5a

Please sign in to comment.