From: David A. Velasco Date: Tue, 21 Jul 2015 14:51:29 +0000 (+0200) Subject: Fixed NullPointerExceptionS in upload cancelations X-Git-Tag: oc-android-1.9^2~37^2~19 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/c0c52fa16a79f6be71ffbe7c7cb587af67335793?ds=inline;hp=-c Fixed NullPointerExceptionS in upload cancelations --- c0c52fa16a79f6be71ffbe7c7cb587af67335793 diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index 58f38ed0..71f4bdbb 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -438,13 +438,8 @@ public class FileDownloader extends Service saveDownloadedFile(); } - } catch (AccountsException e) { - Log_OC.e(TAG, "Error while trying to get authorization for " - + mCurrentAccount.name, e); - downloadResult = new RemoteOperationResult(e); - } catch (IOException e) { - Log_OC.e(TAG, "Error while trying to get authorization for " - + mCurrentAccount.name, e); + } catch (Exception e) { + Log_OC.e(TAG, "Error downloading", e); downloadResult = new RemoteOperationResult(e); } finally { diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index c29cdbeb..445274c4 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -583,14 +583,8 @@ public class FileUploader extends Service uploadResult = grantResult; } - } catch (AccountsException e) { - Log_OC.e(TAG, "Error while trying to get autorization for " + - mCurrentAccount.name, e); - uploadResult = new RemoteOperationResult(e); - - } catch (IOException e) { - Log_OC.e(TAG, "Error while trying to get autorization for " + - mCurrentAccount.name, e); + } catch (Exception e) { + Log_OC.e(TAG, "Error uploading", e); uploadResult = new RemoteOperationResult(e); } finally { diff --git a/src/com/owncloud/android/operations/SynchronizeFileOperation.java b/src/com/owncloud/android/operations/SynchronizeFileOperation.java index f94adb15..d7c49f04 100644 --- a/src/com/owncloud/android/operations/SynchronizeFileOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFileOperation.java @@ -221,6 +221,12 @@ public class SynchronizeFileOperation extends SyncOperation { mLocalFile.getLocalModificationTimestamp() > mLocalFile.getLastSyncDateForData() ); + Log_OC.d(TAG, "TOKENs checked to SYNC " + mRemotePath ); + Log_OC.d(TAG, " server#modificationTimestamp " + mServerFile.getModificationTimestamp()); + Log_OC.d(TAG, " local#modificationTimestampAtLastSyncForData " + mServerFile.getModificationTimestampAtLastSyncForData()); + Log_OC.d(TAG, " local#modificationTimestamp " + mLocalFile.getLocalModificationTimestamp()); + Log_OC.d(TAG, " local#lastSyncDateForData " + mLocalFile.getLastSyncDateForData()); + /// decide action to perform depending upon changes //if (!mLocalFile.getEtag().isEmpty() && localChanged && serverChanged) { if (localChanged && serverChanged) { diff --git a/src/com/owncloud/android/operations/UploadFileOperation.java b/src/com/owncloud/android/operations/UploadFileOperation.java index 12cf1ac7..77de090d 100644 --- a/src/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/com/owncloud/android/operations/UploadFileOperation.java @@ -321,52 +321,49 @@ public class UploadFileOperation extends RemoteOperation { while (listener.hasNext()) { mUploadOperation.addDatatransferProgressListener(listener.next()); } - if (!mCancellationRequested.get()) { - result = mUploadOperation.execute(client); - - /// move local temporal file or original file to its corresponding - // location in the ownCloud local folder - if (result.isSuccess()) { - if (mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_FORGET) { - mFile.setStoragePath(null); - - } else { - mFile.setStoragePath(expectedPath); - File fileToMove = null; - if (temporalFile != null) { // FileUploader.LOCAL_BEHAVIOUR_COPY - // ; see where temporalFile was - // set - fileToMove = temporalFile; - } else { // FileUploader.LOCAL_BEHAVIOUR_MOVE - fileToMove = originalFile; - } - if (!expectedFile.equals(fileToMove)) { - File expectedFolder = expectedFile.getParentFile(); - expectedFolder.mkdirs(); - if (!expectedFolder.isDirectory() || !fileToMove.renameTo(expectedFile)) { - mFile.setStoragePath(null); // forget the local file - // by now, treat this as a success; the file was - // uploaded; the user won't like that the local file - // is not linked, but this should be a very rare - // fail; - // the best option could be show a warning message - // (but not a fail) - // result = new - // RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_MOVED); - // return result; - } + if (mCancellationRequested.get()) { + throw new OperationCancelledException(); + } + + result = mUploadOperation.execute(client); + + /// move local temporal file or original file to its corresponding + // location in the ownCloud local folder + if (result.isSuccess()) { + if (mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_FORGET) { + mFile.setStoragePath(null); + + } else { + mFile.setStoragePath(expectedPath); + File fileToMove = null; + if (temporalFile != null) { // FileUploader.LOCAL_BEHAVIOUR_COPY + // ; see where temporalFile was + // set + fileToMove = temporalFile; + } else { // FileUploader.LOCAL_BEHAVIOUR_MOVE + fileToMove = originalFile; + } + if (!expectedFile.equals(fileToMove)) { + File expectedFolder = expectedFile.getParentFile(); + expectedFolder.mkdirs(); + if (!expectedFolder.isDirectory() || !fileToMove.renameTo(expectedFile)) { + mFile.setStoragePath(null); // forget the local file + // by now, treat this as a success; the file was + // uploaded; the user won't like that the local file + // is not linked, but this should be a very rare + // fail; + // the best option could be show a warning message + // (but not a fail) + // result = new + // RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_MOVED); + // return result; } } } } } catch (Exception e) { - // TODO something cleaner with cancellations - if (mCancellationRequested.get()) { - result = new RemoteOperationResult(new OperationCancelledException()); - } else { - result = new RemoteOperationResult(e); - } + result = new RemoteOperationResult(e); } finally { if (temporalFile != null && !originalFile.equals(temporalFile)) {