How Chocolatey knows which packages are installed and which aren’t

chocolateyinstallationpackage-management

Chocolatey is a package management system for Windows. First, you download and install Chocolatey, which is free and open-source software. You tell it what software you want, then (usually) answer one or more questions. Chocolatey will then download and silently install the software for you.

I'm trying to better understand how Chocolatey knows what it has already installed. This is in order so that I can understand whether or not interrupting a "chocolatey install" operation can cause Chocolatey to become permanently confused, forever.

Using Chocolatey 0.9.9.8, when I try to install a package (7zip) twice in a row, the first time succeeds and the second time does nothing but print a warning message. The message says:

7zip v9.38 already installed.
Use –force to reinstall, specify a version to install, or try upgrade.

Chocolatey installed 0/1 package(s).
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

I looked into the Chocolatey source code in order to try to find the answer. It looks like the method call which checks whether or not a package is already installed is this one. But I couldn't find the source code for the FindPackage method.

How does Chocolatey know which packages it has already installed? Does it keep a central database somewhere on my machine which keeps track of what it has installed and what it hasn't?

Best Answer

It tracks that based on the actual packages on disk. Note that there is a lib folder in %ChocolateyInstall% e.g. 'C:\ProgramData\chocolatey\lib' in the default installed location.

In that folder are package folders, in each of those is a *.nupkg file. Each *.nupkg file represents an installed package.

For where you are looking, note the following -

Also, GitHub trick so you don't need webarchive links - once you've found the source code bit, press y to get the permanent link.

Related Question