@@ -208,40 +208,33 @@ func (p *Packages) processAPKStreaming(packageName string, packageFile *adb.Pack
208208}
209209
210210func (p * Packages ) processLargeEncryptedAPK (packageFile * adb.PackageFile , zipPath string , acq * acquisition.Acquisition , usedZipPaths map [string ]struct {}) (string , error ) {
211- log .Debugf ("APK %s exceeded streaming buffer limit; streaming directly to encrypted archive without certificate check" , packageFile .Path )
211+ log .Debugf ("APK %s exceeded streaming buffer limit; staging it before adding it to the encrypted archive without certificate check" , packageFile .Path )
212212
213213 packageFile .CertificateError = "Skipped certificate check: APK exceeds streaming buffer limit"
214214 packageFile .VerifiedCertificate = false
215215
216- zipPath = reserveUniqueZipPath (zipPath , usedZipPaths )
217- writer , err := acq .ZipWriter .CreateFile (zipPath )
216+ tempPath , err := acq .StreamingPuller .PullToTempFile (packageFile .Path )
218217 if err != nil {
219- return "" , fmt .Errorf ("failed to create zip entry for APK : %v " , err )
218+ return "" , fmt .Errorf ("failed to pull APK to temporary file : %w " , err )
220219 }
221- if err := acq .StreamingPuller .PullToWriter (packageFile .Path , writer ); err != nil {
222- return "" , fmt .Errorf ("failed to stream APK to archive: %v" , err )
220+ defer os .Remove (tempPath )
221+
222+ zipPath = reserveUniqueZipPath (zipPath , usedZipPaths )
223+ if err := acq .ZipWriter .CreateFileFromPath (zipPath , tempPath ); err != nil {
224+ return "" , fmt .Errorf ("failed to add APK to archive: %w" , err )
223225 }
224226 return zipPath , nil
225227}
226228
227229func (p * Packages ) processLargeAPKFromTemp (packageFile * adb.PackageFile , keepOption , zipPath string , acq * acquisition.Acquisition , usedZipPaths map [string ]struct {}) (string , bool , error ) {
228230 log .Debugf ("APK %s exceeded streaming buffer limit; using temporary file for certificate check" , packageFile .Path )
229231
230- tempFile , err := os . CreateTemp ( "" , "androidqf-apk-*.apk" )
232+ tempPath , err := acq . StreamingPuller . PullToTempFile ( packageFile . Path )
231233 if err != nil {
232- return "" , false , fmt .Errorf ("failed to create temporary APK file: %v " , err )
234+ return "" , false , fmt .Errorf ("failed to pull APK to temporary file: %w " , err )
233235 }
234- tempPath := tempFile .Name ()
235236 defer os .Remove (tempPath )
236237
237- if err := acq .StreamingPuller .PullToWriter (packageFile .Path , tempFile ); err != nil {
238- tempFile .Close ()
239- return "" , false , fmt .Errorf ("failed to pull APK to temporary file: %v" , err )
240- }
241- if err := tempFile .Close (); err != nil {
242- return "" , false , fmt .Errorf ("failed to close temporary APK file: %v" , err )
243- }
244-
245238 shouldSkip , err := p .processCertificateFromPath (packageFile , keepOption , tempPath )
246239 if err != nil {
247240 return "" , false , fmt .Errorf ("certificate processing failed: %v" , err )
0 commit comments