From 8d4d1ba6604bfd18e67db6599a9a3ffc0110418d Mon Sep 17 00:00:00 2001 From: tzugen Date: Fri, 16 Apr 2021 14:41:00 +0200 Subject: [PATCH] Move function out of companion object --- .../moire/ultrasonic/service/DownloadFile.kt | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadFile.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadFile.kt index c9334f41..08b081c6 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadFile.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadFile.kt @@ -351,26 +351,25 @@ class DownloadFile( } } - companion object { - private fun updateModificationDate(file: File) { - if (file.exists()) { - val ok = file.setLastModified(System.currentTimeMillis()) - if (!ok) { - Timber.i( - "Failed to set last-modified date on %s, trying alternate method", - file - ) - try { - // Try alternate method to update last modified date to current time - // Found at https://code.google.com/p/android/issues/detail?id=18624 - val raf = RandomAccessFile(file, "rw") - val length = raf.length() - raf.setLength(length + 1) - raf.setLength(length) - raf.close() - } catch (e: Exception) { - Timber.w("Failed to set last-modified date on %s", file) - } + private fun updateModificationDate(file: File) { + if (file.exists()) { + val ok = file.setLastModified(System.currentTimeMillis()) + if (!ok) { + Timber.i( + "Failed to set last-modified date on %s, trying alternate method", + file + ) + try { + // Try alternate method to update last modified date to current time + // 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 length = raf.length() + raf.setLength(length + 1) + raf.setLength(length) + raf.close() + } catch (e: Exception) { + Timber.w("Failed to set last-modified date on %s", file) } } }