Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: FileReader is not closed after use in ApkMetadata
Browse files Browse the repository at this point in the history
itsaky committed Sep 6, 2023
1 parent 7a4fe86 commit e305597
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions app/src/main/java/com/itsaky/androidide/models/ApkMetadata.kt
Original file line number Diff line number Diff line change
@@ -41,27 +41,31 @@ class ApkMetadata {
// So we have to handle this case too.
val redirectedFile = getListingFile(listingFIle).absoluteFile
val dir = redirectedFile.parentFile
val metadata = gson.fromJson(FileReader(redirectedFile), ApkMetadata::class.java)
if (!isValid(metadata)) {
log.warn("Invalid APK metadata:", metadata)
return null
}

for (element in metadata.elements!!) {
if (element.outputFile == null) {
log.warn("No output file specified in APK metadata element:", element)
continue
FileReader(redirectedFile).use {
val metadata = gson.fromJson(it, ApkMetadata::class.java)
if (!isValid(metadata)) {
log.warn("Invalid APK metadata:", metadata)
return@use null
}

if (element.outputFile!!.endsWith(".apk")) {
val apk = element.outputFile?.let { File(dir, it) } ?: continue
if (apk.exists() && apk.isFile) {
log.info("Found apk in metadata:", apk)
return apk
for (element in metadata.elements!!) {
if (element.outputFile == null) {
log.warn("No output file specified in APK metadata element:", element)
continue
}

if (element.outputFile!!.endsWith(".apk")) {
val apk = element.outputFile?.let { File(dir, it) } ?: continue
if (apk.exists() && apk.isFile) {
log.info("Found apk in metadata:", apk)
return@use apk
}
}
}

return@use null
}
null
} catch (e: FileNotFoundException) {
log.error("Metadata file not found...", e)
null

0 comments on commit e305597

Please sign in to comment.