From 2725d8da8b8b00e5c7f406e54fea81b6a005b93f Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 21 Jun 2018 21:33:56 +0300 Subject: [PATCH] Fix issue when "platformio lib uninstall" removes initial source code // Resolve #1023 --- HISTORY.rst | 4 ++++ platformio/managers/package.py | 12 +++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index ab8364483e..afb027ec68 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -16,6 +16,10 @@ PlatformIO 3.0 * Fixed issue with invalid LD script if path contains space * Fixed preprocessor for Arduino sketch when function returns certain type (`issue #1683 `_) +* Fixed issue when ` +platformio lib uninstall `__ + removes initial source code + (`issue #1023 `_) 3.5.3 (2018-06-01) ~~~~~~~~~~~~~~~~~~ diff --git a/platformio/managers/package.py b/platformio/managers/package.py index 5833198057..dd26f00000 100644 --- a/platformio/managers/package.py +++ b/platformio/managers/package.py @@ -18,7 +18,7 @@ import os import re import shutil -from os.path import basename, getsize, isdir, isfile, islink, join +from os.path import abspath, basename, getsize, isdir, isfile, islink, join from tempfile import mkdtemp import click @@ -367,6 +367,12 @@ def get_package_dir(self, name, requirements=None, url=None): return manifest.get("__pkg_dir") if manifest and isdir( manifest.get("__pkg_dir")) else None + def get_package_by_dir(self, pkg_dir): + for manifest in self.get_installed(): + if manifest['__pkg_dir'] == util.path_to_unicode(abspath(pkg_dir)): + return manifest + return None + def find_pkg_root(self, src_dir): if self.manifest_exists(src_dir): return src_dir @@ -715,7 +721,7 @@ def install(self, return pkg_dir def uninstall(self, package, requirements=None, after_update=False): - if isdir(package): + if isdir(package) and self.get_package_by_dir(package): pkg_dir = package else: name, requirements, url = self.parse_pkg_uri(package, requirements) @@ -755,7 +761,7 @@ def uninstall(self, package, requirements=None, after_update=False): return True def update(self, package, requirements=None, only_check=False): - if isdir(package): + if isdir(package) and self.get_package_by_dir(package): pkg_dir = package else: pkg_dir = self.get_package_dir(*self.parse_pkg_uri(package))