Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove partially exported file on hard drive #897

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 35 additions & 30 deletions plugins/LocalFileOutputDevice/LocalFileOutputDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,36 +196,41 @@ def _onJobProgress(self, job, progress):
self.writeProgress.emit(self, progress)

def _onWriteJobFinished(self, job):
self._writing = False
self.writeFinished.emit(self)
if job.getResult():
self.writeSuccess.emit(self)
message = Message(
catalog.i18nc("@info:status Don't translate the XML tags <filename>!", "Saved to <filename>{0}</filename>").format(job.getFileName()),
title = catalog.i18nc("@info:title", "File Saved"),
message_type = Message.MessageType.POSITIVE)
message.addAction("open_folder", catalog.i18nc("@action:button", "Open Folder"), "open-folder", catalog.i18nc("@info:tooltip", "Open the folder containing the file"))
message._folder = os.path.dirname(job.getFileName())
message.actionTriggered.connect(self._onMessageActionTriggered)
message.show()
else:
message = Message(catalog.i18nc("@info:status Don't translate the XML tags <filename> or <message>!",
"Could not save to <filename>{0}</filename>: <message>{1}</message>").format(job.getFileName(), str(job.getError())),
lifetime = 0,
title = catalog.i18nc("@info:title", "Error"),
message_type = Message.MessageType.ERROR)
message.show()
self.writeError.emit(self)

try:
job.getStream().close()
except (OSError, PermissionError): #When you don't have the rights to do the final flush or the disk is full.
message = Message(catalog.i18nc("@info:status",
"Something went wrong saving to <filename>{0}</filename>: <message>{1}</message>").format(job.getFileName(), str(job.getError())),
title = catalog.i18nc("@info:title", "Error"),
message_type = Message.MessageType.ERROR)
message.show()
self.writeError.emit(self)
if job.getStream():
error = job.getError()
try:
# Explicitly closing the stream flushes the write-buffer
job.getStream().close()
except Exception as e:
if not error:
# Only log new error if there was no previous one
error = e

self._writing = False
self.writeFinished.emit(self)

if not error:
message = Message(
catalog.i18nc("@info:status Don't translate the XML tags <filename>!", "Saved to <filename>{0}</filename>").format(job.getFileName()),
title=catalog.i18nc("@info:title", "File Saved"),
message_type=Message.MessageType.POSITIVE)
message.addAction("open_folder", catalog.i18nc("@action:button", "Open Folder"), "open-folder", catalog.i18nc("@info:tooltip", "Open the folder containing the file"))
message._folder = os.path.dirname(job.getFileName())
message.actionTriggered.connect(self._onMessageActionTriggered)
message.show()
self.writeSuccess.emit(self)
else:
try:
os.remove(job.getFileName())
except Exception as e:
Logger.logException("e", "Exception when trying to remove incomplete exported file %s",
str(job.getFileName()))
message = Message(catalog.i18nc("@info:status Don't translate the XML tags <filename> or <message>!",
"Could not save to <filename>{0}</filename>: <message>{1}</message>").format(job.getFileName(), str(error)),
title=catalog.i18nc("@info:title", "Error"),
message_type=Message.MessageType.ERROR)
message.show()
self.writeError.emit(self)

def _onMessageActionTriggered(self, message, action):
if action == "open_folder" and hasattr(message, "_folder"):
Expand Down
Loading