diff --git a/CHANGELOG.md b/CHANGELOG.md index b06bb478f..d64f25405 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,9 @@ Group changes to describe their impact on the project, as follows: - Replaced voice recordings file name by localized placeholder text, like for video conferences invitations - Removed jetifier as it is not needed +### Fixed +- Plain copy of encrypted files (when VFS is enabled) not cleaned + ## [5.0.8] - 2023-03-20 ### Fixed diff --git a/app/src/main/java/org/linphone/activities/main/chat/data/ChatMessageContentData.kt b/app/src/main/java/org/linphone/activities/main/chat/data/ChatMessageContentData.kt index 412b99fce..f09c6b6b9 100644 --- a/app/src/main/java/org/linphone/activities/main/chat/data/ChatMessageContentData.kt +++ b/app/src/main/java/org/linphone/activities/main/chat/data/ChatMessageContentData.kt @@ -209,7 +209,7 @@ class ChatMessageContentData( private fun deletePlainFilePath() { val path = filePath.value.orEmpty() if (path.isNotEmpty() && isFileEncrypted) { - Log.i("[Content] Deleting file used for preview: $path") + Log.i("[Content] [VFS] Deleting file used for preview: $path") FileUtils.deleteFile(path) filePath.value = "" } @@ -247,7 +247,7 @@ class ChatMessageContentData( if (content.isFile || (content.isFileTransfer && chatMessage.isOutgoing)) { val path = if (isFileEncrypted) { - Log.i("[Content] Content is encrypted, requesting plain file path") + Log.i("[Content] [VFS] Content is encrypted, requesting plain file path for file [${content.filePath}]") content.exportPlainFile() } else { content.filePath ?: "" diff --git a/app/src/main/java/org/linphone/activities/main/chat/fragments/DetailChatRoomFragment.kt b/app/src/main/java/org/linphone/activities/main/chat/fragments/DetailChatRoomFragment.kt index 51e6d79de..2726fd36a 100644 --- a/app/src/main/java/org/linphone/activities/main/chat/fragments/DetailChatRoomFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/chat/fragments/DetailChatRoomFragment.kt @@ -1204,16 +1204,10 @@ class DetailChatRoomFragment : MasterFragment - Log.e("[Data Binding] [Coil] Error loading [$path]: ${result.throwable}") + Log.e("[Data Binding] [VFS] [Coil] Error loading [$path]: ${result.throwable}") } ) } diff --git a/app/src/main/java/org/linphone/utils/FileUtils.kt b/app/src/main/java/org/linphone/utils/FileUtils.kt index 325332254..1b7a93444 100644 --- a/app/src/main/java/org/linphone/utils/FileUtils.kt +++ b/app/src/main/java/org/linphone/utils/FileUtils.kt @@ -37,13 +37,12 @@ import kotlinx.coroutines.async import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.withContext import org.linphone.LinphoneApplication.Companion.coreContext +import org.linphone.LinphoneApplication.Companion.corePreferences import org.linphone.R import org.linphone.core.tools.Log class FileUtils { companion object { - const val VFS_PLAIN_FILE_EXTENSION = ".bctbx_evfs_plain" - fun getNameFromFilePath(filePath: String): String { var name = filePath val i = filePath.lastIndexOf('/') @@ -54,15 +53,11 @@ class FileUtils { } fun getExtensionFromFileName(fileName: String): String { - val realFileName = if (fileName.endsWith(VFS_PLAIN_FILE_EXTENSION)) { - fileName.substring(0, fileName.length - VFS_PLAIN_FILE_EXTENSION.length) - } else fileName - - var extension = MimeTypeMap.getFileExtensionFromUrl(realFileName) + var extension = MimeTypeMap.getFileExtensionFromUrl(fileName) if (extension.isNullOrEmpty()) { - val i = realFileName.lastIndexOf('.') + val i = fileName.lastIndexOf('.') if (i > 0) { - extension = realFileName.substring(i + 1) + extension = fileName.substring(i + 1) } } @@ -102,21 +97,10 @@ class FileUtils { } fun clearExistingPlainFiles() { - for (file in coreContext.context.filesDir.listFiles().orEmpty()) { - if (file.path.endsWith(VFS_PLAIN_FILE_EXTENSION)) { - Log.w("[File Utils] Found forgotten plain file: ${file.path}, deleting it") - deleteFile(file.path) - } - } - for (file in coreContext.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)?.listFiles().orEmpty()) { - if (file.path.endsWith(VFS_PLAIN_FILE_EXTENSION)) { - Log.w("[File Utils] Found forgotten plain file: ${file.path}, deleting it") - deleteFile(file.path) - } - } - for (file in coreContext.context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)?.listFiles().orEmpty()) { - if (file.path.endsWith(VFS_PLAIN_FILE_EXTENSION)) { - Log.w("[File Utils] Found forgotten plain file: ${file.path}, deleting it") + val dir = File(corePreferences.vfsCachePath) + if (dir.exists()) { + for (file in dir.listFiles().orEmpty()) { + Log.w("[File Utils] [VFS] Found forgotten plain file [${file.path}], deleting it") deleteFile(file.path) } } @@ -144,14 +128,10 @@ class FileUtils { val path = coreContext.context.cacheDir Log.i("[File Utils] Cache directory is: $path") - val realFileName = if (fileName.endsWith(VFS_PLAIN_FILE_EXTENSION)) { - fileName.substring(0, fileName.length - VFS_PLAIN_FILE_EXTENSION.length) - } else fileName - var file = File(path, realFileName) - + var file = File(path, fileName) var prefix = 1 while (file.exists()) { - file = File(path, prefix.toString() + "_" + realFileName) + file = File(path, prefix.toString() + "_" + fileName) Log.w("[File Utils] File with that name already exists, renamed to ${file.name}") prefix += 1 } @@ -299,7 +279,9 @@ class FileUtils { } else { Log.e("[File Utils] Copy failed") } - remoteFile?.close() + withContext(Dispatchers.IO) { + remoteFile?.close() + } } } catch (e: IOException) { Log.e("[File Utils] getFilePath exception: ", e) @@ -535,5 +517,13 @@ class FileUtils { outStream.flush() outStream.close() } + + fun countFilesInDirectory(path: String): Int { + val dir = File(path) + if (dir.exists()) { + return dir.listFiles().orEmpty().size + } + return -1 + } } }