ToolsInstaller: symlink tools always
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
7a618c1463
commit
7e06768f75
@ -73,32 +73,15 @@ public final class ToolsInstaller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int areSymlinked() throws NoRootException {
|
|
||||||
final StringBuilder script = new StringBuilder();
|
|
||||||
for (final String[] names : EXECUTABLES) {
|
|
||||||
script.append(String.format("test '%s' -ef '%s' && ",
|
|
||||||
new File(nativeLibraryDir, names[0]),
|
|
||||||
new File(localBinaryDir, names[1])));
|
|
||||||
}
|
|
||||||
script.append("exit ").append(OsConstants.EALREADY).append(';');
|
|
||||||
try {
|
|
||||||
return rootShell.run(null, script.toString());
|
|
||||||
} catch (final IOException ignored) {
|
|
||||||
return OsConstants.EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ensureToolsAvailable() throws FileNotFoundException, NoRootException {
|
public void ensureToolsAvailable() throws FileNotFoundException, NoRootException {
|
||||||
if (areToolsAvailable == null) {
|
if (areToolsAvailable == null) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (areToolsAvailable == null) {
|
if (areToolsAvailable == null) {
|
||||||
if (areInstalled() == OsConstants.EALREADY) {
|
int ret = symlink();
|
||||||
Log.d(TAG, "Tools are installed to the system partition");
|
if (ret == OsConstants.EALREADY) {
|
||||||
areToolsAvailable = true;
|
|
||||||
} else if (areSymlinked() == OsConstants.EALREADY) {
|
|
||||||
Log.d(TAG, "Tools were already symlinked into our private binary dir");
|
Log.d(TAG, "Tools were already symlinked into our private binary dir");
|
||||||
areToolsAvailable = true;
|
areToolsAvailable = true;
|
||||||
} else if (symlink() == OsConstants.EXIT_SUCCESS) {
|
} else if (ret == OsConstants.EXIT_SUCCESS) {
|
||||||
Log.d(TAG, "Tools are now symlinked into our private binary dir");
|
Log.d(TAG, "Tools are now symlinked into our private binary dir");
|
||||||
areToolsAvailable = true;
|
areToolsAvailable = true;
|
||||||
} else {
|
} else {
|
||||||
@ -130,12 +113,21 @@ public final class ToolsInstaller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int symlink() throws NoRootException {
|
public int symlink() throws NoRootException {
|
||||||
final StringBuilder script = new StringBuilder("set -ex;");
|
final StringBuilder script = new StringBuilder("set -x; ");
|
||||||
|
for (final String[] names : EXECUTABLES) {
|
||||||
|
script.append(String.format("test '%s' -ef '%s' && ",
|
||||||
|
new File(nativeLibraryDir, names[0]),
|
||||||
|
new File(localBinaryDir, names[1])));
|
||||||
|
}
|
||||||
|
script.append("exit ").append(OsConstants.EALREADY).append("; set -e; ");
|
||||||
|
|
||||||
for (final String[] names : EXECUTABLES) {
|
for (final String[] names : EXECUTABLES) {
|
||||||
script.append(String.format("ln -fns '%s' '%s'; ",
|
script.append(String.format("ln -fns '%s' '%s'; ",
|
||||||
new File(nativeLibraryDir, names[0]),
|
new File(nativeLibraryDir, names[0]),
|
||||||
new File(localBinaryDir, names[1])));
|
new File(localBinaryDir, names[1])));
|
||||||
}
|
}
|
||||||
|
script.append("exit ").append(OsConstants.EXIT_SUCCESS).append(';');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return rootShell.run(null, script.toString());
|
return rootShell.run(null, script.toString());
|
||||||
} catch (final IOException ignored) {
|
} catch (final IOException ignored) {
|
||||||
|
Loading…
Reference in New Issue
Block a user