mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-07 03:05:18 +08:00
Fix workdir logic in RunCommandService
This commit fixes the workdir logic to not send `EXTRA_CURRENT_WORKING_DIRECTORY` extra to `TermuxService` if workdir is empty, since that will raise `No such file or directory` exceptions if `cwd` is empty when targeting sdk `29`.
This commit is contained in:
@@ -104,14 +104,18 @@ public class RunCommandService extends Service {
|
|||||||
return Service.START_NOT_STICKY;
|
return Service.START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uri programUri = new Uri.Builder().scheme("com.termux.file").path(getExpandedTermuxPath(intent.getStringExtra(RUN_COMMAND_PATH))).build();
|
Uri programUri = new Uri.Builder().scheme("com.termux.file").path(getExpandedTermuxPath(intent.getStringExtra(RUN_COMMAND_PATH))).build();
|
||||||
|
|
||||||
Intent execIntent = new Intent(TermuxService.ACTION_EXECUTE, programUri);
|
Intent execIntent = new Intent(TermuxService.ACTION_EXECUTE, programUri);
|
||||||
execIntent.setClass(this, TermuxService.class);
|
execIntent.setClass(this, TermuxService.class);
|
||||||
execIntent.putExtra(TermuxService.EXTRA_ARGUMENTS, intent.getStringArrayExtra(RUN_COMMAND_ARGUMENTS));
|
execIntent.putExtra(TermuxService.EXTRA_ARGUMENTS, intent.getStringArrayExtra(RUN_COMMAND_ARGUMENTS));
|
||||||
execIntent.putExtra(TermuxService.EXTRA_CURRENT_WORKING_DIRECTORY, getExpandedTermuxPath(intent.getStringExtra(RUN_COMMAND_WORKDIR)));
|
|
||||||
execIntent.putExtra(TermuxService.EXTRA_EXECUTE_IN_BACKGROUND, intent.getBooleanExtra(RUN_COMMAND_BACKGROUND, false));
|
execIntent.putExtra(TermuxService.EXTRA_EXECUTE_IN_BACKGROUND, intent.getBooleanExtra(RUN_COMMAND_BACKGROUND, false));
|
||||||
|
|
||||||
|
String workingDirectory = intent.getStringExtra(RUN_COMMAND_WORKDIR);
|
||||||
|
if (workingDirectory != null && !workingDirectory.isEmpty()) {
|
||||||
|
execIntent.putExtra(TermuxService.EXTRA_CURRENT_WORKING_DIRECTORY, getExpandedTermuxPath(workingDirectory));
|
||||||
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
this.startForegroundService(execIntent);
|
this.startForegroundService(execIntent);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user