X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/854d333bd8f39fe76d62bf267ca17e4527560b06..7277d0a8406b5220dcaa60e72e0a8347bfd28e7a:/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 4c1ac7bd..8f4ccb67 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; + + String linkedTo = OCFile.ROOT_PATH; + if (linked) { + linkedTo = parentNode.getKey().substring(account.name.length()); } - currentPath = parentPath; - currentNode = parentNode; - } - String linkedTo = OCFile.ROOT_PATH; - if (linked) { - linkedTo = parentNode.getKey().substring(account.name.length()); + return new Pair(targetKey, linkedTo); } - return new Pair(targetKey, linkedTo); };