Prevent double count of transfer progress when part of an upload is resend
authorDavid A. Velasco <dvelasco@solidgear.es>
Mon, 7 Oct 2013 10:01:15 +0000 (12:01 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Mon, 7 Oct 2013 10:01:15 +0000 (12:01 +0200)
src/eu/alefzero/webdav/ChunkFromFileChannelRequestEntity.java
src/eu/alefzero/webdav/WebdavClient.java

index 3f45396..21f82d9 100644 (file)
@@ -120,11 +120,15 @@ public class ChunkFromFileChannelRequestEntity implements RequestEntity, Progres
             mChannel.position(mOffset);
             long size = mFile.length();
             if (size == 0) size = -1;
             mChannel.position(mOffset);
             long size = mFile.length();
             if (size == 0) size = -1;
-            while (mChannel.position() < mOffset + mChunkSize && mChannel.position() < mChannel.size()) {
+            long maxCount = Math.min(mOffset + mChunkSize, mChannel.size());
+            while (mChannel.position() < maxCount) {
                 readCount = mChannel.read(mBuffer);
                 out.write(mBuffer.array(), 0, readCount);
                 mBuffer.clear();
                 readCount = mChannel.read(mBuffer);
                 out.write(mBuffer.array(), 0, readCount);
                 mBuffer.clear();
-                mTransferred += readCount;
+                if (mTransferred < maxCount) {  // condition to avoid accumulate progress for repeated chunks
+                    Log_OC.d(TAG, "aƱadiendo a mTransfered " + mTransferred + " readCount " + readCount + " hasta " + (mTransferred + readCount));
+                    mTransferred += readCount;
+                }
                 synchronized (mDataTransferListeners) {
                     it = mDataTransferListeners.iterator();
                     while (it.hasNext()) {
                 synchronized (mDataTransferListeners) {
                     it = mDataTransferListeners.iterator();
                     while (it.hasNext()) {
index 2ab5a69..f25e390 100644 (file)
@@ -168,21 +168,21 @@ public class WebdavClient extends HttpClient {
         try {
             method.setFollowRedirects(mFollowRedirects);
         } catch (Exception e) {
         try {
             method.setFollowRedirects(mFollowRedirects);
         } catch (Exception e) {
-            Log_OC.d(TAG, "setFollowRedirects failed for " + method.getName() + " method, custom redirection will be used");
-            customRedirectionNeeded = true;
+            if (mFollowRedirects) Log_OC.d(TAG, "setFollowRedirects failed for " + method.getName() + " method, custom redirection will be used");
+            customRedirectionNeeded = mFollowRedirects;
         }
         if (mSsoSessionCookie != null && mSsoSessionCookie.length() > 0) {
             method.setRequestHeader("Cookie", mSsoSessionCookie);
         }
         int status = super.executeMethod(method);
         int redirectionsCount = 0;
         }
         if (mSsoSessionCookie != null && mSsoSessionCookie.length() > 0) {
             method.setRequestHeader("Cookie", mSsoSessionCookie);
         }
         int status = super.executeMethod(method);
         int redirectionsCount = 0;
-        while (mFollowRedirects &&
+        while (customRedirectionNeeded &&
                 redirectionsCount < MAX_REDIRECTIONS_COUNT &&
                 redirectionsCount < MAX_REDIRECTIONS_COUNT &&
-                customRedirectionNeeded &&
                 (   status == HttpStatus.SC_MOVED_PERMANENTLY || 
                     status == HttpStatus.SC_MOVED_TEMPORARILY ||
                     status == HttpStatus.SC_TEMPORARY_REDIRECT)
                 ) {
                 (   status == HttpStatus.SC_MOVED_PERMANENTLY || 
                     status == HttpStatus.SC_MOVED_TEMPORARILY ||
                     status == HttpStatus.SC_TEMPORARY_REDIRECT)
                 ) {
+            
             Header location = method.getResponseHeader("Location");
             if (location != null) {
                 Log_OC.d(TAG,  "Location to redirect: " + location.getValue());
             Header location = method.getResponseHeader("Location");
             if (location != null) {
                 Log_OC.d(TAG,  "Location to redirect: " + location.getValue());