mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-19 08:52:15 +01:00
Do not delete the source if source = destination
While the previous version could handle the case, it only did so after deleting the destination file, therefore causing data loss.
This commit is contained in:
parent
d3b3714802
commit
1fc0997f71
@ -495,6 +495,10 @@ public class SketchController {
|
||||
isData = true;
|
||||
}
|
||||
|
||||
if (!sourceFile.equals(destFile)) {
|
||||
// The typical case here is adding a file from somewhere else.
|
||||
// This however fails if the source and destination are equal
|
||||
|
||||
// check whether this file already exists
|
||||
if (destFile.exists()) {
|
||||
Object[] options = { tr("OK"), tr("Cancel") };
|
||||
@ -518,8 +522,7 @@ public class SketchController {
|
||||
// otherwise case changes will not be preserved.
|
||||
// http://dev.processing.org/bugs/show_bug.cgi?id=969
|
||||
if (replacement) {
|
||||
boolean muchSuccess = destFile.delete();
|
||||
if (!muchSuccess) {
|
||||
if (!destFile.delete()) {
|
||||
Base.showWarning(tr("Error adding file"),
|
||||
I18n.format(tr("Could not delete the existing ''{0}'' file."), filename),
|
||||
null);
|
||||
@ -527,18 +530,7 @@ public class SketchController {
|
||||
}
|
||||
}
|
||||
|
||||
// make sure they aren't the same file
|
||||
if (isData && sourceFile.equals(destFile)) {
|
||||
Base.showWarning(tr("You can't fool me"),
|
||||
tr("This file has already been copied to the\n" +
|
||||
"location from which where you're trying to add it.\n" +
|
||||
"I ain't not doin nuthin'."), null);
|
||||
return false;
|
||||
}
|
||||
|
||||
// in case the user is "adding" the code in an attempt
|
||||
// to update the sketch's tabs
|
||||
if (!sourceFile.equals(destFile)) {
|
||||
// perform the copy
|
||||
try {
|
||||
Base.copyFile(sourceFile, destFile);
|
||||
|
||||
@ -549,7 +541,18 @@ public class SketchController {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// If the source and destination are equal, a code file is handled
|
||||
// - as a replacement, if there is a corresponding tab,
|
||||
// (eg. user wants to update the file after modifying it outside the editor)
|
||||
// - as an addition, otherwise.
|
||||
// (eg. the user copied the file to the sketch folder and wants to edit it)
|
||||
// For a data file, this is a no-op.
|
||||
if (editor.findTabIndex(destFile) >= 0)
|
||||
replacement = true;
|
||||
}
|
||||
|
||||
// open/refresh the tab
|
||||
if (!isData) {
|
||||
int tabIndex;
|
||||
if (replacement) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user