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 @@ -1061,11 +1061,22 @@ static public String sanitizeName(String origName) {
10611061 }
10621062
10631063 /**
1064- * Spew the contents of a String object out to a file.
1064+ * Save the content of a String into a file
1065+ * - Save the content into a temp file
1066+ * - Find the canonical path of the file (if it's a symlink, follow it)
1067+ * - Remove the original file
1068+ * - Move temp file to original path
1069+ * This ensures that the file is not getting truncated if the disk is full
10651070 */
10661071 static public void saveFile (String str , File file ) throws IOException {
10671072 File temp = File .createTempFile (file .getName (), null , file .getParentFile ());
10681073 PApplet .saveStrings (temp , new String [] { str });
1074+
1075+ try {
1076+ file = file .getCanonicalFile ();
1077+ } catch (IOException e ) {
1078+ }
1079+
10691080 if (file .exists ()) {
10701081 boolean result = file .delete ();
10711082 if (!result ) {
You can’t perform that action at this time.
0 commit comments