Search code examples
macosbuildinstallationdowngradepkgbuild

pkgbuild OSX, Enforce installation failure in case of downgrade


I'd made a package that include 2 components according to --component-plist file. on the plist file I've added the following flag to prevent downgrade :

BundleIsVersionChecked: Don't install bundle if newer version on disk? (bool)

when I perform downgrade scenario, I get the following message :

Sep 15 11:42:49 os-x-10 installd[284]: PackageKit: Skipping component \ 
"com.my.driverAE21E" (<current_version>) because the version \
<new_version> is already installed at <my_component>

This is expected, but unfortunately, the installation goes on, and the other component is being properly installed, and so does the preinstall and postintsall scripts - so I get a mixture of both versions.

Is there any way to enforce component version validation prior to any attempt to actually install them, and stop the installation process in case the validation wasn't pass.

UPDATE :

Another approach that can help me is to prevent the running of preinstall and postinstall scripts in case an attempt to downgrade is made.

I've seen reference to unanswered question about this issue here.


Solution

  • What you need to do is add version-check to your distribution.xml for product archive, and then perform whatever check you want in JavaScript code. This will allow you to prevent installation from starting as early as possible by returning false from the check function. Can't give you an example as I never did custom version check myself, but using my.target.receiptForIdentifier() and system.compareVersions() should get you going.

    More info on the matter: https://developer.apple.com/reference/installerjs (follow "Distribution Definition XML Schema Reference" link there for distribution.xml description).