Skip to content

Commit 6064621

Browse files
committed
Fix symlinks being replaced with files on save
Fixes #5478
1 parent c209e33 commit 6064621

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

arduino-core/src/processing/app/BaseNoGui.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -1061,11 +1061,23 @@ 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 canon = file.getCanonicalFile();
1077+
file = canon;
1078+
} catch (IOException e) {
1079+
}
1080+
10691081
if (file.exists()) {
10701082
boolean result = file.delete();
10711083
if (!result) {

0 commit comments

Comments
 (0)