diff --git a/pisi/atomicoperations.py b/pisi/atomicoperations.py index e6121cab..172ba189 100644 --- a/pisi/atomicoperations.py +++ b/pisi/atomicoperations.py @@ -137,8 +137,9 @@ class Install(AtomicOperation): self.filesdb = pisi.db.filesdb.FilesDB() self.installdb = pisi.db.installdb.InstallDB() self.operation = INSTALL + self.store_old_paths = None - def install(self, ask_reinstall = True): + def install(self, ask_reinstall=True): # Any package should remove the package it replaces before self.check_replaces() @@ -244,6 +245,10 @@ class Install(AtomicOperation): else: pkg_version = pisi.version.make_version(pkg.version) iversion = pisi.version.make_version(iversion_s) + if ctx.get_option('store_lib_info') and pkg_version > iversion: + self.store_old_paths = os.path.join(ctx.config.old_paths_cache_dir(), pkg.name) + ctx.ui.info(_('Storing old paths info')) + open(self.store_old_paths, "w").write("Version: %s\n" % iversion_s) pkg_release = int(pkg.release) irelease = int(irelease_s) @@ -274,7 +279,7 @@ class Install(AtomicOperation): self.old_files = self.installdb.get_files(pkg.name) self.old_pkginfo = self.installdb.get_info(pkg.name) self.old_path = self.installdb.pkg_dir(pkg.name, iversion_s, irelease_s) - self.remove_old = Remove(pkg.name) + self.remove_old = Remove(pkg.name, store_old_paths = self.store_old_paths) self.remove_old.run_preremove() self.remove_old.run_postremove() @@ -446,7 +451,7 @@ class Install(AtomicOperation): if os.path.samestat(new_file_stat, old_file_stat): break else: - Remove.remove_file(old_file, self.pkginfo.name) + Remove.remove_file(old_file, self.pkginfo.name, store_old_paths=self.store_old_paths) if self.reinstall(): # get 'config' typed file objects @@ -554,12 +559,13 @@ def install_single_name(name, upgrade = False): class Remove(AtomicOperation): - def __init__(self, package_name, ignore_dep = None): + def __init__(self, package_name, ignore_dep=None, store_old_paths=None): super(Remove, self).__init__(ignore_dep) self.installdb = pisi.db.installdb.InstallDB() self.filesdb = pisi.db.filesdb.FilesDB() self.package_name = package_name self.package = self.installdb.get_package(self.package_name) + self.store_old_paths = store_old_paths try: self.files = self.installdb.get_files(self.package_name) except pisi.Error as e: @@ -599,7 +605,7 @@ class Remove(AtomicOperation): # is there any package who depends on this package? @staticmethod - def remove_file(fileinfo, package_name, remove_permanent=False): + def remove_file(fileinfo, package_name, remove_permanent=False, store_old_paths=None): if fileinfo.permanent and not remove_permanent: return @@ -640,6 +646,8 @@ class Remove(AtomicOperation): else: if os.path.isfile(fpath) or os.path.islink(fpath): os.unlink(fpath) + if store_old_paths: + open(store_old_paths, "a").write("%s\n" % fpath) elif os.path.isdir(fpath) and not os.listdir(fpath): os.rmdir(fpath) else: diff --git a/pisi/cli/install.py b/pisi/cli/install.py index d92751b5..ec101d3e 100644 --- a/pisi/cli/install.py +++ b/pisi/cli/install.py @@ -65,6 +65,9 @@ expanded to package names. help=_("When installing packages, ignore packages " "and components whose basenames match " "any pattern contained in file.")) + group.add_option("-s", "--store-lib-info", action="store_true", + default=False, + help=_("Store previous libraries info when package is updating to newer version.")) self.parser.add_option_group(group) def run(self): diff --git a/pisi/config.py b/pisi/config.py index 0c36b851..83576ca3 100644 --- a/pisi/config.py +++ b/pisi/config.py @@ -130,6 +130,9 @@ class Config(object, metaclass=pisi.util.Singleton): def debug_packages_dir(self): return self.subdir(self.values.dirs.debug_packages_dir) + def old_paths_cache_dir(self): + return self.subdir(self.values.dirs.old_paths_cache_dir) + def index_dir(self): return self.subdir(self.values.dirs.index_dir) diff --git a/pisi/configfile.py b/pisi/configfile.py index be9bd894..51bbfbff 100644 --- a/pisi/configfile.py +++ b/pisi/configfile.py @@ -129,6 +129,7 @@ class DirectoriesDefaults: cached_packages_dir = "/var/cache/pisi/packages" compiled_packages_dir = "/var/cache/pisi/packages" debug_packages_dir = "/var/cache/pisi/packages-debug" + old_paths_cache_dir = "/var/cache/pisi/old-paths" packages_dir = "/var/lib/pisi/package" lock_dir = "/var/lock/subsys" index_dir = "/var/lib/pisi/index" diff --git a/pisi/db/repodb.py b/pisi/db/repodb.py index 16c62982..588f664c 100644 --- a/pisi/db/repodb.py +++ b/pisi/db/repodb.py @@ -149,7 +149,7 @@ class RepoDB(lazydb.LazyDB): def has_repo(self, name): return name in self.list_repos(only_active=False) - def has_repo_url(self, url, only_active = True): + def has_repo_url(self, url, only_active=True): return url in self.list_repo_urls(only_active) def get_repo_doc(self, repo_name): diff --git a/scripts/revdep-rebuild b/scripts/revdep-rebuild index 32febf14..bd62ab75 100755 --- a/scripts/revdep-rebuild +++ b/scripts/revdep-rebuild @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # -*- coding: utf-8 -*- # # Author: Marcin Bojara @@ -94,7 +94,7 @@ if __name__ == "__main__": ver = f.readline().split(":").pop().strip() paths = [l.strip() for l in f.readlines()] oldpkgfs["%s-%s (previous)" % (ls, ver)] = paths - except AttributeError: + except AttributeError as e: print("%sYour pisi version is too old.%s" % (GR, NO)) print(" done.") @@ -116,7 +116,7 @@ if __name__ == "__main__": soname_search = args sonames = " ".join(soname_search) m = hashlib.md5() - m.update(sonames) + m.update(sonames.encode()) llist = LIST + "_" + m.hexdigest()[:8] head_text = "using given shared object(s) name" ok_text = "There are no dynamic links to %s" % sonames @@ -180,7 +180,7 @@ if __name__ == "__main__": continue p = subprocess.Popen('LD_LIBRARY_PATH="$COMPLETE_LD_LIBRARY_PATH" ldd %s' % f, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() - for line in out.split("\n"): + for line in out.decode().split("\n"): if "=>" in line: src, dst = line.split("=>") src = src.strip()