Skip to content

Commit

Permalink
Set file readable if needed
Browse files Browse the repository at this point in the history
When trying to execute a file in $HOME/.shortcuts/ we already set
the file as executable if needed. Now also set if readable if needed.
  • Loading branch information
fornwall committed Jan 17, 2016
1 parent b018b0c commit bfbb10f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ protected void onResume() {
}

File clickedFile = new File(intent.getData().getPath());
if (!clickedFile.canExecute()) {
// Cover for the user if he forgot to mark the file executable:
clickedFile.setExecutable(true);
}
TermuxWidgetProvider.ensureFileReadableAndExecutable(clickedFile);

Intent executeIntent = new Intent(TermuxWidgetProvider.ACTION_EXECUTE, getIntent().getData());
executeIntent.setClassName("com.termux", TermuxWidgetProvider.TERMUX_SERVICE);
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/java/com/termux/widget/TermuxWidgetProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ public void onReceive(Context context, Intent intent) {
case LIST_ITEM_CLICKED_ACTION:
String clickedFilePath = intent.getStringExtra(EXTRA_CLICKED_FILE);
File clickedFile = new File(clickedFilePath);
if (!clickedFile.canExecute()) {
// Cover for the user if he forgot to mark the file executable:
clickedFile.setExecutable(true);
}
ensureFileReadableAndExecutable(clickedFile);
Uri scriptUri = new Uri.Builder().scheme("file").path(clickedFilePath).build();

// Note: Must match TermuxService#ACTION_EXECUTE constant:
Expand All @@ -106,4 +103,10 @@ public void onReceive(Context context, Intent intent) {
}
}

/** Ensure readable and executable file if user forgot to do so. */
static void ensureFileReadableAndExecutable(File file) {
if (!file.canRead()) file.setReadable(true);
if (!file.canExecute()) file.setExecutable(true);
}

}

0 comments on commit bfbb10f

Please sign in to comment.