File tree Expand file tree Collapse file tree 3 files changed +22
-26
lines changed
arduino-core/src/processing/app Expand file tree Collapse file tree 3 files changed +22
-26
lines changed Original file line number Diff line number Diff line change @@ -187,7 +187,7 @@ protected void nameCode(String newName) {
187187 } else {
188188 // Non-primary file, rename just that file
189189 try {
190- sketch . renameFileTo ( current , newName );
190+ current . renameTo ( newName );
191191 } catch (IOException e ) {
192192 // This does not pass on e, to prevent showing a backtrace for
193193 // "normal" errors.
@@ -349,7 +349,7 @@ public boolean save() throws IOException {
349349 // Do rename of all .pde files to new .ino extension
350350 for (SketchFile file : oldFiles ) {
351351 File newName = FileUtils .replaceExtension (file .getFile (), Sketch .DEFAULT_SKETCH_EXTENSION );
352- file .renameTo (newName );
352+ file .renameTo (newName . getName () );
353353 }
354354 }
355355 }
Original file line number Diff line number Diff line change @@ -277,27 +277,9 @@ public void renameTo(File newFolder) throws IOException {
277277 file .renamedTo (new File (newFolder , file .getFileName ()));
278278
279279 // And finally, rename the primary file
280- if (!getPrimaryFile ().renameTo (newPrimary ))
281- throw new IOException (tr ("Failed to rename primary sketch file" ));
280+ getPrimaryFile ().renameTo (newPrimary .getName ());
282281 }
283282
284- /**
285- * Rename the given file to get the given name.
286- *
287- * @param sketchfile
288- * The SketchFile to be renamed.
289- * @param newName
290- * The new name, including extension, excluding directory
291- * name.
292- * @throws IOException
293- * When a problem occurs, or is expected to occur. The error
294- * message should be already translated.
295- */
296- public void renameFileTo (SketchFile sketchfile , String newName ) throws IOException {
297- File newFile = new File (folder , newName );
298- checkNewFilename (newFile );
299- sketchfile .renameTo (newFile );
300- }
301283
302284 public SketchFile addFile (String newName ) throws IOException {
303285 // Check the name will not cause any conflicts
Original file line number Diff line number Diff line change @@ -160,11 +160,25 @@ private boolean deleteCompiledFilesFrom(Path tempBuildFolder) throws IOException
160160 return true ;
161161 }
162162
163- protected boolean renameTo (File what ) {
164- boolean success = file .renameTo (what );
165- if (success )
166- renamedTo (what );
167- return success ;
163+ /**
164+ * Rename the given file to get the given name.
165+ *
166+ * @param newName
167+ * The new name, including extension, excluding directory
168+ * name.
169+ * @throws IOException
170+ * When a problem occurs, or is expected to occur. The error
171+ * message should be already translated.
172+ */
173+ public void renameTo (String newName ) throws IOException {
174+ File newFile = new File (file .getParentFile (), newName );
175+ sketch .checkNewFilename (newFile );
176+ if (file .renameTo (newFile )) {
177+ renamedTo (newFile );
178+ } else {
179+ String msg = I18n .format (tr ("Failed to rename \" {0}\" to \" {1}\" " ), file .getName (), newName );
180+ throw new IOException (msg );
181+ }
168182 }
169183
170184 /**
You can’t perform that action at this time.
0 commit comments