mirror of
https://github.com/ciromattia/kcc
synced 2025-12-14 02:06:40 +00:00
Yet another workaround for file lock problems (#125)
This commit is contained in:
@@ -23,7 +23,7 @@ from subprocess import STDOUT, PIPE
|
|||||||
from psutil import Popen
|
from psutil import Popen
|
||||||
from shutil import move, copy
|
from shutil import move, copy
|
||||||
from . import rarfile
|
from . import rarfile
|
||||||
from .shared import check7ZFile as is_7zfile
|
from .shared import check7ZFile as is_7zfile, saferReplace
|
||||||
|
|
||||||
|
|
||||||
class CBxArchive:
|
class CBxArchive:
|
||||||
@@ -101,7 +101,7 @@ class CBxArchive:
|
|||||||
for f in os.listdir(os.path.join(targetdir, adir[0])):
|
for f in os.listdir(os.path.join(targetdir, adir[0])):
|
||||||
# If directory names contain UTF-8 chars shutil.move can't clean up the mess alone
|
# If directory names contain UTF-8 chars shutil.move can't clean up the mess alone
|
||||||
if os.path.isdir(os.path.join(targetdir, f)):
|
if os.path.isdir(os.path.join(targetdir, f)):
|
||||||
os.replace(os.path.join(targetdir, adir[0], f), os.path.join(targetdir, adir[0], f + '-A'))
|
saferReplace(os.path.join(targetdir, adir[0], f), os.path.join(targetdir, adir[0], f + '-A'))
|
||||||
f += '-A'
|
f += '-A'
|
||||||
move(os.path.join(targetdir, adir[0], f), targetdir)
|
move(os.path.join(targetdir, adir[0], f), targetdir)
|
||||||
os.rmdir(os.path.join(targetdir, adir[0]))
|
os.rmdir(os.path.join(targetdir, adir[0]))
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ try:
|
|||||||
from PyQt5 import QtCore
|
from PyQt5 import QtCore
|
||||||
except ImportError:
|
except ImportError:
|
||||||
QtCore = None
|
QtCore = None
|
||||||
from .shared import md5Checksum, getImageFileName, walkLevel
|
from .shared import md5Checksum, getImageFileName, walkLevel, saferReplace
|
||||||
from . import comic2panel
|
from . import comic2panel
|
||||||
from . import image
|
from . import image
|
||||||
from . import cbxarchive
|
from . import cbxarchive
|
||||||
@@ -718,7 +718,7 @@ def sanitizeTree(filetree):
|
|||||||
newKey = os.path.join(root, slugified + splitname[1])
|
newKey = os.path.join(root, slugified + splitname[1])
|
||||||
key = os.path.join(root, name)
|
key = os.path.join(root, name)
|
||||||
if key != newKey:
|
if key != newKey:
|
||||||
os.replace(key, newKey)
|
saferReplace(key, newKey)
|
||||||
for name in dirs:
|
for name in dirs:
|
||||||
tmpName = name
|
tmpName = name
|
||||||
slugified = slugify(name)
|
slugified = slugify(name)
|
||||||
@@ -728,7 +728,7 @@ def sanitizeTree(filetree):
|
|||||||
newKey = os.path.join(root, slugified)
|
newKey = os.path.join(root, slugified)
|
||||||
key = os.path.join(root, name)
|
key = os.path.join(root, name)
|
||||||
if key != newKey:
|
if key != newKey:
|
||||||
os.replace(key, newKey)
|
saferReplace(key, newKey)
|
||||||
return chapterNames
|
return chapterNames
|
||||||
|
|
||||||
|
|
||||||
@@ -747,7 +747,7 @@ def sanitizeTreeKobo(filetree):
|
|||||||
newKey = os.path.join(root, slugified + splitname[1])
|
newKey = os.path.join(root, slugified + splitname[1])
|
||||||
key = os.path.join(root, name)
|
key = os.path.join(root, name)
|
||||||
if key != newKey:
|
if key != newKey:
|
||||||
os.replace(key, newKey)
|
saferReplace(key, newKey)
|
||||||
|
|
||||||
|
|
||||||
def sanitizePermissions(filetree):
|
def sanitizePermissions(filetree):
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ from hashlib import md5
|
|||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
from distutils.version import StrictVersion
|
from distutils.version import StrictVersion
|
||||||
from scandir import walk
|
from scandir import walk
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
class HTMLStripper(HTMLParser):
|
class HTMLStripper(HTMLParser):
|
||||||
@@ -74,6 +75,18 @@ def check7ZFile(filePath):
|
|||||||
return header == b"7z\xbc\xaf'\x1c"
|
return header == b"7z\xbc\xaf'\x1c"
|
||||||
|
|
||||||
|
|
||||||
|
def saferReplace(old, new):
|
||||||
|
for x in range(5):
|
||||||
|
try:
|
||||||
|
os.replace(old, new)
|
||||||
|
except PermissionError:
|
||||||
|
sleep(5)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise PermissionError
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
def dependencyCheck(level):
|
def dependencyCheck(level):
|
||||||
missing = []
|
missing = []
|
||||||
|
|||||||
Reference in New Issue
Block a user