mirror of
https://github.com/Leseratte10/acsm-calibre-plugin.git
synced 2024-12-22 17:29:56 +06:00
Fix race condition when importing multiple files at once
This commit is contained in:
parent
1f61d972f5
commit
a7290b536a
@ -30,7 +30,7 @@ __version__ = PLUGIN_VERSION = ".".join([str(x)for x in PLUGIN_VERSION_TUPLE])
|
||||
|
||||
from calibre.utils.config import config_dir # type: ignore
|
||||
|
||||
import os, shutil, traceback, sys, time
|
||||
import os, shutil, traceback, sys, time, io
|
||||
import zipfile
|
||||
from lxml import etree
|
||||
|
||||
@ -74,12 +74,10 @@ class DeACSM(FileTypePlugin):
|
||||
if not os.path.exists(self.maindir):
|
||||
os.mkdir(self.maindir)
|
||||
|
||||
# Re-Extract modules
|
||||
# Extract new modules
|
||||
|
||||
self.moddir = os.path.join(self.maindir,"modules")
|
||||
if os.path.exists(self.moddir):
|
||||
shutil.rmtree(self.moddir, ignore_errors=True)
|
||||
|
||||
if not os.path.exists(self.moddir):
|
||||
os.mkdir(self.moddir)
|
||||
|
||||
names = ["cryptography.zip", "rsa.zip", "oscrypto.zip", "asn1crypto.zip", "pyasn1.zip"]
|
||||
@ -90,15 +88,8 @@ class DeACSM(FileTypePlugin):
|
||||
for entry, data in lib_dict.items():
|
||||
file_path = os.path.join(self.moddir, entry)
|
||||
try:
|
||||
os.remove(file_path)
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
open(file_path,'wb').write(data)
|
||||
with zipfile.ZipFile(file_path, 'r') as ref:
|
||||
with zipfile.ZipFile(io.BytesIO(data), 'r') as ref:
|
||||
ref.extractall(self.moddir)
|
||||
os.remove(file_path)
|
||||
|
||||
except:
|
||||
print("{0} v{1}: Exception when copying needed library files".format(PLUGIN_NAME, PLUGIN_VERSION))
|
||||
|
Loading…
Reference in New Issue
Block a user