Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions cfbs/cfbs_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
load_bundlenames,
)
from cfbs.internal_file_management import (
SUPPORTED_URI_SCHEMES,
clone_url_repo,
fetch_archive,
SUPPORTED_ARCHIVES,
Expand Down Expand Up @@ -132,7 +133,7 @@ def _add_using_url(
if url.endswith(SUPPORTED_ARCHIVES):
config_path, url_commit = fetch_archive(url, checksum)
else:
assert url.startswith(("https://", "git://", "ssh://"))
assert url.startswith(SUPPORTED_URI_SCHEMES)
config_path, url_commit = clone_url_repo(url)

if "@" in url and (url.rindex("@") > url.rindex(".")):
Expand Down Expand Up @@ -385,16 +386,20 @@ def add_command(

before = {m["name"] for m in self.get("build", [])}

if to_add[0].endswith(SUPPORTED_ARCHIVES) or to_add[0].startswith(
("https://", "git://", "ssh://")
):
if to_add[0].startswith(SUPPORTED_URI_SCHEMES):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not the check to see if it ends with one of the SUPPORTED_ARCHIVES still be here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If to_add[0].endswith(SUPPORTED_ARCHIVES) is true then either to_add[0].startswith(SUPPORTED_URI_SCHEMES) is true and nothing has changed, or it's false and to_add[0] isn't a supported URL and the subsequent code has no capability to add a local archive file. Actually neither _add_using_url nor _add_modules have such capability, and it seems adding local archive files has simply never been supported (we could consider supporting it as a local version of adding an archive file by URL in the future).

self._add_using_url(
url=to_add[0],
to_add=to_add[1:],
added_by=added_by,
checksum=checksum,
)
else:
# for this `if` to be valid, module names containing `://` should be illegal
if "://" in to_add[0]:
user_error(
"URI scheme not supported. The supported URI schemes are: "
+ ", ".join(SUPPORTED_URI_SCHEMES)
)
self._add_modules(to_add, added_by, checksum)

added = {m["name"] for m in self["build"]}.difference(before)
Expand Down
3 changes: 2 additions & 1 deletion cfbs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from cfbs.cfbs_config import CFBSConfig, CFBSReturnWithoutCommit
from cfbs.validate import validate_config
from cfbs.internal_file_management import (
SUPPORTED_URI_SCHEMES,
fetch_archive,
get_download_path,
local_module_copy,
Expand Down Expand Up @@ -455,7 +456,7 @@ def _get_modules_by_url(name) -> list:
msg = ""
files = []
for name in to_remove:
if name.startswith(("https://", "ssh://", "git://")):
if name.startswith(SUPPORTED_URI_SCHEMES):
matches = _get_modules_by_url(name)
if not matches:
user_error("Could not find module with URL '%s'" % name)
Expand Down
5 changes: 3 additions & 2 deletions cfbs/internal_file_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

_SUPPORTED_TAR_TYPES = (".tar.gz", ".tgz")
SUPPORTED_ARCHIVES = (".zip",) + _SUPPORTED_TAR_TYPES
SUPPORTED_URI_SCHEMES = ("https://", "ssh://", "git://")


def local_module_name(module_path):
Expand Down Expand Up @@ -113,7 +114,7 @@ def local_module_copy(module, counter, max_length):


def _get_path_from_url(url):
if not url.startswith(("https://", "ssh://", "git://")):
if not url.startswith(SUPPORTED_URI_SCHEMES):
if "://" in url:
return user_error("Unsupported URL protocol in '%s'" % url)
else:
Expand Down Expand Up @@ -153,7 +154,7 @@ def _clone_and_checkout(url, path, commit):


def clone_url_repo(repo_url):
assert repo_url.startswith(("https://", "ssh://", "git://"))
assert repo_url.startswith(SUPPORTED_URI_SCHEMES)

commit = None
if "@" in repo_url and (repo_url.rindex("@") > repo_url.rindex(".")):
Expand Down