vault: fixed replacing on move to vault
This commit is contained in:
parent
d96a067f18
commit
300ce4f1bd
2 changed files with 26 additions and 14 deletions
|
@ -53,14 +53,16 @@ internal class FileImageProvider : ImageProvider() {
|
|||
}
|
||||
|
||||
override suspend fun delete(contextWrapper: ContextWrapper, uri: Uri, path: String?, mimeType: String) {
|
||||
val file = File(File(uri.path!!).path)
|
||||
if (!file.exists()) return
|
||||
|
||||
Log.d(LOG_TAG, "delete file at uri=$uri")
|
||||
if (file.delete()) return
|
||||
path ?: throw Exception("failed to delete file because path is null")
|
||||
|
||||
val file = File(path)
|
||||
if (file.exists()) {
|
||||
Log.d(LOG_TAG, "delete file at path=$path")
|
||||
if (!file.delete()) {
|
||||
throw Exception("failed to delete entry with uri=$uri path=$path")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun renameSingle(
|
||||
activity: Activity,
|
||||
|
|
|
@ -10,7 +10,6 @@ import android.net.Uri
|
|||
import android.os.Binder
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.core.net.toUri
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.DecodeFormat
|
||||
|
@ -53,9 +52,10 @@ abstract class ImageProvider {
|
|||
|
||||
suspend fun scanNewPath(context: Context, path: String, mimeType: String): FieldMap {
|
||||
return if (StorageUtils.isInVault(context, path)) {
|
||||
val uri = Uri.fromFile(File(path))
|
||||
hashMapOf(
|
||||
"origin" to SourceEntry.ORIGIN_VAULT,
|
||||
"uri" to File(path).toUri().toString(),
|
||||
"uri" to uri.toString(),
|
||||
"contentId" to null,
|
||||
"path" to path,
|
||||
)
|
||||
|
@ -64,6 +64,21 @@ abstract class ImageProvider {
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun deletePath(contextWrapper: ContextWrapper, path: String, mimeType: String) {
|
||||
if (StorageUtils.isInVault(contextWrapper, path)) {
|
||||
FileImageProvider().apply {
|
||||
val uri = Uri.fromFile(File(path))
|
||||
delete(contextWrapper, uri, path, mimeType)
|
||||
}
|
||||
} else {
|
||||
MediaStoreImageProvider().apply {
|
||||
val uri = getContentUriForPath(contextWrapper, path)
|
||||
uri ?: throw Exception("failed to find content URI for path=$path")
|
||||
delete(contextWrapper, uri, path, mimeType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open suspend fun delete(contextWrapper: ContextWrapper, uri: Uri, path: String?, mimeType: String) {
|
||||
throw UnsupportedOperationException("`delete` is not supported by this image provider")
|
||||
}
|
||||
|
@ -461,12 +476,7 @@ abstract class ImageProvider {
|
|||
}
|
||||
NameConflictStrategy.REPLACE -> {
|
||||
if (targetFile.exists()) {
|
||||
val path = targetFile.path
|
||||
MediaStoreImageProvider().apply {
|
||||
val uri = getContentUriForPath(contextWrapper, path)
|
||||
uri ?: throw Exception("failed to find content URI for path=$path")
|
||||
delete(contextWrapper, uri, path, mimeType)
|
||||
}
|
||||
deletePath(contextWrapper, targetFile.path, mimeType)
|
||||
}
|
||||
desiredNameWithoutExtension
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue