Commit 8e9566f2 authored by Bastien Le Querrec's avatar Bastien Le Querrec

avoid NPE when exporting data, do not backup lib/

Also, throw IOException on NPE. This should not append because NPE
occurs on some devices when copying lib/. But in case of another corner
case with NPEs, this commit will prevent a crash and log info.

Fixes #631
parent 69d3d635
......@@ -83,26 +83,31 @@ public class EncryptedBackupExporter {
}
private static void exportDirectory(Context context, String directoryName) throws IOException {
File directory = new File(context.getFilesDir().getParent() + File.separatorChar + directoryName);
File exportDirectory = new File(getExportDirectoryPath() + File.separatorChar + directoryName);
if (!directoryName.equals("/lib")) {
File directory = new File(context.getFilesDir().getParent() + File.separatorChar + directoryName);
File exportDirectory = new File(getExportDirectoryPath() + File.separatorChar + directoryName);
if (directory.exists() && directory.isDirectory()) {
exportDirectory.mkdirs();
if (directory.exists() && directory.isDirectory()) {
exportDirectory.mkdirs();
File[] contents = directory.listFiles();
File[] contents = directory.listFiles();
if (contents == null)
throw new IOException("directory.listFiles() is null for " + context.getFilesDir().getParent() + File.separatorChar + directoryName + "!");
for (int i=0;i<contents.length;i++) {
File localFile = contents[i];
for (int i=0;i<contents.length;i++) {
File localFile = contents[i];
if (localFile.isFile() && !localFile.getAbsolutePath().contains("libcurve25519.so")) {
File exportedFile = new File(exportDirectory.getAbsolutePath() + File.separator + localFile.getName());
migrateFile(localFile, exportedFile);
} else {
exportDirectory(context, directoryName + File.separator + localFile.getName());
if (localFile.isFile() && !localFile.getAbsolutePath().contains("libcurve25519.so")) {
File exportedFile = new File(exportDirectory.getAbsolutePath() + File.separator + localFile.getName());
migrateFile(localFile, exportedFile);
} else {
exportDirectory(context, directoryName + File.separator + localFile.getName());
}
}
} else {
Log.w(TAG, "Could not find directory: " + directory.getAbsolutePath() + " (or it is not a directory)");
}
} else {
Log.w(TAG, "Could not find directory: " + directory.getAbsolutePath() + " (or it is not a directory)");
}
}
......
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