Move function out of companion object

This commit is contained in:
tzugen 2021-04-16 14:41:00 +02:00
parent 0efb3547c3
commit 8d4d1ba660
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
1 changed files with 19 additions and 20 deletions

View File

@ -351,26 +351,25 @@ class DownloadFile(
} }
} }
companion object { private fun updateModificationDate(file: File) {
private fun updateModificationDate(file: File) { if (file.exists()) {
if (file.exists()) { val ok = file.setLastModified(System.currentTimeMillis())
val ok = file.setLastModified(System.currentTimeMillis()) if (!ok) {
if (!ok) { Timber.i(
Timber.i( "Failed to set last-modified date on %s, trying alternate method",
"Failed to set last-modified date on %s, trying alternate method", file
file )
) try {
try { // Try alternate method to update last modified date to current time
// Try alternate method to update last modified date to current time // Found at https://code.google.com/p/android/issues/detail?id=18624
// Found at https://code.google.com/p/android/issues/detail?id=18624 // According to the bug, this was fixed in Android 8.0 (API 26)
val raf = RandomAccessFile(file, "rw") val raf = RandomAccessFile(file, "rw")
val length = raf.length() val length = raf.length()
raf.setLength(length + 1) raf.setLength(length + 1)
raf.setLength(length) raf.setLength(length)
raf.close() raf.close()
} catch (e: Exception) { } catch (e: Exception) {
Timber.w("Failed to set last-modified date on %s", file) Timber.w("Failed to set last-modified date on %s", file)
}
} }
} }
} }