Hi, while working on xmldb editor support to upgrade_plugin_savepoint() calls... I found this:
1) the 4th parameter $dir ... perhaps it's clear if it is defined as $name, because it can lead to confussion with plugins stored under "type" dirs and others. That doesn't matter and it's the name of the plugin dir always.
2) To prevent some mistakes, the $type could be checked against get_plugin_types() to see if it's a valid type.
3) Once verified 2) it's easy to perform one dir_exists() to check that the exact plugin exists.
Just a suggestion. I've added tehm as TODOs in the upgrade_plugin_savepoint() function. FYC