*/
public void cancelTransference(OCFile file) {
Account account = mFileActivity.getAccount();
- if (!file.isFolder()) {
- FileDownloaderBinder downloaderBinder = mFileActivity.getFileDownloaderBinder();
- FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder();
- //if (downloaderBinder != null && file.isDownloading()) {
- if (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) {
- // Remove etag for parent, if file is a keep_in_sync
- if (file.keepInSync()) {
- OCFile parent = mFileActivity.getStorageManager().getFileById(file.getParentId());
- parent.setEtag("");
- mFileActivity.getStorageManager().saveFile(parent);
- }
-
- downloaderBinder.cancel(account, file);
-
- } else if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) {
- uploaderBinder.cancel(account, file);
- }
- } else {
+ if (file.isFolder()) {
+ // this goes to the queue!! :S
Intent intent = new Intent(mFileActivity, OperationsService.class);
intent.setAction(OperationsService.ACTION_CANCEL_SYNC_FOLDER);
intent.putExtra(OperationsService.EXTRA_ACCOUNT, account);
intent.putExtra(OperationsService.EXTRA_FILE, file);
mFileActivity.startService(intent);
+ }
+
+ // for both files and folders
+ FileDownloaderBinder downloaderBinder = mFileActivity.getFileDownloaderBinder();
+ FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder();
+ //if (downloaderBinder != null && file.isDownloading()) {
+ if (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) {
+ downloaderBinder.cancel(account, file);
+
+ // TODO - review why is this here, and solve in a better way
+ // Remove etag for parent, if file is a keep_in_sync
+ if (file.keepInSync()) {
+ OCFile parent = mFileActivity.getStorageManager().getFileById(file.getParentId());
+ parent.setEtag("");
+ mFileActivity.getStorageManager().saveFile(parent);
+ }
+ } else if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) {
+ uploaderBinder.cancel(account, file);
}
}
/**
* Cancels a pending or current download of a remote file.
*
- * @param account Owncloud account where the remote file is stored.
+ * @param account ownCloud account where the remote file is stored.
* @param file A file in the queue of pending downloads
*/
public void cancel(Account account, OCFile file) {
download = mPendingDownloads.remove(account, file.getRemotePath());
if (download != null) {
download.cancel();
+ } else {
+ // TODO synchronize
+ if (mCurrentDownload.getRemotePath().startsWith(file.getRemotePath()) &&
+ account.name.equals(mLastAccount)) {
+ mCurrentDownload.cancel();
+ }
}
}
import java.io.File;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Node<V> firstRemoved = mMap.remove(targetKey);
if (firstRemoved != null) {
+ /// remove children
+ removeDescendants(firstRemoved);
+
+ /// remove ancestors if only here due to firstRemoved
Node<V> removed = firstRemoved;
Node<V> parent = removed.getParent();
while (parent != null) {
}
+ private void removeDescendants(Node<V> removed) {
+ Iterator<Node<V>> childrenIt = removed.getChildren().iterator();
+ Node<V> child = null;
+ while (childrenIt.hasNext()) {
+ child = childrenIt.next();
+ mMap.remove(child.getKey());
+ removeDescendants(child);
+ }
+ }
+
public boolean contains(Account account, String remotePath) {
String targetKey = buildKey(account, remotePath);
return mMap.containsKey(targetKey);
// WIP: for the moment, only SYNC_FOLDER and CANCEL_SYNC_FOLDER is expected here;
// the rest of the operations are requested through the Binder
if (ACTION_SYNC_FOLDER.equals(intent.getAction())) {
+
if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_REMOTE_PATH)) {
Log_OC.e(TAG, "Not enough information provided in intent");
return START_NOT_STICKY;
msg.obj = itemSyncKey;
mSyncFolderHandler.sendMessage(msg);
}
+
} else if (ACTION_CANCEL_SYNC_FOLDER.equals(intent.getAction())) {
if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_FILE)) {
Log_OC.e(TAG, "Not enough information provided in intent");
}
//sendBroadcastFinishedSyncFolder(account, file.getRemotePath());
-
- /// cancellation of download needs to be done separately in any case; a SynchronizeFolderOperation
- // may finish much sooner than the real download of the files in the folder
- Intent intent = new Intent(mService, FileDownloader.class);
- intent.setAction(FileDownloader.ACTION_CANCEL_FILE_DOWNLOAD);
- intent.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
- intent.putExtra(FileDownloader.EXTRA_FILE, file);
- mService.startService(intent);
}
/**