closes #24194: switch to IO dispatcher when cleaning wallpapers

This commit is contained in:
MatthewTighe 2022-03-14 10:49:37 -07:00 committed by mergify[bot]
parent ad95f950bb
commit 154ec3402e

View File

@ -40,17 +40,17 @@ class WallpaperFileManager(
* Remove all wallpapers that are not the [currentWallpaper] or in [availableWallpapers]. * Remove all wallpapers that are not the [currentWallpaper] or in [availableWallpapers].
*/ */
fun clean(currentWallpaper: Wallpaper, availableWallpapers: List<Wallpaper.Remote>) { fun clean(currentWallpaper: Wallpaper, availableWallpapers: List<Wallpaper.Remote>) {
scope.launch {
val wallpapersToKeep = (listOf(currentWallpaper) + availableWallpapers).map { it.name } val wallpapersToKeep = (listOf(currentWallpaper) + availableWallpapers).map { it.name }
cleanChildren(portraitDirectory, wallpapersToKeep) cleanChildren(portraitDirectory, wallpapersToKeep)
cleanChildren(landscapeDirectory, wallpapersToKeep) cleanChildren(landscapeDirectory, wallpapersToKeep)
} }
}
private fun cleanChildren(dir: File, wallpapersToKeep: List<String>) { private fun cleanChildren(dir: File, wallpapersToKeep: List<String>) {
for (file in dir.walkTopDown()) { for (file in dir.walkTopDown()) {
if (file.isDirectory || file.nameWithoutExtension in wallpapersToKeep) continue if (file.isDirectory || file.nameWithoutExtension in wallpapersToKeep) continue
scope.launch {
file.delete() file.delete()
} }
} }
} }
}