From 7e06768f752f6ac44d0f33f4d8de5a6cadb4fa7c Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 10 Jan 2018 23:38:39 +0100 Subject: ToolsInstaller: symlink tools always Signed-off-by: Jason A. Donenfeld --- .../com/wireguard/android/util/ToolsInstaller.java | 36 +++++++++------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java b/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java index 46dc43a4..dca410f0 100644 --- a/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java +++ b/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java @@ -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 { if (areToolsAvailable == null) { synchronized (this) { if (areToolsAvailable == null) { - if (areInstalled() == OsConstants.EALREADY) { - Log.d(TAG, "Tools are installed to the system partition"); - areToolsAvailable = true; - } else if (areSymlinked() == OsConstants.EALREADY) { + int ret = symlink(); + if (ret == OsConstants.EALREADY) { Log.d(TAG, "Tools were already symlinked into our private binary dir"); 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"); areToolsAvailable = true; } else { @@ -115,7 +98,7 @@ public final class ToolsInstaller { public int install() throws NoRootException { if (INSTALL_DIR == null) return OsConstants.ENOENT; - final StringBuilder script = new StringBuilder("set -ex;"); + final StringBuilder script = new StringBuilder("set -ex; "); script.append("trap 'mount -o ro,remount /system' EXIT; mount -o rw,remount /system; "); for (final String[] names : EXECUTABLES) { final File destination = new File(INSTALL_DIR, names[1]); @@ -130,12 +113,21 @@ public final class ToolsInstaller { } 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) { script.append(String.format("ln -fns '%s' '%s'; ", new File(nativeLibraryDir, names[0]), new File(localBinaryDir, names[1]))); } + script.append("exit ").append(OsConstants.EXIT_SUCCESS).append(';'); + try { return rootShell.run(null, script.toString()); } catch (final IOException ignored) { -- cgit v1.2.3