Skip to content

Commit

Permalink
Check the size of build_path
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Karetnikov committed Nov 6, 2023
1 parent 0760fa2 commit 291f12a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 10 additions & 3 deletions conda-store-server/conda_store_server/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,22 @@ def build_path(self, conda_store):
"""
store_directory = os.path.abspath(conda_store.store_directory)
namespace = self.environment.namespace.name
name = self.specification.name
return (
res = (
pathlib.Path(
conda_store.build_directory.format(
store_directory=store_directory, namespace=namespace, name=name
store_directory=store_directory,
namespace=namespace,
)
)
/ self.build_key
)
# conda prefix must be less or equal to 255 chars
# https://github.com/conda-incubator/conda-store/issues/649
if len(str(res)) > 255:
raise ValueError(
f"build_path too long: {res} must be <= 255 chars, got {len(str(res))}"
)
return res

def environment_path(self, conda_store):
"""Environment path is the path for the symlink to the build
Expand Down
10 changes: 10 additions & 0 deletions conda-store-server/tests/test_db_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,13 @@ def test_get_set_keyvaluestore(db):
# test updating a prefix
api.set_kvstore_key_values(db, "pytest", {"c": 999, "d": 999}, update=False)
assert {**setting_1, **setting_2} == api.get_kvstore_key_values(db, "pytest")


def test_build_path_too_long(db, conda_store, simple_specification):
conda_store.store_directory = 'A' * 800
build_id = conda_store.register_environment(
db, specification=simple_specification, namespace="pytest"
)
build = api.get_build(db, build_id=build_id)
with pytest.raises(ValueError, match=r"build_path too long: .* must be <= 255 chars"):
build.build_path(conda_store)

0 comments on commit 291f12a

Please sign in to comment.