mirror of
https://github.com/ciromattia/kcc
synced 2025-12-13 17:56:30 +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 shutil import move, copy
|
||||
from . import rarfile
|
||||
from .shared import check7ZFile as is_7zfile
|
||||
from .shared import check7ZFile as is_7zfile, saferReplace
|
||||
|
||||
|
||||
class CBxArchive:
|
||||
@@ -101,7 +101,7 @@ class CBxArchive:
|
||||
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 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'
|
||||
move(os.path.join(targetdir, adir[0], f), targetdir)
|
||||
os.rmdir(os.path.join(targetdir, adir[0]))
|
||||
|
||||
@@ -42,7 +42,7 @@ try:
|
||||
from PyQt5 import QtCore
|
||||
except ImportError:
|
||||
QtCore = None
|
||||
from .shared import md5Checksum, getImageFileName, walkLevel
|
||||
from .shared import md5Checksum, getImageFileName, walkLevel, saferReplace
|
||||
from . import comic2panel
|
||||
from . import image
|
||||
from . import cbxarchive
|
||||
@@ -718,7 +718,7 @@ def sanitizeTree(filetree):
|
||||
newKey = os.path.join(root, slugified + splitname[1])
|
||||
key = os.path.join(root, name)
|
||||
if key != newKey:
|
||||
os.replace(key, newKey)
|
||||
saferReplace(key, newKey)
|
||||
for name in dirs:
|
||||
tmpName = name
|
||||
slugified = slugify(name)
|
||||
@@ -728,7 +728,7 @@ def sanitizeTree(filetree):
|
||||
newKey = os.path.join(root, slugified)
|
||||
key = os.path.join(root, name)
|
||||
if key != newKey:
|
||||
os.replace(key, newKey)
|
||||
saferReplace(key, newKey)
|
||||
return chapterNames
|
||||
|
||||
|
||||
@@ -747,7 +747,7 @@ def sanitizeTreeKobo(filetree):
|
||||
newKey = os.path.join(root, slugified + splitname[1])
|
||||
key = os.path.join(root, name)
|
||||
if key != newKey:
|
||||
os.replace(key, newKey)
|
||||
saferReplace(key, newKey)
|
||||
|
||||
|
||||
def sanitizePermissions(filetree):
|
||||
|
||||
@@ -21,6 +21,7 @@ from hashlib import md5
|
||||
from html.parser import HTMLParser
|
||||
from distutils.version import StrictVersion
|
||||
from scandir import walk
|
||||
from time import sleep
|
||||
|
||||
|
||||
class HTMLStripper(HTMLParser):
|
||||
@@ -74,6 +75,18 @@ def check7ZFile(filePath):
|
||||
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
|
||||
def dependencyCheck(level):
|
||||
missing = []
|
||||
|
||||
Reference in New Issue
Block a user