Just in case, clean up any existing plain file when core starts if VFS is enabled

This commit is contained in:
Sylvain Berfini 2022-01-04 11:47:21 +01:00
parent fc6792687c
commit 1522d3b17d
2 changed files with 25 additions and 0 deletions

View file

@ -317,6 +317,10 @@ class CoreContext(val context: Context, coreConfig: Config) {
EmojiCompat.init(BundledEmojiCompatConfig(context))
collator.strength = Collator.NO_DECOMPOSITION
if (corePreferences.vfsEnabled) {
FileUtils.clearExistingPlainFiles()
}
Log.i("[Context] Started")
}

View file

@ -99,6 +99,27 @@ class FileUtils {
return type?.startsWith("audio/") ?: false
}
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")
deleteFile(file.path)
}
}
}
fun getFileStorageDir(isPicture: Boolean = false): File {
var path: File? = null
if (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) {