Skip to content

Commit a93b45d

Browse files
authored
Merge pull request #5573 from facchinm/fix_symlink_5478
Fix symlinks being replaced with files on save
2 parents 1a97ec4 + 2d1f49a commit a93b45d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Diff for: arduino-core/src/processing/app/BaseNoGui.java

+12-1
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)