Skip to content

Commit 31fe4ac

Browse files
matthijskooijmancmaglie
authored andcommitted
Add Base.absoluteFile method
This method takes filenames as specified on the commandline and turns them into the right File object, taking into account the current directory passed through --curdir by the wrapper script.
1 parent 0798e1c commit 31fe4ac

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

app/src/processing/app/Base.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,18 @@ static protected void initRequirements() {
291291
}
292292
}
293293

294+
// Returns a File object for the given pathname. If the pathname
295+
// is not absolute, it is interpreted relative to the current
296+
// directory when starting the IDE (which is not the same as the
297+
// current working directory!).
298+
static public File absoluteFile(String path) {
299+
File file = new File(path);
300+
if (!file.isAbsolute()) {
301+
file = new File(currentDirectory, path);
302+
}
303+
return file;
304+
}
305+
294306

295307
protected static enum ACTION { GUI, VERIFY, UPLOAD, NOOP, GET_PREF };
296308
public Base(String[] args) throws Exception {
@@ -457,12 +469,11 @@ public Base(String[] args) throws Exception {
457469
}
458470
}
459471

460-
if (!new File(path).isAbsolute()) {
461-
path = new File(currentDirectory, path).getAbsolutePath();
462-
}
472+
// Correctly resolve relative paths
473+
File file = absoluteFile(path);
463474

464475
boolean showEditor = (action == ACTION.GUI);
465-
if (handleOpen(new File(path), nextEditorLocation(), showEditor) == null) {
476+
if (handleOpen(file, nextEditorLocation(), showEditor) == null) {
466477
String mess = I18n.format(_("Failed to open sketch: \"{0}\""), path);
467478
// Open failure is fatal in upload/verify mode
468479
if (action == ACTION.VERIFY || action == ACTION.UPLOAD)

0 commit comments

Comments
 (0)