Fix wallpaper migration getting stuck on malformed files.
Closes #13769
This commit is contained in:
parent
bdd19f6b47
commit
3a5dc4e731
2 changed files with 28 additions and 5 deletions
|
@ -2061,7 +2061,18 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
|||
* Migrates all recipients using [legacyUri] for their wallpaper to [newUri].
|
||||
* Needed for an app migration.
|
||||
*/
|
||||
fun migrateWallpaperUri(legacyUri: Uri, newUri: Uri): Int {
|
||||
fun migrateWallpaperUri(legacyUri: Uri, newUri: Uri?): Int {
|
||||
if (newUri == null) {
|
||||
return writableDatabase
|
||||
.update(TABLE_NAME)
|
||||
.values(
|
||||
WALLPAPER to null,
|
||||
WALLPAPER_URI to null
|
||||
)
|
||||
.where("$WALLPAPER_URI = ?", legacyUri)
|
||||
.run()
|
||||
}
|
||||
|
||||
val newWallpaper = ChatWallpaperFactory.create(newUri)
|
||||
|
||||
return writableDatabase
|
||||
|
|
|
@ -50,13 +50,25 @@ internal class WallpaperStorageMigrationJob(parameters: Parameters = Parameters.
|
|||
val currentDefaultWallpaperUri = SignalStore.wallpaper.currentRawWallpaper?.file_?.uri
|
||||
|
||||
for (filename in wallpaperFileNames) {
|
||||
val inputStream = FileStorage.read(context, DIRECTORY, filename)
|
||||
val wallpaperAttachmentId = SignalDatabase.attachments.insertWallpaper(inputStream)
|
||||
|
||||
val legacyUri = Uri.withAppendedPath(CONTENT_URI, filename)
|
||||
val directory = context.getDir(DIRECTORY, Context.MODE_PRIVATE)
|
||||
val file = File(directory, filename)
|
||||
|
||||
val legacyUri = Uri.withAppendedPath(CONTENT_URI, filename)
|
||||
val inputStream = try {
|
||||
FileStorage.read(context, DIRECTORY, filename)
|
||||
} catch (e: IOException) {
|
||||
Log.w(TAG, "Failed to read $filename! Clearing references.")
|
||||
val updatedUserCount = SignalDatabase.recipients.migrateWallpaperUri(
|
||||
legacyUri = legacyUri,
|
||||
newUri = null
|
||||
)
|
||||
Log.d(TAG, "Wallpaper with name '$filename' was in use by $updatedUserCount recipients.")
|
||||
file.delete()
|
||||
continue
|
||||
}
|
||||
|
||||
val wallpaperAttachmentId = SignalDatabase.attachments.insertWallpaper(inputStream)
|
||||
|
||||
val newUri = PartAuthority.getAttachmentDataUri(wallpaperAttachmentId)
|
||||
|
||||
val updatedUserCount = SignalDatabase.recipients.migrateWallpaperUri(
|
||||
|
|
Loading…
Add table
Reference in a new issue