Skip to content

Commit

Permalink
Feature/cache save compression level (#16211)
Browse files Browse the repository at this point in the history
* use core.gzip:compresslevel in conan cache save

* add check
  • Loading branch information
memsharded authored May 7, 2024
1 parent 5391d5a commit 69a251c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
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

0 comments on commit 69a251c

Please sign in to comment.