From 8ddc6e9d6f3c41c1528e0d43156d7d811dd6be40 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sun, 24 Sep 2023 22:36:37 +0200 Subject: [PATCH] fix: Check if file exists before trying to open it --- src/main/kotlin/app/revanced/library/zip/ZipFile.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/app/revanced/library/zip/ZipFile.kt b/src/main/kotlin/app/revanced/library/zip/ZipFile.kt index 8e1d147..1b652ec 100644 --- a/src/main/kotlin/app/revanced/library/zip/ZipFile.kt +++ b/src/main/kotlin/app/revanced/library/zip/ZipFile.kt @@ -13,7 +13,12 @@ import java.util.zip.Deflater class ZipFile(file: File) : Closeable { private var entries: MutableList = mutableListOf() - private val filePointer: RandomAccessFile = RandomAccessFile(file, if (file.canWrite()) "rw" else "r") + // Open file for writing if it doesn't exist (because the intention is to write) or is writable. + private val filePointer: RandomAccessFile = RandomAccessFile( + file, + if (!file.exists() || file.canWrite()) "rw" else "r" + ) + private var centralDirectoryNeedsRewrite = false private val compressionLevel = 5