[api] check device info file permission before upgrade

This commit is contained in:
StageGuard 2023-07-28 10:39:43 +08:00
parent 575bac4a1e
commit fca4a3cfb4
No known key found for this signature in database
GPG Key ID: F6FF8760A883492B

View File

@ -147,8 +147,16 @@ public actual constructor(
this.writeText(DeviceInfoManager.serialize(it, json)) this.writeText(DeviceInfoManager.serialize(it, json))
} }
} }
return DeviceInfoManager.deserialize(this.readText(), json) { upg -> return DeviceInfoManager.deserialize(this.readText(), json) upg@{ upg ->
this.writeText(DeviceInfoManager.serialize(upg, json)) if (!this.canWrite()) {
logger.warning("Device info file $this is not writable, failed to upgrade legacy device info.")
return@upg
}
try {
this.writeText(DeviceInfoManager.serialize(upg, json))
} catch (ex: SecurityException) {
logger.warning("Device info file $this is not writable, failed to upgrade legacy device info.", ex)
}
} }
} }