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

Corrupted jclic.zip file if image not found when saving #26

Closed
ferrarimartin opened this issue Jul 29, 2018 · 2 comments
Closed

Corrupted jclic.zip file if image not found when saving #26

ferrarimartin opened this issue Jul 29, 2018 · 2 comments

Comments

@ferrarimartin
Copy link

 When saving a file to jclic.zip format by using JClic author, if there's a resource (for example, an image) that's missing, the target jclic.zip file starts being written, but when the resource would be saved, an error appears, writing stops at that point, and the output  zip file gets corrupted and can't be opened.
 This could happen if for example an image from a usb drive was included, and the drive removed before saving.
  It would be good if the behavior was less drastic, because if the user closes Jclic at that point, their work is lost.
@frncesc
Copy link
Member

frncesc commented Aug 6, 2018

Class edu.xtec.jclic.FileSystem#SecureFileOutputStream has been modified to avoid this kind of errors. The original workflow when saving projects was:

1 - Create a temporary ZIP file
2 - Write the project definition (.jclic file) and needed ingredients (images, sounds...) into this temporary file.
3 - If something goes wrong, catch the exception and notify the user about the error found. The project state remains as "unsaved", and the original file has been not modified.
4 - From here, we assume that everything went well. The temporary ZIP file contains the saved project and is in good condition.
5 - Replace the original project file with the temporary ZIP file. This is done deleting the original file and, then, renaming the temporary.

In some cases, and for unknown reasons, the assertion made in step 4 is not met. Actually, the temporary file is corrupted and no error or exception is thrown by the Java engine. This results in the loss of the original project.

Now, since JClic v0.3.2.0, we perform an additional step:

2b - Open the temporary file, read its the ZIP directory and check for empty or inaccessible files inside it. If something goes wrong, throw an IOException.

Hope this will reduce the risk of producing corrupted files when saving projects. Please notify us if the problem appears again.

Thanks for reporting!

@frncesc frncesc closed this as completed Aug 6, 2018
@ferrarimartin
Copy link
Author

Thank you so much Francesc.
I've added some missing translations for portuguese in launchpad, in case they are useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants