fix external check flagging deletion

This commit is contained in:
qimiko committed 2024-01-15 03:14:53 -07:00
1 parent f938b64a27
commit e7ebea1ea6
1 file changed
+17 -2
@@ -138,6 +138,22 @@ class ReleaseManager private constructor(
_uiState.value = ReleaseManagerState.Finished(true)
}
private fun fileWasExternallyModified(): Boolean {
val geodeFile = getGeodeOutputPath()
if (!geodeFile.exists()) {
return false
}
val sharedPreferences = PreferenceUtils.get(applicationContext)
val fileLastModified = sharedPreferences.getLong(PreferenceUtils.Key.CURRENT_RELEASE_MODIFIED)
if (fileLastModified == 0L) {
return false
}
return fileLastModified != geodeFile.lastModified()
}
private suspend fun checkForNewRelease(allowOverwriting: Boolean = false) {
val release = try {
getLatestRelease()
@@ -166,8 +182,7 @@ class ReleaseManager private constructor(
}
// check if the file was externally modified
val fileLastModified = sharedPreferences.getLong(PreferenceUtils.Key.CURRENT_RELEASE_MODIFIED)
if (!allowOverwriting && fileLastModified != 0L && fileLastModified != geodeFile.lastModified()) {
if (!allowOverwriting && fileWasExternallyModified()) {
sendError(UpdateException(UpdateException.Reason.EXTERNAL_FILE_IN_USE))
return
}