diff --git a/conan/api/subapi/cache.py b/conan/api/subapi/cache.py index 468ed14009b..d76624ccf6c 100644 --- a/conan/api/subapi/cache.py +++ b/conan/api/subapi/cache.py @@ -119,6 +119,7 @@ def save(self, package_list, tgz_path): for ref, ref_bundle in package_list.refs().items(): ref_layout = app.cache.recipe_layout(ref) recipe_folder = os.path.relpath(ref_layout.base_folder, cache_folder) + recipe_folder = recipe_folder.replace("\\", "/") # make win paths portable ref_bundle["recipe_folder"] = recipe_folder out.info(f"Saving {ref}: {recipe_folder}") tgz.add(os.path.join(cache_folder, recipe_folder), recipe_folder, recursive=True) @@ -126,13 +127,15 @@ def save(self, package_list, tgz_path): pref_layout = app.cache.pkg_layout(pref) pkg_folder = pref_layout.package() folder = os.path.relpath(pkg_folder, cache_folder) + folder = folder.replace("\\", "/") # make win paths portable pref_bundle["package_folder"] = folder out.info(f"Saving {pref}: {folder}") tgz.add(os.path.join(cache_folder, folder), folder, recursive=True) if os.path.exists(pref_layout.metadata()): metadata_folder = os.path.relpath(pref_layout.metadata(), cache_folder) + metadata_folder = metadata_folder.replace("\\", "/") # make paths portable pref_bundle["metadata_folder"] = metadata_folder - out.info(f"Saving {pref} metadata: {folder}") + out.info(f"Saving {pref} metadata: {metadata_folder}") tgz.add(os.path.join(cache_folder, metadata_folder), metadata_folder, recursive=True) serialized = json.dumps(package_list.serialize(), indent=2) @@ -159,6 +162,7 @@ def restore(self, path): recipe_layout = cache.get_or_create_ref_layout(ref) recipe_folder = ref_bundle["recipe_folder"] rel_path = os.path.relpath(recipe_layout.base_folder, cache.cache_folder) + rel_path = rel_path.replace("\\", "/") assert rel_path == recipe_folder, f"{rel_path}!={recipe_folder}" out.info(f"Restore: {ref} in {recipe_folder}") for pref, pref_bundle in package_list.prefs(ref, ref_bundle).items(): diff --git a/conans/test/integration/command_v2/test_cache_save_restore.py b/conans/test/integration/command_v2/test_cache_save_restore.py index 598c13e4fe8..587eda7297c 100644 --- a/conans/test/integration/command_v2/test_cache_save_restore.py +++ b/conans/test/integration/command_v2/test_cache_save_restore.py @@ -1,6 +1,7 @@ import json import os import shutil +import tarfile from conans.test.assets.genconanfile import GenConanfile from conans.test.utils.tools import TestClient @@ -18,6 +19,16 @@ def test_cache_save_restore(): assert os.path.exists(cache_path) _validate_restore(cache_path) + # Lets test that the pkglist does not contain windows backslash paths to make it portable + with open(cache_path, mode='rb') as file_handler: + the_tar = tarfile.open(fileobj=file_handler) + fileobj = the_tar.extractfile("pkglist.json") + pkglist = fileobj.read() + the_tar.close() + + package_list = json.loads(pkglist) + assert "\\" not in package_list + def test_cache_save_downloaded_restore(): """ what happens if we save packages downloaded from server, not