X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/265e32dee6f3d92dfde7ede23e3baa2d831923b3..a07937cb6f1d2a19d526e7fcb666c8e66515620d:/src/com/owncloud/android/files/services/IndexedForest.java diff --git a/src/com/owncloud/android/files/services/IndexedForest.java b/src/com/owncloud/android/files/services/IndexedForest.java index 52482993..0f737aad 100644 --- a/src/com/owncloud/android/files/services/IndexedForest.java +++ b/src/com/owncloud/android/files/services/IndexedForest.java @@ -18,6 +18,7 @@ package com.owncloud.android.files.services; import android.accounts.Account; +import android.util.Pair; import com.owncloud.android.datamodel.OCFile; @@ -91,7 +92,7 @@ public class IndexedForest { } - public /* synchronized */ String putIfAbsent(Account account, String remotePath, V value) { + public /* synchronized */ Pair putIfAbsent(Account account, String remotePath, V value) { String targetKey = buildKey(account, remotePath); Node valuedNode = new Node(targetKey, value); mMap.putIfAbsent( @@ -121,12 +122,17 @@ public class IndexedForest { currentNode = parentNode; } - return targetKey; + String linkedTo = OCFile.ROOT_PATH; + if (linked) { + linkedTo = parentNode.getKey().substring(account.name.length()); + } + return new Pair(targetKey, linkedTo); }; - public /* synchronized */ V remove(Account account, String remotePath) { + public /* synchronized */ Pair remove(Account account, String remotePath) { String targetKey = buildKey(account, remotePath); Node firstRemoved = mMap.remove(targetKey); + String unlinkedFrom = null; if (firstRemoved != null) { /// remove children @@ -135,21 +141,26 @@ public class IndexedForest { /// remove ancestors if only here due to firstRemoved Node removed = firstRemoved; Node parent = removed.getParent(); + boolean unlinked = false; while (parent != null) { parent.removeChild(removed); if (!parent.hasChildren()) { removed = mMap.remove(parent.getKey()); parent = removed.getParent(); } else { - parent = null; + break; } } + + if (parent != null) { + unlinkedFrom = parent.getKey().substring(account.name.length()); + } } if (firstRemoved != null) { - return firstRemoved.getPayload(); + return new Pair(firstRemoved.getPayload(), unlinkedFrom); } else { - return null; + return new Pair(null, unlinkedFrom); } }