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.
This commit is contained in:
Eli Schwartz 2019-05-12 09:35:53 -04:00
parent ae02c30a17
commit 1aecd23852
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6

View File

@ -110,7 +110,7 @@ UNINSTALL = '''\
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
euid = {euid} euid = {euid}
import os, subprocess, shutil import os, subprocess, shutil, tempfile
try: try:
raw_input 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')): if not frozen_path or not os.path.exists(os.path.join(frozen_path, 'resources', 'calibre-mimetypes.xml')):
frozen_path = None frozen_path = None
dummy_mime_path = tempfile.mkdtemp(prefix='mime-hack.')
for f in {mime_resources!r}: for f in {mime_resources!r}:
if os.path.exists(f): # dummyfile
cmd = ['xdg-mime', 'uninstall', f] file = os.path.join(dummy_mime_path, f)
print ('Removing mime resource:', os.path.basename(f)) open(file, 'w').close()
ret = subprocess.call(cmd, shell=False) cmd = ['xdg-mime', 'uninstall', file]
if ret != 0: print ('Removing mime resource:', f)
print ('WARNING: Failed to remove 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): if not x or not os.path.exists(x):
continue continue
print ('Removing', x) print ('Removing', x)
@ -894,8 +897,7 @@ class PostInstall:
self.appdata_resources.append(write_appdata(ak, APPDATA[ak], appdata, translators)) self.appdata_resources.append(write_appdata(ak, APPDATA[ak], appdata, translators))
MIME_BASE = 'calibre-mimetypes.xml' MIME_BASE = 'calibre-mimetypes.xml'
MIME = P(MIME_BASE) MIME = P(MIME_BASE)
self.mime_resources.append(MIME) self.mime_resources.append(MIME_BASE)
self.mime_resources.append(os.path.join(self.opts.staging_sharedir, MIME_BASE))
if not getattr(self.opts, 'staged_install', False): if not getattr(self.opts, 'staged_install', False):
cc(['xdg-mime', 'install', MIME]) cc(['xdg-mime', 'install', MIME])
cc(['xdg-desktop-menu', 'forceupdate']) cc(['xdg-desktop-menu', 'forceupdate'])