]> xmof Git - DeDRM.git/commitdiff
Fix automatic import of decryption keys on Linux with wine
authorAdam Plaice <plaice.adam+github@gmail.com>
Wed, 12 Jun 2019 19:13:25 +0000 (21:13 +0200)
committerAdam Plaice <plaice.adam+github@gmail.com>
Wed, 12 Jun 2019 19:13:25 +0000 (21:13 +0200)
By default, the wineprefix passed to WineGetKeys is "". Unfortunately,

    os.path.abspath(os.path.expanduser(os.path.expandvars("")))

returns the path to the working directory, which depends on the
directory from which calibre was invoked.  Hence under current
behaviour the wineprefix becomes that path, no longer being the empty
string.  This means that the `cmdline` that's run is always
`WINEPREFIX=/some/path/ wine python.exe [...]`, rather than `wine
python.exe [...]` even under default conditions, when the wineprefix
hasn't been changed.  Unless the user is improbably lucky and invokes
calibre from ~/.wine/ (the default wineprefix), this causes automatic
retrieval of the keys to always fail.

The bug was introduced in f2190a67558a.

Checking for "" allows for correct behaviour in the default case,
while keeping the nice behaviour of expanding `~`.

dedrm_src/wineutils.py

index 0485e5e1769a7b8d9f885b9dd80e900d4d7c95e7..c45572158d9e0ad60b06facc8a7ba25dcdf3069e 100644 (file)
@@ -26,7 +26,9 @@ def WineGetKeys(scriptpath, extension, wineprefix=""):
     if not os.path.exists(outdirpath):
         os.makedirs(outdirpath)
 
-    wineprefix = os.path.abspath(os.path.expanduser(os.path.expandvars(wineprefix)))
+    if wineprefix != "":
+        wineprefix = os.path.abspath(os.path.expanduser(os.path.expandvars(wineprefix)))
+
     if wineprefix != "" and os.path.exists(wineprefix):
          cmdline = u"WINEPREFIX=\"{2}\" wine python.exe \"{0}\" \"{1}\"".format(scriptpath,outdirpath,wineprefix)
     else: