- RemoteOperationResult uploadResult = null, grantResult = null;
-
- try {
- /// prepare client object to send requests to the ownCloud server
- if (mUploadClient == null || !mLastAccount.equals(mCurrentUpload.getAccount())) {
- mLastAccount = mCurrentUpload.getAccount();
- mStorageManager =
- new FileDataStorageManager(mLastAccount, getContentResolver());
- OwnCloudAccount ocAccount = new OwnCloudAccount(mLastAccount, this);
- mUploadClient = OwnCloudClientManagerFactory.getDefaultSingleton().
- getClientFor(ocAccount, this);
- }
-
- /// check the existence of the parent folder for the file to upload
- String remoteParentPath = new File(mCurrentUpload.getRemotePath()).getParent();
- remoteParentPath = remoteParentPath.endsWith(OCFile.PATH_SEPARATOR) ? remoteParentPath : remoteParentPath + OCFile.PATH_SEPARATOR;
- grantResult = grantFolderExistence(remoteParentPath);
-
- /// perform the upload
- if (grantResult.isSuccess()) {
- OCFile parent = mStorageManager.getFileByPath(remoteParentPath);
- mCurrentUpload.getFile().setParentId(parent.getFileId());
- uploadResult = mCurrentUpload.execute(mUploadClient);
- if (uploadResult.isSuccess()) {
- saveUploadedFile();
+ notifyUploadStart(mCurrentUpload);
+
+ RemoteOperationResult uploadResult = null, grantResult = null;
+
+ try {
+ /// prepare client object to send requests to the ownCloud server
+ if (mUploadClient == null ||
+ !mLastAccount.equals(mCurrentUpload.getAccount())) {
+ mLastAccount = mCurrentUpload.getAccount();
+ mStorageManager =
+ new FileDataStorageManager(mLastAccount, getContentResolver());
+ OwnCloudAccount ocAccount = new OwnCloudAccount(mLastAccount, this);
+ mUploadClient = OwnCloudClientManagerFactory.getDefaultSingleton().
+ getClientFor(ocAccount, this);
+ }
+
+ /// check the existence of the parent folder for the file to upload
+ String remoteParentPath = new File(mCurrentUpload.getRemotePath()).getParent();
+ remoteParentPath = remoteParentPath.endsWith(OCFile.PATH_SEPARATOR) ?
+ remoteParentPath : remoteParentPath + OCFile.PATH_SEPARATOR;
+ grantResult = grantFolderExistence(remoteParentPath);
+
+ /// perform the upload
+ if (grantResult.isSuccess()) {
+ OCFile parent = mStorageManager.getFileByPath(remoteParentPath);
+ mCurrentUpload.getFile().setParentId(parent.getFileId());
+ uploadResult = mCurrentUpload.execute(mUploadClient);
+ if (uploadResult.isSuccess()) {
+ saveUploadedFile();
+ }
+ } else {
+ uploadResult = grantResult;
+ }
+
+ } catch (AccountsException e) {
+ Log_OC.e(TAG, "Error while trying to get autorization for " +
+ mLastAccount.name, e);
+ uploadResult = new RemoteOperationResult(e);
+
+ } catch (IOException e) {
+ Log_OC.e(TAG, "Error while trying to get autorization for " +
+ mLastAccount.name, e);
+ uploadResult = new RemoteOperationResult(e);
+
+ } finally {
+ synchronized (mPendingUploads) {
+ mPendingUploads.remove(uploadKey);
+ Log_OC.i(TAG, "Remove CurrentUploadItem from pending upload Item Map.");
+ }
+ if (uploadResult.isException()) {
+ // enforce the creation of a new client object for next uploads;
+ // this grant that a new socket will be created in the future if
+ // the current exception is due to an abrupt lose of network connection
+ mUploadClient = null;