Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/save restore portable #15253

Merged
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
6 changes: 5 additions & 1 deletion conan/api/subapi/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,23 @@ 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)
for pref, pref_bundle in package_list.prefs(ref, ref_bundle).items():
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)
Expand All @@ -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():
Expand Down
11 changes: 11 additions & 0 deletions conans/test/integration/command_v2/test_cache_save_restore.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down