ToolsInstaller: Add methods to check/make symlinks
Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
parent
011d683c23
commit
1cfb938dd1
@ -31,11 +31,13 @@ public final class ToolsInstaller {
|
|||||||
};
|
};
|
||||||
private static final File INSTALL_DIR = getInstallDir();
|
private static final File INSTALL_DIR = getInstallDir();
|
||||||
|
|
||||||
|
private final File localBinaryDir;
|
||||||
private final File nativeLibraryDir;
|
private final File nativeLibraryDir;
|
||||||
private final RootShell rootShell;
|
private final RootShell rootShell;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ToolsInstaller(@ApplicationContext final Context context, final RootShell rootShell) {
|
public ToolsInstaller(@ApplicationContext final Context context, final RootShell rootShell) {
|
||||||
|
localBinaryDir = new File(context.getCacheDir(), "bin");
|
||||||
nativeLibraryDir = new File(context.getApplicationInfo().nativeLibraryDir);
|
nativeLibraryDir = new File(context.getApplicationInfo().nativeLibraryDir);
|
||||||
this.rootShell = rootShell;
|
this.rootShell = rootShell;
|
||||||
}
|
}
|
||||||
@ -68,6 +70,21 @@ public final class ToolsInstaller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean areSymlinked() {
|
||||||
|
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);
|
||||||
|
try {
|
||||||
|
return rootShell.run(null, script.toString()) == OsConstants.EALREADY;
|
||||||
|
} catch (final ErrnoException | IOException | NoRootException ignored) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int install() {
|
public int install() {
|
||||||
if (INSTALL_DIR == null)
|
if (INSTALL_DIR == null)
|
||||||
return OsConstants.ENOENT;
|
return OsConstants.ENOENT;
|
||||||
@ -88,4 +105,22 @@ public final class ToolsInstaller {
|
|||||||
return OsConstants.EACCES;
|
return OsConstants.EACCES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int symlink() {
|
||||||
|
final StringBuilder script = new StringBuilder("set -ex");
|
||||||
|
for (final String[] names : EXECUTABLES) {
|
||||||
|
script.append(String.format("; ln -fns '%s' '%s'",
|
||||||
|
new File(nativeLibraryDir, names[0]),
|
||||||
|
new File(localBinaryDir, names[1])));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return rootShell.run(null, script.toString());
|
||||||
|
} catch (final ErrnoException e) {
|
||||||
|
return e.errno;
|
||||||
|
} catch (final IOException ignored) {
|
||||||
|
return OsConstants.EXIT_FAILURE;
|
||||||
|
} catch (final NoRootException ignored) {
|
||||||
|
return OsConstants.EACCES;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user