From fb267a0564392adf4938b8f8824e5c89c22776a0 Mon Sep 17 00:00:00 2001
From: masensio <masensio@solidgear.es>
Date: Fri, 28 Feb 2014 13:53:56 +0100
Subject: [PATCH] OC-3097: (fix bug) When the connection is lost during a
 download, app thinks that the download is finished

---
 .../files/DownloadRemoteFileOperation.java         | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java
index 849acabc..7500c121 100644
--- a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java
+++ b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java
@@ -131,11 +131,15 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
                         }
                     }
                 }
-                savedFile = true;
-                Header modificationTime = mGet.getResponseHeader("Last-Modified");
-                if (modificationTime != null) {
-                    Date d = WebdavUtils.parseResponseDate((String) modificationTime.getValue());
-                    mModificationTimestamp = (d != null) ? d.getTime() : 0;
+                if (transferred == totalToTransfer) {  // Check if the file is completed
+                	savedFile = true;
+                	Header modificationTime = mGet.getResponseHeader("Last-Modified");
+                	if (modificationTime != null) {
+                		Date d = WebdavUtils.parseResponseDate((String) modificationTime.getValue());
+                		mModificationTimestamp = (d != null) ? d.getTime() : 0;
+                	}
+                } else {
+                	client.exhaustResponse(mGet.getResponseBodyAsStream());
                 }
                 
             } else {