Skip to content

Commit

Permalink
Ensure failsafe session can still be opened if files directory is not…
Browse files Browse the repository at this point in the history
… accessible and fix comment

The `/data/data/com.termux` directory will not be created if it did not already exist and android did not already create it instead of as mentioned in 6fa4b9b. Check #2168 (comment)
  • Loading branch information
agnostic-apollo committed Jul 14, 2021
1 parent 0308d6a commit a189f63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions app/src/main/java/com/termux/app/TermuxInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ static void setupBootstrapIfNeeded(final Activity activity, final Runnable whenD
String bootstrapErrorMessage;
Error filesDirectoryAccessibleError;

// This will also call Context.getFilesDir(), which should ensure that TERMUX_INTERNAL_PRIVATE_APP_DATA_DIR_PATH
// is created if it does not already exist, like if it was not already created by android
// This will also call Context.getFilesDir(), which should ensure that TERMUX_FILES_DIR_PATH
// is created if it does not already exist
filesDirectoryAccessibleError = TermuxFileUtils.isTermuxFilesDirectoryAccessible(activity, true, true);
boolean isFilesDirectoryAccessible = filesDirectoryAccessibleError == null;

Expand All @@ -79,9 +79,9 @@ static void setupBootstrapIfNeeded(final Activity activity, final Runnable whenD
bootstrapErrorMessage = Error.getMinimalErrorString(filesDirectoryAccessibleError) + "\nTERMUX_FILES_DIR: " + MarkdownUtils.getMarkdownCodeForString(TermuxConstants.TERMUX_FILES_DIR_PATH, false);
Logger.logError(LOG_TAG, bootstrapErrorMessage);
CrashUtils.sendCrashReportNotification(activity, LOG_TAG, "## Bootstrap Error\n\n" + bootstrapErrorMessage, true, true);
MessageDialogUtils.exitAppWithErrorMessage(activity,
MessageDialogUtils.showMessage(activity,
activity.getString(R.string.bootstrap_error_title),
bootstrapErrorMessage);
bootstrapErrorMessage, null);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,13 @@ public static Error validateDirectoryFileExistenceAndPermissions(String label, f
* Validate the existence and permissions of {@link TermuxConstants#TERMUX_FILES_DIR_PATH}.
*
* The directory will not be created manually but by calling {@link Context#getFilesDir()}
* so that android itself creates it. The `/data/data/[package_name]` directory cannot be
* created by an app itself. Note that the path returned by {@link Context#getFilesDir()} will
* so that android itself creates it. However, the call will not create its parent package
* data directory `/data/user/0/[package_name]` if it does not already exist and a `logcat`
* error will be logged by android.
* {@code Failed to ensure /data/user/0/<package_name>/files: mkdir failed: ENOENT (No such file or directory)}
* An android app likely can't create the package data directory since its parent `/data/user/0`
* is owned by `system` user and is normally create at app install or update time and not at app startup.
* Note that the path returned by {@link Context#getFilesDir()} will
* be under `/data/user/[id]/[package_name]` instead of `/data/data/[package_name]`
* defined by default by {@link TermuxConstants#TERMUX_FILES_DIR_PATH}, where id will be 0 for
* primary user and a higher number for other users/profiles. If app is running under work profile
Expand Down

0 comments on commit a189f63

Please sign in to comment.