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

Feature/cache save compression level #16211

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
11 changes: 7 additions & 4 deletions conan/api/subapi/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,24 @@ def clean(self, package_list, source=True, build=True, download=True, temp=True,

def save(self, package_list, tgz_path):
cache_folder = self.conan_api.cache_folder
app = ConanApp(self.conan_api)
global_conf = self.conan_api.config.global_conf
cache = ClientCache(cache_folder, global_conf)
out = ConanOutput()
mkdir(os.path.dirname(tgz_path))
name = os.path.basename(tgz_path)
compresslevel = global_conf.get("core.gzip:compresslevel", check_type=int)
with open(tgz_path, "wb") as tgz_handle:
tgz = gzopen_without_timestamps(name, mode="w", fileobj=tgz_handle)
tgz = gzopen_without_timestamps(name, mode="w", fileobj=tgz_handle,
compresslevel=compresslevel)
for ref, ref_bundle in package_list.refs().items():
ref_layout = app.cache.recipe_layout(ref)
ref_layout = 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)
pref_layout = cache.pkg_layout(pref)
pkg_folder = pref_layout.package()
folder = os.path.relpath(pkg_folder, cache_folder)
folder = folder.replace("\\", "/") # make win paths portable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def test_cache_save_restore():
c.run("create . --name=pkg --version=1.0 -s os=Linux")
c.run("create . --name=pkg --version=1.1 -s os=Linux")
c.run("create . --name=other --version=2.0 -s os=Linux")
c.run("cache save pkg/*:* ")
# Force the compress level just to make sure it doesn't crash
c.run("cache save pkg/*:* -cc core.gzip:compresslevel=9")
cache_path = os.path.join(c.current_folder, "conan_cache_save.tgz")
assert os.path.exists(cache_path)
_validate_restore(cache_path)
Expand Down