Commit afbeb414 authored by Roumen Petrov's avatar Roumen Petrov

install copy of "executable" if installed libraries are without executable bit set

parent f9b446eb
......@@ -46,6 +46,8 @@
public static final String ARGUMENT_SHELL_COMMAND = "com.termoneplus.Command";
public static final String ARGUMENT_WINDOW_HANDLE = "com.termoneplus.WindowHandle";
public static File xbindir;
private static File rootdir;
private static File etcdir;
private static File libdir;
......@@ -60,14 +62,6 @@ public static String getTmpPath() {
return getTmpDir().getAbsolutePath();
}
public static File getLibDir() {
return libdir;
}
public static String getLibPath() {
return getLibDir().getPath();
}
public static File getScriptFile() {
return new File(etcdir, "mkshrc");
}
......@@ -84,12 +78,24 @@ public void onCreate() {
rootdir = getFilesDir().getParentFile();
etcdir = new File(rootdir, "etc");
libdir = new File(getApplicationInfo().nativeLibraryDir);
xbindir = libdir;
cachedir = getCacheDir();
setupPreferences();
ThemeManager.migrateFileSelectionThemeMode(this);
Installer.install_directory(etcdir, false);
// Note at this point xbindir == libdir
File exe = new File(xbindir, Installer.APPINFO_COMMAND);
if (!exe.canExecute()) {
// Old Android (API Level < 17) - libraries are without executable bit set
xbindir = new File(rootdir, ".x");
Installer.install_directory(xbindir, false);
Installer.copy_executable(exe, xbindir);
}
Installer.installAppScriptFile();
}
......
......@@ -17,7 +17,11 @@
package com.termoneplus;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
......@@ -64,4 +68,35 @@ public static boolean installAppScriptFile() {
return install_text_file(shell_script.toArray(new String[0]), Application.getScriptFile());
}
public static boolean copy_executable(File source, File target_path) {
int buflen = 32 * 1024; // 32k
byte[] buf = new byte[buflen];
File target = new File(target_path, source.getName());
File backup = new File(target.getAbsolutePath() + "-bak");
if (target.exists())
if (!target.renameTo(backup))
return false;
try {
OutputStream os = new FileOutputStream(target);
InputStream is = new FileInputStream(source);
int len;
while ((len = is.read(buf, 0, buflen)) > 0) {
os.write(buf, 0, len);
}
os.close();
is.close();
if (backup.exists())
backup.delete();
// always preset executable permissions
return target.setReadable(true) &&
target.setExecutable(true, false);
} catch (Exception ignore) {
}
return false;
}
}
......@@ -108,7 +108,7 @@ private int createShellProcess(TermSettings settings, PathSettings path_settings
String[] env = new String[5];
env[0] = "TERM=" + settings.getTermType();
env[1] = "PATH=" + Application.getLibPath() + File.pathSeparator + path_settings.buildPATH();
env[1] = "PATH=" + Application.xbindir.getPath() + File.pathSeparator + path_settings.buildPATH();
env[2] = "HOME=" + settings.getHomePath();
env[3] = "TMPDIR=" + Application.getTmpPath();
env[4] = "ENV=" + Application.getScriptFilePath();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment