mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-21 05:12:27 +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
|
# Save to plain text
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
global cache
|
global cache
|
||||||
|
|
||||||
# Project path
|
# 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"))
|
LOGGER.debug("* Writing file {} ({})".format(path, "not in cache" if path not in cache else "different"))
|
||||||
# mode = "w" + ("b" if type(content) == bytes else "")
|
# mode = "w" + ("b" if type(content) == bytes else "")
|
||||||
if type(content) == bytes:
|
if type(content) == bytes:
|
||||||
with open(filename, "wb") as f:
|
try:
|
||||||
f.write(content)
|
with open(filename, "wb") as f:
|
||||||
|
f.write(content)
|
||||||
|
except PermissionError as e:
|
||||||
|
LOGGER.error("Cannot open file " + filename + " for writing: " + e.strerror)
|
||||||
else:
|
else:
|
||||||
with open(filename, "w", encoding='utf8') as f:
|
try:
|
||||||
f.write(content)
|
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
|
cache[path] = content
|
||||||
|
|
||||||
|
@ -412,8 +417,12 @@ def saveProject(zip=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Write the project file's content
|
# Write the project file's content
|
||||||
with open(project, "w", encoding='utf8') as f:
|
try:
|
||||||
f.write("1") # Format number
|
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
|
return True
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue