MTP: Delete all files and subdirectories when deleting directories.
Children are now recursively deleted from the database and filesystem. Change-Id: Ifd9b48cbc34b84b8f5073f2493dfe9735fae5492 Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
@ -478,12 +478,26 @@ public class MtpDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
private int deleteRecursive(int handle) throws RemoteException {
|
||||
int[] children = getObjectList(0 /* storageID */, 0 /* format */, handle);
|
||||
Uri uri = Files.getMtpObjectsUri(mVolumeName, handle);
|
||||
// delete parent first, to avoid potential infinite recursion
|
||||
int count = mMediaProvider.delete(uri, null, null);
|
||||
if (count == 1) {
|
||||
if (children != null) {
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
count += deleteRecursive(children[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private int deleteFile(int handle) {
|
||||
Log.d(TAG, "deleteFile: " + handle);
|
||||
mDatabaseModified = true;
|
||||
Uri uri = Files.getMtpObjectsUri(mVolumeName, handle);
|
||||
try {
|
||||
if (mMediaProvider.delete(uri, null, null) == 1) {
|
||||
if (deleteRecursive(handle) > 0) {
|
||||
return MtpConstants.RESPONSE_OK;
|
||||
} else {
|
||||
return MtpConstants.RESPONSE_INVALID_OBJECT_HANDLE;
|
||||
|
Reference in New Issue
Block a user