-Subproject commit 2157723124a15dffb0a142c25e4ca706558acc48
+Subproject commit 16d237e42ad8338aea13365f6a50459f3b6c1fd8
// }
- public void removeFile(OCFile file, boolean removeDBData, boolean removeLocalCopy) {
+ public boolean removeFile(OCFile file, boolean removeDBData, boolean removeLocalCopy) {
+ boolean success = true;
if (file != null) {
if (file.isFolder()) {
- removeFolder(file, removeDBData, removeLocalCopy);
+ success = removeFolder(file, removeDBData, removeLocalCopy);
} else {
if (removeDBData) {
Uri file_uri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, file.getFileId());
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?" + " AND " + ProviderTableMeta.FILE_PATH + "=?";
String [] whereArgs = new String[]{mAccount.name, file.getRemotePath()};
+ int deleted = 0;
if (getContentProviderClient() != null) {
try {
- getContentProviderClient().delete(file_uri, where, whereArgs);
+ deleted = getContentProviderClient().delete(file_uri, where, whereArgs);
} catch (RemoteException e) {
e.printStackTrace();
}
} else {
- getContentResolver().delete(file_uri, where, whereArgs);
+ deleted = getContentResolver().delete(file_uri, where, whereArgs);
}
- //updateFolderSize(file.getParentId());
+ success &= (deleted > 0);
}
- if (removeLocalCopy && file.isDown() && file.getStoragePath() != null) {
- boolean success = new File(file.getStoragePath()).delete();
+ if (removeLocalCopy && file.isDown() && file.getStoragePath() != null && success) {
+ success = new File(file.getStoragePath()).delete();
if (!removeDBData && success) {
// maybe unnecessary, but should be checked TODO remove if unnecessary
file.setStoragePath(null);
}
}
}
+ return success;
}
- public void removeFolder(OCFile folder, boolean removeDBData, boolean removeLocalContent) {
+ public boolean removeFolder(OCFile folder, boolean removeDBData, boolean removeLocalContent) {
+ boolean success = true;
if (folder != null && folder.isFolder()) {
if (removeDBData && folder.getFileId() != -1) {
- removeFolderInDb(folder);
+ success = removeFolderInDb(folder);
}
- if (removeLocalContent) {
+ if (removeLocalContent && success) {
File localFolder = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, folder));
- removeLocalFolder(localFolder);
+ success = removeLocalFolder(localFolder);
}
}
+ return success;
}
- private void removeFolderInDb(OCFile folder) {
+ private boolean removeFolderInDb(OCFile folder) {
Uri folder_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, ""+ folder.getFileId()); // URI for recursive deletion
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?" + " AND " + ProviderTableMeta.FILE_PATH + "=?";
String [] whereArgs = new String[]{mAccount.name, folder.getRemotePath()};
+ int deleted = 0;
if (getContentProviderClient() != null) {
try {
- getContentProviderClient().delete(folder_uri, where, whereArgs);
+ deleted = getContentProviderClient().delete(folder_uri, where, whereArgs);
} catch (RemoteException e) {
e.printStackTrace();
}
} else {
- getContentResolver().delete(folder_uri, where, whereArgs);
+ deleted = getContentResolver().delete(folder_uri, where, whereArgs);
}
- //updateFolderSize(folder.getParentId());
+ return deleted > 0;
}
- private void removeLocalFolder(File folder) {
+ private boolean removeLocalFolder(File folder) {
+ boolean success = true;
if (folder.exists()) {
File[] files = folder.listFiles();
if (files != null) {
for (File file : files) {
if (file.isDirectory()) {
- removeLocalFolder(file);
+ success &= removeLocalFolder(file);
} else {
- file.delete();
+ success &= file.delete();
}
}
}
- folder.delete();
+ success &= folder.delete();
}
+ return success;
}
/**
}
- public void removeFile(OCFile file, boolean removeLocalCopy) {
+ public void removeFile(OCFile file, boolean onlyLocalCopy) {
// RemoveFile
Intent service = new Intent(mFileActivity, OperationsService.class);
service.setAction(OperationsService.ACTION_REMOVE);
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
- service.putExtra(OperationsService.EXTRA_REMOVE_LOCAL_COPY, removeLocalCopy);
+ service.putExtra(OperationsService.EXTRA_REMOVE_ONLY_LOCAL, onlyLocalCopy);
mFileActivity.getOperationsServiceBinder().newOperation(service);
mFileActivity.showLoadingDialog();
OCFile mFileToRemove;
String mRemotePath;
- boolean mDeleteLocalCopy;
+ boolean mOnlyLocalCopy;
/**
* Constructor
*
- * @param remotePath RemotePath of the OCFile instance describing the remote file or folder to remove from the server
- * @param deleteLocalCopy When 'true', and a local copy of the file exists, it is also removed.
+ * @param remotePath RemotePath of the OCFile instance describing the remote file or
+ * folder to remove from the server
+ * @param onlyLocalCopy When 'true', and a local copy of the file exists, only this is
+ * removed.
*/
- public RemoveFileOperation(String remotePath, boolean deleteLocalCopy) {
+ public RemoveFileOperation(String remotePath, boolean onlyLocalCopy) {
mRemotePath = remotePath;
- mDeleteLocalCopy = deleteLocalCopy;
+ mOnlyLocalCopy = onlyLocalCopy;
}
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
- RemoveRemoteFileOperation operation = new RemoveRemoteFileOperation(mRemotePath);
- result = operation.execute(client);
-
mFileToRemove = getStorageManager().getFileByPath(mRemotePath);
+
+ boolean localRemovalFailed = false;
+ if (!mOnlyLocalCopy) {
+ RemoveRemoteFileOperation operation = new RemoveRemoteFileOperation(mRemotePath);
+ result = operation.execute(client);
+ if (result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND) {
+ localRemovalFailed = !(getStorageManager().removeFile(mFileToRemove, true, true));
+ }
+
+ } else {
+ localRemovalFailed = !(getStorageManager().removeFile(mFileToRemove, false, true));
+ if (!localRemovalFailed) {
+ result = new RemoteOperationResult(ResultCode.OK);
+ }
+ }
- if (result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND) {
- getStorageManager().removeFile(mFileToRemove, true, mDeleteLocalCopy);
+ if (localRemovalFailed) {
+ result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_REMOVED);
}
return result;
public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
public static final String EXTRA_SEND_INTENT = "SEND_INTENT";
public static final String EXTRA_NEWNAME = "NEWNAME";
- public static final String EXTRA_REMOVE_LOCAL_COPY = "REMOVE_LOCAL_COPY";
+ public static final String EXTRA_REMOVE_ONLY_LOCAL = "REMOVE_LOCAL_COPY";
public static final String EXTRA_CREATE_FULL_PATH = "CREATE_FULL_PATH";
public static final String EXTRA_RESULT = "RESULT";
} else if (action.equals(ACTION_REMOVE)) {
// Remove file or folder
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
- boolean removeLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_LOCAL_COPY, true);
- operation = new RemoveFileOperation(remotePath, removeLocalCopy);
+ boolean onlyLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL, false);
+ operation = new RemoveFileOperation(remotePath, onlyLocalCopy);
} else if (action.equals(ACTION_CREATE_FOLDER)) {
// Create Folder
OCFile file = getFile();
if (callerTag.equals(FTAG_CONFIRMATION)) {
if (mContainerActivity.getStorageManager().getFileById(file.getFileId()) != null) {
- mContainerActivity.getFileOperationsHelper().removeFile(file, true);
+ mContainerActivity.getFileOperationsHelper().removeFile(file, false);
}
}
}
@Override
public void onNeutral(String callerTag) {
OCFile file = getFile();
- mContainerActivity.getStorageManager().removeFile(file, false, true); // TODO perform in background task / new thread
- if (file.getStoragePath() != null) {
- file.setStoragePath(null);
- updateFileDetails(file, mAccount);
- }
+ mContainerActivity.getFileOperationsHelper().removeFile(file, true);
+ //if (file.getStoragePath() != null) {
+ // file.setStoragePath(null);
+ // updateFileDetails(file, mAccount);
+ //}
}
@Override
if (callerTag.equals(FileDetailFragment.FTAG_CONFIRMATION)) {
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
if (storageManager.getFileById(mTargetFile.getFileId()) != null) {
- mContainerActivity.getFileOperationsHelper().removeFile(mTargetFile, true);
+ mContainerActivity.getFileOperationsHelper().removeFile(mTargetFile, false);
}
}
}
@Override
public void onNeutral(String callerTag) {
- mContainerActivity.getStorageManager().removeFile(mTargetFile, false, true); // TODO perform in background task / new thread
- listDirectory();
- mContainerActivity.onTransferStateChanged(mTargetFile, false, false);
+ mContainerActivity.getFileOperationsHelper().removeFile(mTargetFile, true);
+ //listDirectory();
+ //mContainerActivity.onTransferStateChanged(mTargetFile, false, false);
}
@Override
public void onConfirmation(String callerTag) {
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
if (storageManager.getFileById(getFile().getFileId()) != null) { // check that the file is still there;
- mContainerActivity.getFileOperationsHelper().removeFile(getFile(), true);
+ mContainerActivity.getFileOperationsHelper().removeFile(getFile(), false);
}
}
@Override
public void onNeutral(String callerTag) {
OCFile file = getFile();
- mContainerActivity.getStorageManager().removeFile(file, false, true); // TODO perform in background task / new thread
- finish();
+ mContainerActivity.getFileOperationsHelper().removeFile(file, true);
+ //mContainerActivity.getStorageManager().removeFile(file, false, true); // TODO perform in background task / new thread
+ //finish();
}
/**
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
if (storageManager.getFileById(file.getFileId()) != null) { // check that the file is still there;
stopPreview(true);
- mContainerActivity.getFileOperationsHelper().removeFile(file, true);
+ mContainerActivity.getFileOperationsHelper().removeFile(file, false);
}
}
public void onNeutral(String callerTag) {
OCFile file = getFile();
stopPreview(true);
- mContainerActivity.getStorageManager().removeFile(file, false, true); // TODO perform in background task / new thread
- finish();
+ //mContainerActivity.getStorageManager().removeFile(file, false, true); // TODO perform in background task / new thread
+ mContainerActivity.getFileOperationsHelper().removeFile(file, true);
+ //finish();
}
/**