From adcc2c5539908e28fc93f9e7f3c3cc7ecc4ecc09 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 9 May 2019 21:25:55 -0400 Subject: [PATCH] install: fix calibre-uninstall relying on the source tree Injecting the location of the mime_resources file from P() in non-frozen builds will depend on the mime resource from the source tree rather than the same location during install time... a source tree which may be deleted after successful installation. On a frozen build, or when using 'develop' instead of 'install', this path will be the same, and things just work. The solution is to add *both* paths, and try to uninstall whichever one exists. --- src/calibre/linux.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/calibre/linux.py b/src/calibre/linux.py index df9a153820..8c8d31fc3e 100644 --- a/src/calibre/linux.py +++ b/src/calibre/linux.py @@ -127,11 +127,12 @@ if not frozen_path or not os.path.exists(os.path.join(frozen_path, 'resources', frozen_path = None for f in {mime_resources!r}: - cmd = ['xdg-mime', 'uninstall', f] - print ('Removing mime resource:', os.path.basename(f)) - ret = subprocess.call(cmd, shell=False) - if ret != 0: - print ('WARNING: Failed to remove mime resource', f) + if os.path.exists(f): + cmd = ['xdg-mime', 'uninstall', f] + print ('Removing mime resource:', os.path.basename(f)) + ret = subprocess.call(cmd, shell=False) + if ret != 0: + print ('WARNING: Failed to remove mime resource', f) for x in tuple({manifest!r}) + tuple({appdata_resources!r}) + (os.path.abspath(__file__), __file__, frozen_path): if not x or not os.path.exists(x): @@ -890,14 +891,16 @@ class PostInstall: ak = x.partition('.')[0] if ak in APPDATA and os.access(appdata, os.W_OK): self.appdata_resources.append(write_appdata(ak, APPDATA[ak], appdata, translators)) - MIME = P('calibre-mimetypes.xml') + MIME_BASE = 'calibre-mimetypes.xml' + MIME = P(MIME_BASE) self.mime_resources.append(MIME) + self.mime_resources.append(os.path.join(self.opts.staging_sharedir, MIME_BASE)) if not getattr(self.opts, 'staged_install', False): cc(['xdg-mime', 'install', MIME]) cc(['xdg-desktop-menu', 'forceupdate']) else: from shutil import copyfile - copyfile(MIME, os.path.join(env['XDG_DATA_DIRS'], 'mime', 'packages', os.path.basename(MIME))) + copyfile(MIME, os.path.join(env['XDG_DATA_DIRS'], 'mime', 'packages', MIME_BASE)) except Exception: if self.opts.fatal_errors: raise