- Only copy files to cache if the file has more than 0 bytes
- PrivilegeChecker had a bug if cache/recovery path didn't exist
diff --git a/src/com/fairphone/updater/tools/PrivilegeChecker.java b/src/com/fairphone/updater/tools/PrivilegeChecker.java
index da72977..10283b0 100644
--- a/src/com/fairphone/updater/tools/PrivilegeChecker.java
+++ b/src/com/fairphone/updater/tools/PrivilegeChecker.java
@@ -13,19 +13,15 @@
static {
// If we have permissions to write instructions to the recovery, we are a privileged app.
- File f = new File("/cache/recovery/command");
- if ( f.exists() ) {
- isPrivilegedApp = f.canWrite();
- } else {
- boolean success = false;
- try {
- success = f.createNewFile() && f.delete();
- } catch (IOException ignored) {
- success = false;
- } finally {
- isPrivilegedApp = success;
- }
- }
+ File f = new File("/cache/test.txt");
+ boolean success = false;
+ try {
+ success = f.createNewFile() && f.delete();
+ } catch (IOException ignored) {
+ success = false;
+ } finally {
+ isPrivilegedApp = success;
+ }
Log.i(TAG, "App is " + (isPrivilegedApp ? "" : "not") + " privileged.");
}
diff --git a/src/com/fairphone/updater/tools/Utils.java b/src/com/fairphone/updater/tools/Utils.java
index 9bce949..fbd7069 100644
--- a/src/com/fairphone/updater/tools/Utils.java
+++ b/src/com/fairphone/updater/tools/Utils.java
@@ -376,7 +376,7 @@
{
double fileSize = file.length();
double cacheSize = Utils.getPartitionSizeInBytes(Environment.getDownloadCacheDirectory());
- return cacheSize >= fileSize;
+ return fileSize > 0 && cacheSize >= fileSize;
}
public static String getFilenameFromDownloadableItem(DownloadableItem item, boolean isVersion)