From 6f87c59b7baa06359b5405edc881d3dc39d364f3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 28 Jan 2018 08:08:43 +0530 Subject: [PATCH] Replace use of CreateFile with CreateFileW --- src/calibre/utils/lock.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/calibre/utils/lock.py b/src/calibre/utils/lock.py index bc86b3c4a6..fff9b261a1 100644 --- a/src/calibre/utils/lock.py +++ b/src/calibre/utils/lock.py @@ -49,8 +49,10 @@ def unix_retry(err): def windows_open(path): + if isinstance(path, bytes): + path = path.decode('mbcs') try: - h = win32file.CreateFile( + h = win32file.CreateFileW( path, win32file.GENERIC_READ | win32file.GENERIC_WRITE, # Open for reading and writing @@ -86,9 +88,8 @@ def retry_for_a_time(timeout, sleep_time, func, error_retry, *args): class ExclusiveFile(object): def __init__(self, path, timeout=15, sleep_time=0.2): - if iswindows: - if isinstance(path, bytes): - path = path.decode(filesystem_encoding) + if iswindows and isinstance(path, bytes): + path = path.decode(filesystem_encoding) self.path = path self.timeout = timeout self.sleep_time = sleep_time