Skip to content

Commit

Permalink
Setup $HOME/storage symlink for external symlink
Browse files Browse the repository at this point in the history
At startup Termux now checks if there is external storage available,
and creates a private area on the external storage if one exists as
well as creating a symlink to the private are at $HOME/storage.
  • Loading branch information
fornwall committed Dec 12, 2015
1 parent e185791 commit bce65f7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/com/termux/app/TermuxActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ public void onClick(View v) {

mTerminalView.checkForTypeface();
mTerminalView.checkForColors();

TermuxInstaller.setupStorageSymlink(this);
}

/**
Expand Down
54 changes: 43 additions & 11 deletions app/src/main/java/com/termux/app/TermuxInstaller.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
package com.termux.app;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
Expand All @@ -26,6 +15,17 @@
import com.termux.R;
import com.termux.terminal.EmulatorDebug;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/**
* Install the Termux bootstrap packages if necessary by following the below steps:
*
Expand Down Expand Up @@ -200,4 +200,36 @@ static void deleteFolder(File fileOrDirectory) {
}
}

public static void setupStorageSymlink(final Context context) {
final File[] dirs = context.getExternalFilesDirs(null);
if (dirs == null || dirs.length < 2) return;
new Thread() {
public void run() {
try {
final File externalDir = dirs[1];
File homeDir = new File(TermuxService.HOME_PATH);
homeDir.mkdirs();
File externalLink = new File(homeDir, "storage");

if (externalLink.exists()) {
if (externalLink.getCanonicalPath().equals(externalDir.getPath())) {
// Keeping existing link.
return;
} else {
// Removing old link to give place to new.
if (!externalLink.delete()) {
Log.e("termux", "Unable to remove old $HOME/storage to give place for new");
return;
}
}
}

Os.symlink(externalDir.getAbsolutePath(), externalLink.getAbsolutePath());
} catch (Exception e) {
Log.e("termux", "Error setting up link", e);
}
}
}.start();
}

}

0 comments on commit bce65f7

Please sign in to comment.