File tree 1 file changed +13
-1
lines changed
arduino-core/src/processing/app
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -1061,11 +1061,23 @@ static public String sanitizeName(String origName) {
1061
1061
}
1062
1062
1063
1063
/**
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
1065
1070
*/
1066
1071
static public void saveFile (String str , File file ) throws IOException {
1067
1072
File temp = File .createTempFile (file .getName (), null , file .getParentFile ());
1068
1073
PApplet .saveStrings (temp , new String [] { str });
1074
+
1075
+ try {
1076
+ File canon = file .getCanonicalFile ();
1077
+ file = canon ;
1078
+ } catch (IOException e ) {
1079
+ }
1080
+
1069
1081
if (file .exists ()) {
1070
1082
boolean result = file .delete ();
1071
1083
if (!result ) {
You can’t perform that action at this time.
0 commit comments