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,13 +53,15 @@ internal class FileImageProvider : ImageProvider() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun delete(contextWrapper: ContextWrapper, uri: Uri, path: String?, mimeType: String) {
|
override suspend fun delete(contextWrapper: ContextWrapper, uri: Uri, path: String?, mimeType: String) {
|
||||||
val file = File(File(uri.path!!).path)
|
path ?: throw Exception("failed to delete file because path is null")
|
||||||
if (!file.exists()) return
|
|
||||||
|
|
||||||
Log.d(LOG_TAG, "delete file at uri=$uri")
|
val file = File(path)
|
||||||
if (file.delete()) return
|
if (file.exists()) {
|
||||||
|
Log.d(LOG_TAG, "delete file at path=$path")
|
||||||
throw Exception("failed to delete entry with uri=$uri path=$path")
|
if (!file.delete()) {
|
||||||
|
throw Exception("failed to delete entry with uri=$uri path=$path")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun renameSingle(
|
override suspend fun renameSingle(
|
||||||
|
|
|
@ -10,7 +10,6 @@ import android.net.Uri
|
||||||
import android.os.Binder
|
import android.os.Binder
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.core.net.toUri
|
|
||||||
import androidx.exifinterface.media.ExifInterface
|
import androidx.exifinterface.media.ExifInterface
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.DecodeFormat
|
import com.bumptech.glide.load.DecodeFormat
|
||||||
|
@ -53,9 +52,10 @@ abstract class ImageProvider {
|
||||||
|
|
||||||
suspend fun scanNewPath(context: Context, path: String, mimeType: String): FieldMap {
|
suspend fun scanNewPath(context: Context, path: String, mimeType: String): FieldMap {
|
||||||
return if (StorageUtils.isInVault(context, path)) {
|
return if (StorageUtils.isInVault(context, path)) {
|
||||||
|
val uri = Uri.fromFile(File(path))
|
||||||
hashMapOf(
|
hashMapOf(
|
||||||
"origin" to SourceEntry.ORIGIN_VAULT,
|
"origin" to SourceEntry.ORIGIN_VAULT,
|
||||||
"uri" to File(path).toUri().toString(),
|
"uri" to uri.toString(),
|
||||||
"contentId" to null,
|
"contentId" to null,
|
||||||
"path" to path,
|
"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) {
|
open suspend fun delete(contextWrapper: ContextWrapper, uri: Uri, path: String?, mimeType: String) {
|
||||||
throw UnsupportedOperationException("`delete` is not supported by this image provider")
|
throw UnsupportedOperationException("`delete` is not supported by this image provider")
|
||||||
}
|
}
|
||||||
|
@ -461,12 +476,7 @@ abstract class ImageProvider {
|
||||||
}
|
}
|
||||||
NameConflictStrategy.REPLACE -> {
|
NameConflictStrategy.REPLACE -> {
|
||||||
if (targetFile.exists()) {
|
if (targetFile.exists()) {
|
||||||
val path = targetFile.path
|
deletePath(contextWrapper, targetFile.path, mimeType)
|
||||||
MediaStoreImageProvider().apply {
|
|
||||||
val uri = getContentUriForPath(contextWrapper, path)
|
|
||||||
uri ?: throw Exception("failed to find content URI for path=$path")
|
|
||||||
delete(contextWrapper, uri, path, mimeType)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
desiredNameWithoutExtension
|
desiredNameWithoutExtension
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue