mirror of
https://github.com/Leseratte10/acsm-calibre-plugin.git
synced 2024-12-23 01:34:36 +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
|
from calibre.utils.config import config_dir # type: ignore
|
||||||
|
|
||||||
import os, shutil, traceback, sys, time
|
import os, shutil, traceback, sys, time, io
|
||||||
import zipfile
|
import zipfile
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
@ -74,12 +74,10 @@ class DeACSM(FileTypePlugin):
|
|||||||
if not os.path.exists(self.maindir):
|
if not os.path.exists(self.maindir):
|
||||||
os.mkdir(self.maindir)
|
os.mkdir(self.maindir)
|
||||||
|
|
||||||
# Re-Extract modules
|
# Extract new modules
|
||||||
|
|
||||||
self.moddir = os.path.join(self.maindir,"modules")
|
self.moddir = os.path.join(self.maindir,"modules")
|
||||||
if os.path.exists(self.moddir):
|
if not os.path.exists(self.moddir):
|
||||||
shutil.rmtree(self.moddir, ignore_errors=True)
|
|
||||||
|
|
||||||
os.mkdir(self.moddir)
|
os.mkdir(self.moddir)
|
||||||
|
|
||||||
names = ["cryptography.zip", "rsa.zip", "oscrypto.zip", "asn1crypto.zip", "pyasn1.zip"]
|
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():
|
for entry, data in lib_dict.items():
|
||||||
file_path = os.path.join(self.moddir, entry)
|
file_path = os.path.join(self.moddir, entry)
|
||||||
try:
|
try:
|
||||||
os.remove(file_path)
|
with zipfile.ZipFile(io.BytesIO(data), 'r') as ref:
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
open(file_path,'wb').write(data)
|
|
||||||
with zipfile.ZipFile(file_path, 'r') as ref:
|
|
||||||
ref.extractall(self.moddir)
|
ref.extractall(self.moddir)
|
||||||
os.remove(file_path)
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print("{0} v{1}: Exception when copying needed library files".format(PLUGIN_NAME, PLUGIN_VERSION))
|
print("{0} v{1}: Exception when copying needed library files".format(PLUGIN_NAME, PLUGIN_VERSION))
|
||||||
|
Loading…
Reference in New Issue
Block a user