fix #2336, really delete files from the device after 30 days in the bin

This commit is contained in:
tibbi 2022-02-13 12:08:34 +01:00
parent a1589b60f1
commit 5e548e0460
2 changed files with 9 additions and 4 deletions

View file

@ -1324,7 +1324,12 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
Handler().postDelayed({ Handler().postDelayed({
ensureBackgroundThread { ensureBackgroundThread {
try { try {
mediaDB.deleteOldRecycleBinItems(System.currentTimeMillis() - MONTH_MILLISECONDS) val filesToDelete = mediaDB.getOldRecycleBinItems(System.currentTimeMillis() - MONTH_MILLISECONDS)
filesToDelete.forEach {
if (File(it.path.replaceFirst(RECYCLE_BIN, recycleBinPath)).delete()) {
mediaDB.deleteMediumPath(it.path)
}
}
} catch (e: Exception) { } catch (e: Exception) {
} }
} }

View file

@ -24,6 +24,9 @@ interface MediumDao {
@Query("SELECT COUNT(filename) FROM media WHERE deleted_ts != 0") @Query("SELECT COUNT(filename) FROM media WHERE deleted_ts != 0")
fun getDeletedMediaCount(): Long fun getDeletedMediaCount(): Long
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, video_duration, is_favorite, deleted_ts, media_store_id FROM media WHERE deleted_ts < :timestmap AND deleted_ts != 0")
fun getOldRecycleBinItems(timestmap: Long): List<Medium>
@Insert(onConflict = REPLACE) @Insert(onConflict = REPLACE)
fun insert(medium: Medium) fun insert(medium: Medium)
@ -36,9 +39,6 @@ interface MediumDao {
@Query("DELETE FROM media WHERE full_path = :path COLLATE NOCASE") @Query("DELETE FROM media WHERE full_path = :path COLLATE NOCASE")
fun deleteMediumPath(path: String) fun deleteMediumPath(path: String)
@Query("DELETE FROM media WHERE deleted_ts < :timestmap AND deleted_ts != 0")
fun deleteOldRecycleBinItems(timestmap: Long)
@Query("UPDATE OR REPLACE media SET filename = :newFilename, full_path = :newFullPath, parent_path = :newParentPath WHERE full_path = :oldPath COLLATE NOCASE") @Query("UPDATE OR REPLACE media SET filename = :newFilename, full_path = :newFullPath, parent_path = :newParentPath WHERE full_path = :oldPath COLLATE NOCASE")
fun updateMedium(newFilename: String, newFullPath: String, newParentPath: String, oldPath: String) fun updateMedium(newFilename: String, newFullPath: String, newParentPath: String, oldPath: String)