From 0789d62ec7b438d1b0cb92e3ae0510a82345bd3b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 13 Dec 2015 16:30:31 +0530 Subject: [PATCH] Workaround for windows' crazy file locking model --- src/calibre/ebooks/oeb/polish/container.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/oeb/polish/container.py b/src/calibre/ebooks/oeb/polish/container.py index 7f2a09e939..a6ea5b0186 100644 --- a/src/calibre/ebooks/oeb/polish/container.py +++ b/src/calibre/ebooks/oeb/polish/container.py @@ -7,7 +7,7 @@ __license__ = 'GPL v3' __copyright__ = '2013, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import os, logging, sys, hashlib, uuid, re, shutil, unicodedata, errno +import os, logging, sys, hashlib, uuid, re, shutil, unicodedata, errno, time from collections import defaultdict from io import BytesIO from urlparse import urlparse @@ -17,6 +17,7 @@ from lxml import etree from cssutils import replaceUrls, getUrls from calibre import CurrentDir +from calibre.constants import iswindows from calibre.customize.ui import (plugin_for_input_format, plugin_for_output_format) from calibre.ebooks.chardet import xml_to_unicode from calibre.ebooks.conversion.plugins.epub_input import ( @@ -878,7 +879,13 @@ class Container(object): # {{{ # Decouple this file from its links temp = path + 'xxx' shutil.copyfile(path, temp) - os.unlink(path) + try: + os.unlink(path) + except EnvironmentError: + if not iswindows: + raise + time.sleep(1) # Wait for whatever has locked the file to release it + os.unlink(path) os.rename(temp, path) return path