mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-11 00:12:24 +12:00
Fix crash when files are locked for writing (Fixes olivierkes#950)
Wrap file opens in try-catch Applied fix for project file as well as other files that are opened during save
This commit is contained in:
parent
0182a43b8e
commit
37667ed70f
|
@ -327,7 +327,6 @@ def saveProject(zip=None):
|
|||
# Save to plain text
|
||||
|
||||
else:
|
||||
|
||||
global cache
|
||||
|
||||
# Project path
|
||||
|
@ -378,11 +377,17 @@ def saveProject(zip=None):
|
|||
LOGGER.debug("* Writing file {} ({})".format(path, "not in cache" if path not in cache else "different"))
|
||||
# mode = "w" + ("b" if type(content) == bytes else "")
|
||||
if type(content) == bytes:
|
||||
with open(filename, "wb") as f:
|
||||
f.write(content)
|
||||
try:
|
||||
with open(filename, "wb") as f:
|
||||
f.write(content)
|
||||
except PermissionError as e:
|
||||
LOGGER.error("Cannot open file " + filename + " for writing: " + e.strerror)
|
||||
else:
|
||||
with open(filename, "w", encoding='utf8') as f:
|
||||
f.write(content)
|
||||
try:
|
||||
with open(filename, "w", encoding='utf8') as f:
|
||||
f.write(content)
|
||||
except PermissionError as e:
|
||||
LOGGER.error("Cannot open file " + filename + " for writing: " + e.strerror)
|
||||
|
||||
cache[path] = content
|
||||
|
||||
|
@ -412,8 +417,12 @@ def saveProject(zip=None):
|
|||
pass
|
||||
|
||||
# Write the project file's content
|
||||
with open(project, "w", encoding='utf8') as f:
|
||||
f.write("1") # Format number
|
||||
try:
|
||||
with open(project, "w", encoding='utf8') as f:
|
||||
f.write("1") # Format number
|
||||
except PermissionError as e:
|
||||
LOGGER.error("Cannot open file " + project + " for writing: " + e.strerror)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
|
Loading…
Reference in a new issue