diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index b6f21a5cb0..513a639f24 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -174,10 +174,11 @@ public class FileDownloader extends Service Pair putResult = mPendingDownloads.putIfAbsent( account, file.getRemotePath(), newDownload ); - String downloadKey = putResult.first; - requestedDownloads.add(downloadKey); - - sendBroadcastNewDownload(newDownload, putResult.second); + if (putResult != null) { + String downloadKey = putResult.first; + requestedDownloads.add(downloadKey); + sendBroadcastNewDownload(newDownload, putResult.second); + } // else, file already in the queue of downloads; don't repeat the request } catch (IllegalArgumentException e) { Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage()); diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index df4dccdac0..89dc8b8553 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -300,8 +300,10 @@ public class FileUploader extends Service Pair putResult = mPendingUploads.putIfAbsent( account, files[i].getRemotePath(), newUpload ); - uploadKey = putResult.first; - requestedUploads.add(uploadKey); + if (putResult != null) { + uploadKey = putResult.first; + requestedUploads.add(uploadKey); + } // else, file already in the queue of uploads; don't repeat the request } } catch (IllegalArgumentException e) { diff --git a/src/com/owncloud/android/files/services/IndexedForest.java b/src/com/owncloud/android/files/services/IndexedForest.java index 4c1ac7bd25..8f4ccb67c0 100644 --- a/src/com/owncloud/android/files/services/IndexedForest.java +++ b/src/com/owncloud/android/files/services/IndexedForest.java @@ -101,38 +101,45 @@ public class IndexedForest { public /* synchronized */ Pair putIfAbsent(Account account, String remotePath, V value) { String targetKey = buildKey(account, remotePath); Node valuedNode = new Node(targetKey, value); - mMap.putIfAbsent( - targetKey, - valuedNode + Node previousValue = mMap.putIfAbsent( + targetKey, + valuedNode ); + if (previousValue != null) { + // remotePath already known; not replaced + return null; - String currentPath = remotePath, parentPath = null, parentKey = null; - Node currentNode = valuedNode, parentNode = null; - boolean linked = false; - while (!OCFile.ROOT_PATH.equals(currentPath) && !linked) { - parentPath = new File(currentPath).getParent(); - if (!parentPath.endsWith(OCFile.PATH_SEPARATOR)) { - parentPath += OCFile.PATH_SEPARATOR; + } else { + // value really added + String currentPath = remotePath, parentPath = null, parentKey = null; + Node currentNode = valuedNode, parentNode = null; + boolean linked = false; + while (!OCFile.ROOT_PATH.equals(currentPath) && !linked) { + parentPath = new File(currentPath).getParent(); + if (!parentPath.endsWith(OCFile.PATH_SEPARATOR)) { + parentPath += OCFile.PATH_SEPARATOR; + } + parentKey = buildKey(account, parentPath); + parentNode = mMap.get(parentKey); + if (parentNode == null) { + parentNode = new Node(parentKey, null); + parentNode.addChild(currentNode); + mMap.put(parentKey, parentNode); + } else { + parentNode.addChild(currentNode); + linked = true; + } + currentPath = parentPath; + currentNode = parentNode; } - parentKey = buildKey(account, parentPath); - parentNode = mMap.get(parentKey); - if (parentNode == null) { - parentNode = new Node(parentKey, null); - parentNode.addChild(currentNode); - mMap.put(parentKey, parentNode); - } else { - parentNode.addChild(currentNode); - linked = true; - } - currentPath = parentPath; - currentNode = parentNode; - } - String linkedTo = OCFile.ROOT_PATH; - if (linked) { - linkedTo = parentNode.getKey().substring(account.name.length()); + String linkedTo = OCFile.ROOT_PATH; + if (linked) { + linkedTo = parentNode.getKey().substring(account.name.length()); + } + + return new Pair(targetKey, linkedTo); } - return new Pair(targetKey, linkedTo); }; diff --git a/src/com/owncloud/android/services/SyncFolderHandler.java b/src/com/owncloud/android/services/SyncFolderHandler.java index 33318f5712..daa16128d1 100644 --- a/src/com/owncloud/android/services/SyncFolderHandler.java +++ b/src/com/owncloud/android/services/SyncFolderHandler.java @@ -138,8 +138,11 @@ class SyncFolderHandler extends Handler { public void add(Account account, String remotePath, SynchronizeFolderOperation syncFolderOperation){ - mPendingOperations.putIfAbsent(account, remotePath, syncFolderOperation); - sendBroadcastNewSyncFolder(account, remotePath); // TODO upgrade! + Pair putResult = + mPendingOperations.putIfAbsent(account, remotePath, syncFolderOperation); + if (putResult != null) { + sendBroadcastNewSyncFolder(account, remotePath); // TODO upgrade! + } } diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index e814c2d3bd..697d7b3ec1 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1047,7 +1047,7 @@ public class FileDisplayActivity extends HookActivity @Override public void onReceive(Context context, Intent intent) { try { - String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH); + String uploadedRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH); String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME); boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name); OCFile currentDir = getCurrentDir(); @@ -1056,7 +1056,7 @@ public class FileDisplayActivity extends HookActivity if (sameAccount && isDescendant) { String linkedToRemotePath = - intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH); + intent.getStringExtra(FileUploader.EXTRA_LINKED_TO_PATH); if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) { refreshListOfFilesFragment(); }