Skip to content

Commit 732e703

Browse files
committed
do not lowercase deleted path urls + some safety checks
1 parent 7658651 commit 732e703

File tree

7 files changed

+19
-10
lines changed

7 files changed

+19
-10
lines changed

app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,11 @@ class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesLis
204204
private fun deleteItem(file: File) {
205205
if (needsStupidWritePermissions(file.absolutePath)) {
206206
if (!isShowingPermDialog(file)) {
207-
getFileDocument(file.absolutePath, mConfig.treeUri).delete()
207+
val document = getFileDocument(file.absolutePath, mConfig.treeUri)
208+
209+
// double check we have the uri to the proper file path, not some parent folder
210+
if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath()))
211+
document.delete()
208212
}
209213
} else {
210214
file.delete()

app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,17 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media
231231
for (delPath in mToBeDeleted) {
232232
val file = File(delPath)
233233
if (file.exists() && file.isPhotoVideo()) {
234-
if (needsStupidWritePermissions(delPath)) {
234+
if (needsStupidWritePermissions(file.absolutePath)) {
235235
if (isShowingPermDialog(file))
236236
return
237237

238-
if (getFileDocument(delPath, mConfig.treeUri).delete()) {
239-
wereFilesDeleted = true
238+
val document = getFileDocument(file.absolutePath, mConfig.treeUri)
239+
240+
// double check we have the uri to the proper file path, not some parent folder
241+
if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath())) {
242+
if (document.delete()) {
243+
wereFilesDeleted = true
244+
}
240245
}
241246
} else {
242247
if (file.delete())
@@ -251,8 +256,8 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media
251256
finish()
252257
}
253258
}
254-
mToBeDeleted.clear()
255259
}
260+
mToBeDeleted.clear()
256261
}
257262

258263
private val undoDeletion = View.OnClickListener {

app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
343343

344344
private fun deleteDirectoryIfEmpty() {
345345
val file = File(mDirectory)
346-
if (file.isDirectory && file.listFiles().size == 0) {
346+
if (file.isDirectory && file.listFiles().isEmpty()) {
347347
file.delete()
348348
}
349349

app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
187187
private fun prepareForDeleting() {
188188
val selections = multiSelector.selectedPositions
189189
val paths = ArrayList<String>(selections.size)
190-
selections.forEach { paths.add(dirs[it].path.toLowerCase()) }
190+
selections.forEach { paths.add(dirs[it].path) }
191191
listener?.prepareForDeleting(paths)
192192
}
193193

app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class MediaAdapter(val activity: SimpleActivity, val media: MutableList<Medium>,
137137
private fun prepareForDeleting() {
138138
val selections = multiSelector.selectedPositions
139139
val paths = ArrayList<String>(selections.size)
140-
selections.forEach { paths.add(media[it].path.toLowerCase()) }
140+
selections.forEach { paths.add(media[it].path) }
141141
listener?.prepareForDeleting(paths)
142142
}
143143

app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
6565
val newImageCnt = directory.mediaCnt + 1
6666
directory.mediaCnt = newImageCnt
6767
directory.addSize(file.length())
68-
} else if (!mToBeDeleted.contains(parentDir.toLowerCase())) {
68+
} else if (!mToBeDeleted.contains(parentDir)) {
6969
var dirName = context.getHumanizedFilename(parentDir)
7070
if (mConfig.getIsFolderHidden(parentDir)) {
7171
dirName += " ${context.resources.getString(R.string.hidden)}"

app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
5151
do {
5252
val curPath = cursor.getString(pathIndex) ?: continue
5353

54-
if (curPath.matches(pattern.toRegex()) && !mToBeDeleted.contains(curPath.toLowerCase())) {
54+
if (curPath.matches(pattern.toRegex()) && !mToBeDeleted.contains(curPath)) {
5555
val file = File(curPath)
5656
if (file.exists()) {
5757
val dateIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_MODIFIED)

0 commit comments

Comments
 (0)