Pair<String, String> 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());
public /* synchronized */ Pair<String, String> putIfAbsent(Account account, String remotePath, V value) {
String targetKey = buildKey(account, remotePath);
Node<V> valuedNode = new Node(targetKey, value);
- mMap.putIfAbsent(
- targetKey,
- valuedNode
+ Node<V> previousValue = mMap.putIfAbsent(
+ targetKey,
+ valuedNode
);
+ if (previousValue != null) {
+ // remotePath already known; not replaced
+ return null;
- String currentPath = remotePath, parentPath = null, parentKey = null;
- Node<V> 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<V> 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<String, String>(targetKey, linkedTo);
}
- return new Pair<String, String>(targetKey, linkedTo);
};
public void add(Account account, String remotePath,
SynchronizeFolderOperation syncFolderOperation){
- mPendingOperations.putIfAbsent(account, remotePath, syncFolderOperation);
- sendBroadcastNewSyncFolder(account, remotePath); // TODO upgrade!
+ Pair<String, String> putResult =
+ mPendingOperations.putIfAbsent(account, remotePath, syncFolderOperation);
+ if (putResult != null) {
+ sendBroadcastNewSyncFolder(account, remotePath); // TODO upgrade!
+ }
}
@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();
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();
}