diff --git a/conan/internal/model/conf.py b/conan/internal/model/conf.py index 52d69540f75..42c662e5063 100644 --- a/conan/internal/model/conf.py +++ b/conan/internal/model/conf.py @@ -1,4 +1,5 @@ import copy +import hashlib import numbers import platform import re @@ -756,7 +757,8 @@ def load_global_conf(home_folder): content = template.render({"platform": platform, "os": os, "distro": distro, "conan_version": conan_version, "conan_home_folder": home_folder, - "detect_api": detect_api}) + "detect_api": detect_api, + "hashlib": hashlib}) new_config.loads(content) else: # creation of a blank global.conf file for user convenience default_global_conf = textwrap.dedent("""\ diff --git a/test/integration/cache/storage_path_test.py b/test/integration/cache/storage_path_test.py index 851078babda..2cac6d7b2ee 100644 --- a/test/integration/cache/storage_path_test.py +++ b/test/integration/cache/storage_path_test.py @@ -1,4 +1,6 @@ import os +import textwrap +from hashlib import sha256 from conan.test.utils.test_files import temp_folder from conan.test.utils.tools import TestClient, GenConanfile @@ -22,3 +24,18 @@ def test_wrong_home_error(): client.save_home({"global.conf": "core.cache:storage_path=//"}) client.run("list *") assert "Couldn't initialize storage in" in client.out + + +def test_short_storage_path(): + c = TestClient() + global_conf = textwrap.dedent("""\ + {% set h = hashlib.new("sha256", conan_home_folder.encode(), + usedforsecurity=False).hexdigest() %} + core.cache:storage_path=C:/conan_{{h[:6]}} + """) + c.save_home({"global.conf": global_conf}) + c.run("config show *") + myhash = sha256() + myhash.update(c.cache_folder.replace("\\", "/").encode()) + myhash = myhash.hexdigest()[:6] + assert f"core.cache:storage_path: C:/conan_{myhash}" in c.out