File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
arduino-core/src/processing/app Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -884,11 +884,22 @@ static public String sanitizeName(String origName) {
884884 }
885885
886886 /**
887- * Spew the contents of a String object out to a file.
887+ * Save the content of a String into a file
888+ * - Save the content into a temp file
889+ * - Find the canonical path of the file (if it's a symlink, follow it)
890+ * - Remove the original file
891+ * - Move temp file to original path
892+ * This ensures that the file is not getting truncated if the disk is full
888893 */
889894 static public void saveFile (String str , File file ) throws IOException {
890895 File temp = File .createTempFile (file .getName (), null , file .getParentFile ());
891896 PApplet .saveStrings (temp , new String [] { str });
897+
898+ try {
899+ file = file .getCanonicalFile ();
900+ } catch (IOException e ) {
901+ }
902+
892903 if (file .exists ()) {
893904 boolean result = file .delete ();
894905 if (!result ) {
You can’t perform that action at this time.
0 commit comments