do not crash if file vanishes during getBinaryHash()
APKs can be deleted at any time, either by being uninstalled or deleted from the cache.
This commit is contained in:
parent
86cc977746
commit
6055874d9d
@ -38,12 +38,10 @@ import android.text.style.TypefaceSpan;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
||||
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
|
||||
import com.nostra13.universalimageloader.utils.StorageUtils;
|
||||
|
||||
import org.fdroid.fdroid.compat.FileCompat;
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
import org.fdroid.fdroid.data.SanitizedFile;
|
||||
@ -400,7 +398,16 @@ public final class Utils {
|
||||
/**
|
||||
* Get the checksum hash of the file {@code apk} using the algorithm in {@code algo}.
|
||||
* {@code apk} must exist on the filesystem and {@code algo} must be supported
|
||||
* by this device, otherwise an {@link IllegalArgumentException} is thrown.
|
||||
* by this device, otherwise an {@link IllegalArgumentException} is thrown. This
|
||||
* method must be very defensive about checking whether the file exists, since APKs
|
||||
* can be uninstalled/deleted in background at any time, even if this is in the
|
||||
* middle of running.
|
||||
* <p>
|
||||
* This also will run into filesystem corruption if the device is having trouble.
|
||||
* So hide those so F-Droid does not pop up crash reports about that. As such this
|
||||
* exception-message-parsing-and-throwing-a-new-ignorable-exception-hackery is
|
||||
* probably warranted. See https://www.gitlab.com/fdroid/fdroidclient/issues/855
|
||||
* for more detail.
|
||||
*/
|
||||
public static String getBinaryHash(File apk, String algo) {
|
||||
FileInputStream fis = null;
|
||||
@ -418,14 +425,12 @@ public final class Utils {
|
||||
byte[] mdbytes = md.digest();
|
||||
return toHexString(mdbytes).toLowerCase(Locale.ENGLISH);
|
||||
} catch (IOException e) {
|
||||
// The annoyance (potentially) caused by miscellaneous filesystem corruption results in
|
||||
// F-Droid constantly popping up crash reports when F-Droid isn't even open. As such this
|
||||
// exception-message-parsing-and-throwing-a-new-ignorable-exception-hackery is probably
|
||||
// warranted. See https://www.gitlab.com/fdroid/fdroidclient/issues/855 for more detail.
|
||||
if (e.getMessage().contains("read failed: EIO (I/O error)")) {
|
||||
String message = e.getMessage();
|
||||
if (message.contains("read failed: EIO (I/O error)")) {
|
||||
throw new PotentialFilesystemCorruptionException(e);
|
||||
} else if (message.contains(" ENOENT ")) {
|
||||
Utils.debugLog(TAG, apk + " vanished: " + message);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
|
Loading…
x
Reference in New Issue
Block a user