diff --git a/conda-store-server/conda_store_server/orm.py b/conda-store-server/conda_store_server/orm.py index 5a9b11762..3420e85a8 100644 --- a/conda-store-server/conda_store_server/orm.py +++ b/conda-store-server/conda_store_server/orm.py @@ -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 diff --git a/conda-store-server/tests/test_db_api.py b/conda-store-server/tests/test_db_api.py index b9574e7d6..75abeb4c4 100644 --- a/conda-store-server/tests/test_db_api.py +++ b/conda-store-server/tests/test_db_api.py @@ -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)