Better log for FileUtils::doesFileExist() #6

This commit is contained in:
Emmanuel Engelhart 2016-03-04 20:19:03 +01:00
parent 1e280d99ca
commit 372b725749
3 changed files with 13 additions and 5 deletions

View File

@ -460,11 +460,10 @@ def step_embed_zimfile(jsdata, **options):
os.symlink('../{}/{}'.format(archs[0], jsdata.get('zim_name')),
jsdata.get('zim_name'))
os.chdir(tmpd)
syscall('zip -r -0 {} lib'
syscall('zip -r -0 -y {} lib'
.format(os.path.join(ANDROID_PATH, 'content-libs.jar')))
shutil.rmtree(tmpd)
def step_build_apk(jsdata, **options):
''' build the actual APK '''

View File

@ -1123,11 +1123,8 @@ public class KiwixMobileActivity extends AppCompatActivity
filePath = FileUtils.generateSaveFileName(fileName);
}
Log.d(TAG_KIWIX, "Looking for: " + filePath + " -- filesize: "
+ Constants.CUSTOM_APP_ZIM_FILE_SIZE);
if (!FileUtils
.doesFileExist(filePath, Constants.CUSTOM_APP_ZIM_FILE_SIZE, false)) {
Log.d(TAG_KIWIX, "... doesn't exist.");
AlertDialog.Builder zimFileMissingBuilder = new AlertDialog.Builder(
this);

View File

@ -1,5 +1,6 @@
package org.kiwix.kiwixmobile.utils.files;
import android.util.Log;
import android.content.Context;
import android.os.Environment;
import java.io.File;
@ -7,6 +8,8 @@ import org.kiwix.kiwixmobile.settings.Constants;
public class FileUtils {
public static final String TAG_KIWIX = "kiwix";
public static File getFileCacheDir(Context context) {
boolean external = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
@ -61,18 +64,27 @@ public class FileUtils {
*/
static public boolean doesFileExist(String fileName, long fileSize,
boolean deleteFileOnMismatch) {
Log.d(TAG_KIWIX, "Looking for '" + fileName + "' with size=" + fileSize);
// the file may have been delivered by Market --- let's make sure
// it's the size we expect
File fileForNewFile = new File(fileName);
if (fileForNewFile.exists()) {
if (fileForNewFile.length() == fileSize) {
Log.d(TAG_KIWIX, "Correct file '" + fileName + "' found.");
return true;
} else {
Log.d(TAG_KIWIX, "File '" + fileName + "' found but with wrong size=" + fileForNewFile.length());
}
if (deleteFileOnMismatch) {
// delete the file --- we won't be able to resume
// because we cannot confirm the integrity of the file
fileForNewFile.delete();
}
} else {
Log.d(TAG_KIWIX, "No file '" + fileName + "' found.");
}
return false;
}