浏览代码

Fix upload by sharing link with defensive check during mtime read

Since mtime is used to update cache and is not on critical path,
we can make it optional. If it's not available, cache behaviour
will suffer, but sharing should not fail.

Fixes #7587

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
Chris Narkiewicz 4 年之前
父节点
当前提交
70865ae337
共有 1 个文件被更改,包括 6 次插入4 次删除
  1. 6 4
      src/main/java/com/owncloud/android/ui/asynctasks/CopyAndUploadContentUrisTask.java

+ 6 - 4
src/main/java/com/owncloud/android/ui/asynctasks/CopyAndUploadContentUrisTask.java

@@ -152,9 +152,11 @@ public class CopyAndUploadContentUrisTask extends AsyncTask<Object, Void, Result
                                                                  null,
                                                                  null)) {
                     if (cursor != null && cursor.moveToFirst()) {
-                        lastModified = cursor.getLong(
-                            cursor.getColumnIndexOrThrow(
-                                DocumentsContract.Document.COLUMN_LAST_MODIFIED));
+                        // this check prevents a crash when last modification time is not available on certain phones
+                        int columnIndex = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_LAST_MODIFIED);
+                        if (columnIndex >= 0) {
+                            lastModified = cursor.getLong(columnIndex);
+                        }
                     }
                 }
 
@@ -173,7 +175,7 @@ public class CopyAndUploadContentUrisTask extends AsyncTask<Object, Void, Result
                 while ((count = inputStream.read(buffer)) > 0) {
                     outputStream.write(buffer, 0, count);
                 }
- 
+
                 if (lastModified != 0) {
                     try {
                         if (!cacheFile.setLastModified(lastModified)) {