Merge "Wire removeDocument() to Jobs." into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1bf6ed9fb8
@@ -376,7 +376,7 @@ class CopyJob extends Job {
|
||||
if (Document.MIME_TYPE_DIR.equals(src.mimeType)) {
|
||||
copyDirectoryHelper(src, dstInfo);
|
||||
} else {
|
||||
copyFileHelper(src, dstInfo, dstMimeType);
|
||||
copyFileHelper(src, dstInfo, dest, dstMimeType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,13 +439,14 @@ class CopyJob extends Job {
|
||||
/**
|
||||
* Handles copying a single file.
|
||||
*
|
||||
* @param srcUriInfo Info of the file to copy from.
|
||||
* @param dstUriInfo Info of the *file* to copy to. Must be created beforehand.
|
||||
* @param src Info of the file to copy from.
|
||||
* @param dest Info of the *file* to copy to. Must be created beforehand.
|
||||
* @param destParent Info of the parent of the destination.
|
||||
* @param mimeType Mime type for the target. Can be different than source for virtual files.
|
||||
* @throws ResourceException
|
||||
*/
|
||||
private void copyFileHelper(DocumentInfo src, DocumentInfo dest, String mimeType)
|
||||
throws ResourceException {
|
||||
private void copyFileHelper(DocumentInfo src, DocumentInfo dest, DocumentInfo destParent,
|
||||
String mimeType) throws ResourceException {
|
||||
CancellationSignal canceller = new CancellationSignal();
|
||||
AssetFileDescriptor srcFileAsAsset = null;
|
||||
ParcelFileDescriptor srcFile = null;
|
||||
@@ -527,8 +528,8 @@ class CopyJob extends Job {
|
||||
if (DEBUG) Log.d(TAG, "Cleaning up failed operation leftovers.");
|
||||
canceller.cancel();
|
||||
try {
|
||||
DocumentsContract.deleteDocument(getClient(dest), dest.derivedUri);
|
||||
} catch (RemoteException | RuntimeException e) {
|
||||
deleteDocument(dest, destParent);
|
||||
} catch (ResourceException e) {
|
||||
Log.w(TAG, "Failed to cleanup after copy error: " + src.derivedUri, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ final class DeleteJob extends Job {
|
||||
for (DocumentInfo doc : mSrcs) {
|
||||
if (DEBUG) Log.d(TAG, "Deleting document @ " + doc.derivedUri);
|
||||
try {
|
||||
deleteDocument(doc);
|
||||
deleteDocument(doc, mSrcParent);
|
||||
} catch (ResourceException e) {
|
||||
Log.e(TAG, "Failed to delete document @ " + doc.derivedUri);
|
||||
onFileFailed(doc);
|
||||
|
||||
@@ -184,10 +184,17 @@ abstract public class Job implements Runnable {
|
||||
return false;
|
||||
}
|
||||
|
||||
final void deleteDocument(DocumentInfo doc) throws ResourceException {
|
||||
final void deleteDocument(DocumentInfo doc, DocumentInfo parent) throws ResourceException {
|
||||
try {
|
||||
DocumentsContract.deleteDocument(getClient(doc), doc.derivedUri);
|
||||
} catch (Exception e) {
|
||||
if (doc.isRemoveSupported()) {
|
||||
DocumentsContract.removeDocument(getClient(doc), doc.derivedUri, parent.derivedUri);
|
||||
} else if (doc.isDeleteSupported()) {
|
||||
DocumentsContract.deleteDocument(getClient(doc), doc.derivedUri);
|
||||
} else {
|
||||
throw new ResourceException("Unable to delete source document as the file is " +
|
||||
"not deletable nor removable: %s.", doc.derivedUri);
|
||||
}
|
||||
} catch (RemoteException | RuntimeException e) {
|
||||
throw new ResourceException("Failed to delete file %s due to an exception.",
|
||||
doc.derivedUri, e);
|
||||
}
|
||||
|
||||
@@ -115,6 +115,9 @@ final class MoveJob extends CopyJob {
|
||||
|
||||
// If we couldn't do an optimized copy...we fall back to vanilla byte copy.
|
||||
byteCopyDocument(src, dest);
|
||||
|
||||
// Remove the source document.
|
||||
deleteDocument(src, srcParent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user