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:
Mike Lockwood
2010-09-13 17:15:58 -04:00
parent f4cae9f944
commit ccb6e96194
2 changed files with 79 additions and 7 deletions

View File

@ -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;