Fixed an issue when unnecessary packages were removed in `update --dry-run` mode // Resolve #3809

This commit is contained in:
Ivan Kravets
2021-01-23 15:24:32 +02:00
parent e695e30a9b
commit ef6e70a38b
2 changed files with 21 additions and 17 deletions

View File

@ -19,6 +19,7 @@ PlatformIO Core 5
* Fixed an issue with Python 3.8+ on Windows when a network drive is used (`issue #3417 <https://github.com/platformio/platformio-core/issues/3417>`_) * Fixed an issue with Python 3.8+ on Windows when a network drive is used (`issue #3417 <https://github.com/platformio/platformio-core/issues/3417>`_)
* Fixed an issue when "strict" compatibility mode was not used for a library with custom "platforms" field in `library.json <https://docs.platformio.org/page/librarymanager/config.html>`__ manifest (`issue #3806 <https://github.com/platformio/platformio-core/issues/3806>`_) * Fixed an issue when "strict" compatibility mode was not used for a library with custom "platforms" field in `library.json <https://docs.platformio.org/page/librarymanager/config.html>`__ manifest (`issue #3806 <https://github.com/platformio/platformio-core/issues/3806>`_)
* Fixed an issue with compiler driver for ".ccls" language server (`issue #3808 <https://github.com/platformio/platformio-core/issues/3808>`_) * Fixed an issue with compiler driver for ".ccls" language server (`issue #3808 <https://github.com/platformio/platformio-core/issues/3808>`_)
* Fixed an issue when unnecessary packages were removed in ``update --dry-run`` mode (`issue #3809 <https://github.com/platformio/platformio-core/issues/3809>`_)
5.0.4 (2020-12-30) 5.0.4 (2020-12-30)
~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~

View File

@ -69,7 +69,7 @@ class PlatformPackageManager(BasePackageManager): # pylint: disable=too-many-an
) )
p.install_python_packages() p.install_python_packages()
p.on_installed() p.on_installed()
self.cleanup_packages(list(p.packages)) self.autoremove_packages(list(p.packages))
return pkg return pkg
def uninstall(self, spec, silent=False, skip_dependencies=False): def uninstall(self, spec, silent=False, skip_dependencies=False):
@ -83,7 +83,7 @@ class PlatformPackageManager(BasePackageManager): # pylint: disable=too-many-an
if not skip_dependencies: if not skip_dependencies:
p.uninstall_python_packages() p.uninstall_python_packages()
p.on_uninstalled() p.on_uninstalled()
self.cleanup_packages(list(p.packages)) self.autoremove_packages(list(p.packages))
return pkg return pkg
def update( # pylint: disable=arguments-differ, too-many-arguments def update( # pylint: disable=arguments-differ, too-many-arguments
@ -118,7 +118,8 @@ class PlatformPackageManager(BasePackageManager): # pylint: disable=too-many-an
) )
p.update_packages(only_check) p.update_packages(only_check)
self.cleanup_packages(list(p.packages)) if not only_check:
self.autoremove_packages(list(p.packages))
if missed_pkgs: if missed_pkgs:
p.install_packages( p.install_packages(
@ -127,28 +128,30 @@ class PlatformPackageManager(BasePackageManager): # pylint: disable=too-many-an
return new_pkg or pkg return new_pkg or pkg
def cleanup_packages(self, names): def autoremove_packages(self, names):
self.memcache_reset() self.memcache_reset()
deppkgs = {} required = {}
for platform in PlatformPackageManager().get_installed(): for platform in PlatformPackageManager().get_installed():
p = PlatformFactory.new(platform) p = PlatformFactory.new(platform)
for pkg in p.get_installed_packages(): for pkg in p.get_installed_packages():
if pkg.metadata.name not in deppkgs: if pkg.metadata.name not in required:
deppkgs[pkg.metadata.name] = set() required[pkg.metadata.name] = set()
deppkgs[pkg.metadata.name].add(pkg.metadata.version) required[pkg.metadata.name].add(pkg.metadata.version)
pm = ToolPackageManager() pm = ToolPackageManager()
for pkg in pm.get_installed(): for pkg in pm.get_installed():
if pkg.metadata.name not in names: skip_conds = [
pkg.metadata.name not in names,
pkg.metadata.spec.url,
pkg.metadata.name in required
and pkg.metadata.version in required[pkg.metadata.name],
]
if any(skip_conds):
continue continue
if ( try:
pkg.metadata.name not in deppkgs pm.uninstall(pkg.metadata.spec)
or pkg.metadata.version not in deppkgs[pkg.metadata.name] except UnknownPackageError:
): pass
try:
pm.uninstall(pkg.metadata.spec)
except UnknownPackageError:
pass
self.memcache_reset() self.memcache_reset()
return True return True