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 recreation of same package revision #14938

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
10 changes: 9 additions & 1 deletion conan/internal/cache/cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import hashlib
import os
import shutil
import uuid

from conan.internal.cache.conan_reference_layout import RecipeLayout, PackageLayout
Expand Down Expand Up @@ -187,9 +188,16 @@ def assign_prev(self, layout: PackageLayout):
self._db.create_package(relpath, pref, build_id)
except ConanReferenceAlreadyExistsInDB:
# TODO: Optimize this into 1 single UPSERT operation
# This was exported before, making it latest again, update timestamp
# There was a previous package folder for this same package reference (and prev)
pkg_layout = self.get_package_layout(pref)
# We remove the old one and move the new one to the path of the previous one
# this can be necessary in case of new metadata or build-folder because of "build_id()"
pkg_layout.remove()
shutil.move(layout.base_folder, pkg_layout.base_folder) # clean unused temporary build
layout._base_folder = pkg_layout.base_folder # reuse existing one
# TODO: The relpath would be the same as the previous one, it shouldn't be ncessary to
# update it, the update_package_timestamp() can be simplified and path dropped
relpath = os.path.relpath(layout.base_folder, self._base_folder)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have little insight into why this is needed again given the conext of the comment above, I'll trust you on this one but maybe I just need to look deeper into this bit of code functionality

self._db.update_package_timestamp(pref, path=relpath, build_id=build_id)

def assign_rrev(self, layout: RecipeLayout):
Expand Down
21 changes: 21 additions & 0 deletions conans/test/integration/cache/test_same_pref_removal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os

from conans.test.assets.genconanfile import GenConanfile
from conans.test.utils.tools import TestClient


def test_same_pref_removal():
c = TestClient()
c.save({"conanfile.py": GenConanfile("pkg", "0.1")})
c.run("export .")
c.run("install --requires=pkg/0.1 --build=pkg*")
layout = c.created_layout()
pkg_folder1 = layout.package()
assert os.path.exists(os.path.join(pkg_folder1, "conanmanifest.txt"))
assert os.path.exists(os.path.join(pkg_folder1, "conaninfo.txt"))
c.run("install --requires=pkg/0.1 --build=pkg*")
layout = c.created_layout()
pkg_folder2 = layout.package()
assert pkg_folder1 == pkg_folder2
assert os.path.exists(os.path.join(pkg_folder1, "conanmanifest.txt"))
assert os.path.exists(os.path.join(pkg_folder1, "conaninfo.txt"))
6 changes: 3 additions & 3 deletions conans/test/integration/command_v2/test_cache_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def test_cache_clean_all():

def test_cache_multiple_builds_same_prev_clean():
"""
Different consecutive builds will create different folders, even if for the
same exact prev, leaving trailing non-referenced folders
Different consecutive builds will create exactly the same folder, for the
same exact prev, not leaving trailing non-referenced folders
"""
c = TestClient()
c.save({"conanfile.py": GenConanfile("pkg", "0.1")})
Expand All @@ -75,7 +75,7 @@ def test_cache_multiple_builds_same_prev_clean():
c.run("cache path pkg/0.1:da39a3ee5e6b4b0d3255bfef95601890afd80709")
path2 = str(c.stdout)
assert path2 in create_out
assert path1 != path2
assert path1 == path2

builds_folder = os.path.join(c.cache_folder, "p", "b")
assert len(os.listdir(builds_folder)) == 1 # only one build
Expand Down