|
1 | 1 | package com.termux.app;
|
2 | 2 |
|
3 |
| -import java.io.BufferedReader; |
4 |
| -import java.io.File; |
5 |
| -import java.io.FileOutputStream; |
6 |
| -import java.io.InputStreamReader; |
7 |
| -import java.net.MalformedURLException; |
8 |
| -import java.net.URL; |
9 |
| -import java.util.ArrayList; |
10 |
| -import java.util.List; |
11 |
| -import java.util.zip.ZipEntry; |
12 |
| -import java.util.zip.ZipInputStream; |
13 |
| - |
14 | 3 | import android.app.Activity;
|
15 | 4 | import android.app.AlertDialog;
|
16 | 5 | import android.app.ProgressDialog;
|
|
26 | 15 | import com.termux.R;
|
27 | 16 | import com.termux.terminal.EmulatorDebug;
|
28 | 17 |
|
| 18 | +import java.io.BufferedReader; |
| 19 | +import java.io.File; |
| 20 | +import java.io.FileOutputStream; |
| 21 | +import java.io.InputStreamReader; |
| 22 | +import java.net.MalformedURLException; |
| 23 | +import java.net.URL; |
| 24 | +import java.util.ArrayList; |
| 25 | +import java.util.List; |
| 26 | +import java.util.zip.ZipEntry; |
| 27 | +import java.util.zip.ZipInputStream; |
| 28 | + |
29 | 29 | /**
|
30 | 30 | * Install the Termux bootstrap packages if necessary by following the below steps:
|
31 | 31 | *
|
@@ -200,4 +200,36 @@ static void deleteFolder(File fileOrDirectory) {
|
200 | 200 | }
|
201 | 201 | }
|
202 | 202 |
|
| 203 | + public static void setupStorageSymlink(final Context context) { |
| 204 | + final File[] dirs = context.getExternalFilesDirs(null); |
| 205 | + if (dirs == null || dirs.length < 2) return; |
| 206 | + new Thread() { |
| 207 | + public void run() { |
| 208 | + try { |
| 209 | + final File externalDir = dirs[1]; |
| 210 | + File homeDir = new File(TermuxService.HOME_PATH); |
| 211 | + homeDir.mkdirs(); |
| 212 | + File externalLink = new File(homeDir, "storage"); |
| 213 | + |
| 214 | + if (externalLink.exists()) { |
| 215 | + if (externalLink.getCanonicalPath().equals(externalDir.getPath())) { |
| 216 | + // Keeping existing link. |
| 217 | + return; |
| 218 | + } else { |
| 219 | + // Removing old link to give place to new. |
| 220 | + if (!externalLink.delete()) { |
| 221 | + Log.e("termux", "Unable to remove old $HOME/storage to give place for new"); |
| 222 | + return; |
| 223 | + } |
| 224 | + } |
| 225 | + } |
| 226 | + |
| 227 | + Os.symlink(externalDir.getAbsolutePath(), externalLink.getAbsolutePath()); |
| 228 | + } catch (Exception e) { |
| 229 | + Log.e("termux", "Error setting up link", e); |
| 230 | + } |
| 231 | + } |
| 232 | + }.start(); |
| 233 | + } |
| 234 | + |
203 | 235 | }
|
0 commit comments