From 1aecd238525315197bdc88f2878836a07ebd605b Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 12 May 2019 09:35:53 -0400 Subject: [PATCH] calibre-uninstall: be even more thorough about deleting mime files Since xdg-mime only cares about basename(filename) and that filename is an existing file (and we don't know where the installed one is), create an empty file with the right name and then delete that. --- src/calibre/linux.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/calibre/linux.py b/src/calibre/linux.py index 6d692c61ce..3805877aa0 100644 --- a/src/calibre/linux.py +++ b/src/calibre/linux.py @@ -110,7 +110,7 @@ UNINSTALL = '''\ from __future__ import print_function, unicode_literals euid = {euid} -import os, subprocess, shutil +import os, subprocess, shutil, tempfile try: raw_input @@ -126,15 +126,18 @@ frozen_path = {frozen_path!r} if not frozen_path or not os.path.exists(os.path.join(frozen_path, 'resources', 'calibre-mimetypes.xml')): frozen_path = None +dummy_mime_path = tempfile.mkdtemp(prefix='mime-hack.') for f in {mime_resources!r}: - 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) + # dummyfile + file = os.path.join(dummy_mime_path, f) + open(file, 'w').close() + cmd = ['xdg-mime', 'uninstall', file] + print ('Removing mime resource:', 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): +for x in tuple({manifest!r}) + tuple({appdata_resources!r}) + (os.path.abspath(__file__), __file__, frozen_path, dummy_mime_path): if not x or not os.path.exists(x): continue print ('Removing', x) @@ -894,8 +897,7 @@ class PostInstall: self.appdata_resources.append(write_appdata(ak, APPDATA[ak], appdata, translators)) 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)) + self.mime_resources.append(MIME_BASE) if not getattr(self.opts, 'staged_install', False): cc(['xdg-mime', 'install', MIME]) cc(['xdg-desktop-menu', 'forceupdate'])