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

[develop2] add pkg name in new cache path hashes #13011

Merged
merged 1 commit into from
Jan 31, 2023
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
32 changes: 20 additions & 12 deletions conan/internal/cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ def __init__(self, base_folder, db_filename):
self._base_folder = os.path.realpath(base_folder)
self._db = CacheDatabase(filename=db_filename)

def closedb(self):
self._db.close()

def _create_path(self, relative_path, remove_contents=True):
path = self._full_path(relative_path)
if os.path.exists(path) and remove_contents:
Expand All @@ -47,17 +44,28 @@ def _short_hash_path(h):
md.update(h)
sha_bytes = md.hexdigest()
# len based on: https://github.com/conan-io/conan/pull/9595#issuecomment-918976451
return sha_bytes[0:16]
# Reduce length in 3 characters 16 - 3 = 13
return sha_bytes[0:13]

@staticmethod
def _get_tmp_path(ref: RecipeReference):
# The reference will not have revision, but it will be always constant
h = ref.name[:5] + DataCache._short_hash_path(ref.repr_notime())
return os.path.join("t", h)

@staticmethod
def _get_tmp_path(ref):
def _get_tmp_path_pref(pref):
# The reference will not have revision, but it will be always constant
h = DataCache._short_hash_path(ref.repr_notime())
return os.path.join("tmp", h)
h = pref.ref.name[:5] + DataCache._short_hash_path(pref.repr_notime())
return os.path.join("t", h)

@staticmethod
def _get_path(ref: RecipeReference):
return ref.name[:5] + DataCache._short_hash_path(ref.repr_notime())

@staticmethod
def _get_path(ref):
return DataCache._short_hash_path(ref.repr_notime())
def _get_path_pref(pref):
return pref.ref.name[:5] + DataCache._short_hash_path(pref.repr_notime())

def create_export_recipe_layout(self, ref: RecipeReference):
# This is a temporary layout while exporting a new recipe, because the revision is not
Expand All @@ -74,7 +82,7 @@ def create_build_pkg_layout(self, pref: PkgReference):
assert pref.package_id, "Package id must be known to get or create the package layout"
assert pref.revision is None, "Package revision should be None"
assert pref.timestamp is None
package_path = self._get_tmp_path(pref)
package_path = self._get_tmp_path_pref(pref)
self._create_path(package_path)
return PackageLayout(pref, os.path.join(self.base_folder, package_path))

Expand Down Expand Up @@ -117,7 +125,7 @@ def get_or_create_pkg_layout(self, pref: PkgReference):
assert pref.ref.revision, "Recipe revision must be known to create the package layout"
assert pref.package_id, "Package id must be known to create the package layout"
assert pref.revision, "Package revision should be known to create the package layout"
package_path = self._get_path(pref)
package_path = self._get_path_pref(pref)
self._db.create_package(package_path, pref, None)
self._create_path(package_path, remove_contents=False)
return PackageLayout(pref, os.path.join(self.base_folder, package_path))
Expand Down Expand Up @@ -171,7 +179,7 @@ def remove_package(self, layout: RecipeLayout):
def assign_prev(self, layout: PackageLayout):
pref = layout.reference

new_path = self._get_path(pref)
new_path = self._get_path_pref(pref)

full_path = self._full_path(new_path)
rmdir(full_path)
Expand Down
2 changes: 0 additions & 2 deletions conan/internal/cache/db/cache_database.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sqlite3

from conan.internal.cache.db.packages_table import PackagesDBTable
from conan.internal.cache.db.recipes_table import RecipesDBTable
from conans.model.package_ref import PkgReference
Expand Down
3 changes: 0 additions & 3 deletions conans/client/cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ def __init__(self, cache_folder):
# The cache is first thing instantiated, we can remove this from env now
self._localdb_encryption_key = os.environ.pop('CONAN_LOGIN_ENCRYPTION_KEY', None)

def closedb(self):
self._data_cache.closedb()

def create_export_recipe_layout(self, ref: RecipeReference):
return self._data_cache.create_export_recipe_layout(ref)

Expand Down
4 changes: 0 additions & 4 deletions conans/test/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,6 @@ def _run_cli(self, command_line, assert_error=False):
trace = traceback.format_exc()
error = command.exception_exit_error(e)
finally:
try:
self.api.app.cache.closedb()
except AttributeError:
pass
sys.path = old_path
os.chdir(current_dir)
# Reset sys.modules to its prev state. A .copy() DOES NOT WORK
Expand Down