Skip to content

Commit

Permalink
Merge branch 'master' of github.com:arduino/Arduino
Browse files Browse the repository at this point in the history
  • Loading branch information
facchinm committed Dec 12, 2016
2 parents 83f9ed7 + a93b45d commit 8756482
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion arduino-core/src/processing/app/BaseNoGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -884,11 +884,22 @@ static public String sanitizeName(String origName) {
}

/**
* Spew the contents of a String object out to a file.
* Save the content of a String into a file
* - Save the content into a temp file
* - Find the canonical path of the file (if it's a symlink, follow it)
* - Remove the original file
* - Move temp file to original path
* This ensures that the file is not getting truncated if the disk is full
*/
static public void saveFile(String str, File file) throws IOException {
File temp = File.createTempFile(file.getName(), null, file.getParentFile());
PApplet.saveStrings(temp, new String[] { str });

try {
file = file.getCanonicalFile();
} catch (IOException e) {
}

if (file.exists()) {
boolean result = file.delete();
if (!result) {
Expand Down

0 comments on commit 8756482

Please sign in to comment.