NetBSDfr / pkgin

pkgin's official github repository
129 stars 40 forks source link

pkgin should be able to rm named packages without dependencies #48

Closed gdt closed 1 year ago

gdt commented 9 years ago

I'd like to be able to remove a package or set of packges, and have that just work if it can be removed, and just fail with an error if it cannot (due to a dependency still being there). As it is I have to parse the suggested output, and this basically requires pkgin to be used interactively.

Perhaps I should use pkg_delete instead, and it's an error to use the human tool for machine operations.

jperkin commented 1 year ago

Could you give me an example? I'm not entirely sure what you're asking. Thanks.

gdt commented 1 year ago

What I mean is:

except that I don't want --non-interactive but something else. Really I personally would want my behavior to be default and -r if rm should recurse, but I suspect that's a minority opinion.

Once I have my keep flags set, I find pkgin ar does what I want so this isn't so acute. But in general, pkgin is hard to use other than interactively by a human.

jperkin commented 1 year ago

Ok. This is definitely something I do not want pkgin to support, certainly the first behaviour, and absolutely never by default, as it should never knowingly create a broken system. Advanced users who know what they're doing can just use pkg_delete -f and ignore the warnings for that use-case.

I can maybe see some merit in showing if a package to be deleted has any dependents, and maybe if others feel strongly about this I could consider an optional argument to pkgin remove, but again given its advanced nature in knowingly leading to a broken system I'd argue the advanced user can just use pkg_info -qr around whatever tooling they are using instead.

gdt commented 1 year ago

I did not mean leading to a broken system at all. I completely agree that no broken states should ever result. I just mean 'pkgin rm foo' either can safely remove foo without recursing and does so, exiting 0, or cannot safely do so, prints an error, and exits 1.

I guess a more fundamental question might be: is it an error for pkgin to be called from a script, without a human to answer questions, or to be called like [complicated pipeline] | xargs pkgin rm? If that's out of scope, then the docs should say that, because otherwise a reasonable assumption is unix norms. I sort of feel like this is a GUI program only that happens to use the command line sometimes, but I'm not sure that's fair.

jperkin commented 1 year ago

It's reasonably fair. Given that pkgin is primarily a wrapper around pkg_install, it's certainly the case that it is tailored towards interactive use and providing the user options and features that are not supported by pkg_install. For any advanced usage such as pipelines I personally would lean towards using pkg_install (in this case | xargs pkg_delete should do what you want), as trying to make pkgin support many of the same features would just result in a lot of code duplication and even more confusion about which tool to use when.

That said there is some merit in having an option e.g. pkgin remove -o, that will only consider arguments that do not affect other packages. It would be useful for cases such as #42.

gdt commented 1 year ago

On one hand I am sympathetic to the "document that using it non-interactively is a bug", but pkgin also does a lot of cross-pkg dependency management that pkg_install cannot do. After this discussion I lean to:

Right now it feels like one should be able to call it non-interactively, but it doesn't really work.

jperkin commented 1 year ago

Just to be clear that using it non-interactively is emphatically not a bug, the disagreement is only in the behaviour that should occur where the expectation perhaps differs from what regular users would expect. Both apt and yum behave the same way that pkgin does, and will remove all affected packages if you try to remove a dependency. My point was perhaps badly made, I just wanted to emphasise that if you are a user who wants alternative behaviour to the default then you may be better served by using the underlying tools rather than the front-end which tries to be more user friendly and behave in ways that users coming from other systems might expect.

pkgin is used by a number of provisioning / configuration management systems (ansible, salt, etc.) where it is always called non-interactively and we encourage its continued use in those tools.

gdt commented 1 year ago

I guess then my residual issue is that calling it with /dev/null stdin leads to it trying to read to answer questions and printing odd complaints.

So perhaps a way forward is that if stdin is not a tty, then 1) don't ask the question and 2) do what should be done for a script if that is safe. I don't see recursive rm as safe, but I do see "i asked to install foo, and foo and 3 deps are installed" as safe.

That leaves the behavior with a tty the same, and makes it more script friendly.

gdt commented 1 year ago

Or if -n is supposed to be used for this, then not giving -n can be an error if not tty. using pkgin in shell scripts without that has frequently led me to confusion.

jperkin commented 1 year ago

Yeh certainly if there are areas where stdin isn't working then we should fix those.

gdt commented 1 year ago

ok, will file new point bugs as I find it, and thanks for the polite discussion!