Perform database moveObject after actual move.
For folders to recursively update their paths,
MediaProvider expects the folder to already exist
when database moveObject is called.
Bug: 66925416
Test: Move a folder containing files and use content query --uri content://media/external/file to verify paths are correct.
Change-Id: I45668159d2d3f99db088d8d4dcd065a79b732c44
diff --git a/media/mtp/MtpServer.cpp b/media/mtp/MtpServer.cpp
index a0944a9..7b3e96e 100644
--- a/media/mtp/MtpServer.cpp
+++ b/media/mtp/MtpServer.cpp
@@ -1062,10 +1062,6 @@
path += "/";
path += info.mName;
- result = mDatabase->moveObject(objectHandle, parent, storageID, path);
- if (result != MTP_RESPONSE_OK)
- return result;
-
if (info.mStorageID == storageID) {
ALOGV("Moving file from %s to %s", (const char*)fromPath, (const char*)path);
if (rename(fromPath, path)) {
@@ -1092,10 +1088,8 @@
}
// If the move failed, undo the database change
- if (result != MTP_RESPONSE_OK)
- if (mDatabase->moveObject(objectHandle, info.mParent, info.mStorageID,
- fromPath) != MTP_RESPONSE_OK)
- ALOGE("Couldn't undo failed move");
+ if (result == MTP_RESPONSE_OK)
+ result = mDatabase->moveObject(objectHandle, parent, storageID, path);
return result;
}