Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions app/src/main/java/com/httrack/android/HTTrackActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -903,18 +903,25 @@ protected static boolean isIPv6Enabled() {
}

/**
* Emergency dump.
*/
protected static void emergencyDump(final Throwable e) {
try {
final File dumpFile = new File(new File(
Environment.getExternalStorageState(), "HTTrack"), "error.txt");
final FileWriter writer = new FileWriter(dumpFile);
final PrintWriter print = new PrintWriter(writer);
* Emergency dump, into storage of our own: this runs on a crash path, so it must not depend
* on a permission, nor on a volume being mounted.
*
* @param context
* null while the activity is being torn down, in which case nothing is written
* @param e
* the throwable to record
*/
protected static void emergencyDump(final Context context, final Throwable e) {
if (context == null) {
return;
}
final File external = context.getExternalFilesDir(null);
final File dumpFile = new File(
external != null ? external : context.getFilesDir(), "error.txt");
try (final PrintWriter print = new PrintWriter(new FileWriter(dumpFile))) {
e.printStackTrace(print);
writer.close();
HTTrackActivity.setFileReadWrite(dumpFile);
} catch (final IOException io) {
Log.w(HTTrackActivity.class.getSimpleName(), "could not write " + dumpFile, io);
}
}

Expand Down Expand Up @@ -1118,7 +1125,7 @@ protected Void doInBackground(final Void... arg0) {
try {
runInternal();
} catch (final RuntimeException e) {
HTTrackActivity.emergencyDump(e);
HTTrackActivity.emergencyDump(parent, e);
throw e;
} finally {
ended = true;
Expand Down
24 changes: 15 additions & 9 deletions app/src/main/jni/htslibjni.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#include <android/log.h>

Expand Down Expand Up @@ -62,15 +64,19 @@ static char *rootPath = NULL;
/* log assertion failure. */
static void log_assert_failure(const char* exp, const char* file, int line) {
__android_log_print(ANDROID_LOG_VERBOSE, "httrack", "assertion '%s' failed at %s:%d", exp, file, line);
#define MKDIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
/* FIXME TODO: pass the getExternalStorageDirectory() in init. */
FILE *dumpFile;
const char *const filename = emergencyLog != NULL ? emergencyLog
: "/mnt/sdcard/Download/HTTrack/error.txt";
dumpFile = fopen(filename, "wb");
if (dumpFile != NULL) {
fprintf(dumpFile, "assertion '%s' failed at %s:%d\n", exp, file, line);
fclose(dumpFile);
/* Nothing is writable before initRootPath(); logcat above carries it either way. */
if (emergencyLog != NULL) {
/* Owner-only (0600): a crash log created with fopen's default 0666 is world-writable. */
const int fd = open(emergencyLog, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd != -1) {
FILE *const dumpFile = fdopen(fd, "wb");
if (dumpFile != NULL) {
fprintf(dumpFile, "assertion '%s' failed at %s:%d\n", exp, file, line);
fclose(dumpFile);
} else {
close(fd);
}
}
}
}

Expand Down
Loading