conan-io / examples2

Conan 2.x examples
MIT License
90 stars 48 forks source link

cmd_clean command removes wrong packages #44

Open antze-k opened 2 years ago

antze-k commented 2 years ago

The command removes all package revisions except for the latest one from a recipe, but not a package. This leads to the following: if I build two packages for a single recipe, for example, Debug and Release one, "conan clean" removes one of them (the one that was built the first, I suppose).

I think the correct behaviour would be if this:

all_prevs = conan_api.search.package_revisions(f"{rrev.repr_notime()}:*#*", remote=remote)
# ...

is replaced with this:

packages = conan_api.list.packages_configurations(rrev, remote=remote)
for package in packages:
    all_prevs = conan_api.search.package_revisions(repr(package), remote=remote)
    # ...

At least, with such fix the behaviour looks like what I expected, so far.

memsharded commented 2 years ago

I see, yes, I think you are right.

But I think the right solution is not to change the logic to adapt it, but to simplify the example, simplifying the assumptions to "a command that removes all recipe revisions of a package except the last one", not mixing the behavior for also package revisions. Checking with team for feedback.

antze-k commented 2 years ago

Both functionalities are actually handy. When I found this example initially (along with the possibility of writing custom commands), it helped me a lot, because the use case "remove everything from the cache that I don't need anymore" is very common for me.

Anyway, it's an example, not a core Conan command, so I guess any decision is fine. I'd also like to remind that the whole command code is also available in the docs, so it has to be fixed in the docs repo as well. I could contribute and help with that if you like, whenever you're settled with the final decision.

memsharded commented 2 years ago

Both functionalities are actually handy. When I found this example initially (along with the possibility of writing custom commands), it helped me a lot, because the use case "remove everything from the cache that I don't need anymore" is very common for me.

Yes, the functionality is handy, but this is not an example of cleaning things in the cache, it is an example of how to write a custom command, the focus should be in the command syntax, not very elaborate logic on the "clean" part. Lets see what @czoido thinks about it.