Skip to content

Commit 101fb9f

Browse files
marconeAndroid (Google) Code Review
authored andcommitted
Merge "Handle _ and % in paths" into jb-dev
2 parents ed82973 + b4b8478 commit 101fb9f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

media/java/android/media/MediaScanner.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,9 @@ FileEntry makeEntryFor(String path) {
14441444
String where;
14451445
String[] selectionArgs;
14461446
if (mCaseInsensitivePaths) {
1447-
where = Files.FileColumns.DATA + " LIKE ?";
1447+
// the 'like' makes it use the index, the 'lower()' makes it correct
1448+
// when the path contains sqlite wildcard characters
1449+
where = "_data LIKE ?1 AND lower(_data)=lower(?1)";
14481450
selectionArgs = new String[] { path };
14491451
} else {
14501452
where = Files.FileColumns.DATA + "=?";

media/java/android/mtp/MtpDatabase.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,8 +932,11 @@ private int deleteFile(int handle) {
932932
if (format == MtpConstants.FORMAT_ASSOCIATION) {
933933
// recursive case - delete all children first
934934
Uri uri = Files.getMtpObjectsUri(mVolumeName);
935-
int count = mMediaProvider.delete(uri, "_data LIKE ?",
936-
new String[] { path + "/%"});
935+
int count = mMediaProvider.delete(uri,
936+
// the 'like' makes it use the index, the 'lower()' makes it correct
937+
// when the path contains sqlite wildcard characters
938+
"_data LIKE ? AND lower(substr(_data,?))=lower(?)",
939+
new String[] { path + "/%", "" + path.length() + 1, path + "/"});
937940
}
938941

939942
Uri uri = Files.getMtpObjectsUri(mVolumeName, handle);

0 commit comments

Comments
 (0)