Bläddra i källkod

When conflicting upload and user decides to keep existing file, do not fail on downloading it

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 4 år sedan
förälder
incheckning
01240c9fd4

+ 4 - 2
src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -112,11 +112,13 @@ public class FileDataStorageManager {
         return getFileByPath(ProviderTableMeta.FILE_PATH, path);
     }
 
-    public OCFile getFileByDecryptedRemotePath(String path) {
+    public @Nullable
+    OCFile getFileByDecryptedRemotePath(String path) {
         return getFileByPath(ProviderTableMeta.FILE_PATH_DECRYPTED, path);
     }
 
-    private OCFile getFileByPath(String type, String path) {
+    private @Nullable
+    OCFile getFileByPath(String type, String path) {
         Cursor cursor = getFileCursorForValue(type, path);
         OCFile ocFile = null;
         if (cursor.moveToFirst()) {

+ 11 - 0
src/main/java/com/owncloud/android/files/services/FileDownloader.java

@@ -503,6 +503,17 @@ public class FileDownloader extends Service
      */
     private void saveDownloadedFile() {
         OCFile file = mStorageManager.getFileById(mCurrentDownload.getFile().getFileId());
+
+        if (file == null) {
+            // try to get file via path, needed for overwriting existing files on conflict dialog
+            file = mStorageManager.getFileByDecryptedRemotePath(mCurrentDownload.getFile().getRemotePath());
+        }
+
+        if (file == null) {
+            Log_OC.e(this, "Could not save " + mCurrentDownload.getFile().getRemotePath());
+            return;
+        }
+
         long syncDate = System.currentTimeMillis();
         file.setLastSyncDateForProperties(syncDate);
         file.setLastSyncDateForData(syncDate);