mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-19 08:52:15 +01:00
Merge pull request #5573 from facchinm/fix_symlink_5478
Fix symlinks being replaced with files on save
This commit is contained in:
commit
a93b45d9c8
@ -884,11 +884,22 @@ public class BaseNoGui {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user