kineapps / flutter_archive

Flutter plugin for creating and extracting ZIP files.
https://pub.dev/packages/flutter_archive
BSD 3-Clause "New" or "Revised" License
57 stars 43 forks source link

Unable to unzip file due to error - open failed: EPERM (Operation not permitted) #38

Closed bluntmess closed 3 years ago

bluntmess commented 3 years ago

Getting the following error when trying to extract a zip file at this path /storage/emulated/0/Test:

D/FilePickerDelegate(12452): [SingleFilePick] File URI:content://com.android.externalstorage.documents/tree/primary%3ATest/document/primary%3ATest
I/flutter (12452): result: /storage/emulated/0/Test
D/FlutterArchivePlugin(11785): onMethodCall / unzip...
D/FlutterArchivePlugin(11785): destinationDir.path: /storage/emulated/0/Test
D/FlutterArchivePlugin(11785): destinationDir.canonicalPath: /storage/emulated/0/Test
D/FlutterArchivePlugin(11785): destinationDir.absolutePath: /storage/emulated/0/Test
D/FlutterArchivePlugin(11785): zipEntry fileName=c4611_sample_explain 0.pdf, compressedSize=150723, size=177590, crc=1899967778
D/FlutterArchivePlugin(11785): Writing entry to file: /storage/emulated/0/Test/c4611_sample_explain 0.pdf
W/System.err(11785): java.io.FileNotFoundException: /storage/emulated/0/Test/c4611_sample_explain 0.pdf: open failed: EPERM (Operation not permitted)
W/System.err(11785):    at libcore.io.IoBridge.open(IoBridge.java:492)
W/System.err(11785):    at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
W/System.err(11785):    at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
W/System.err(11785):    at com.kineapps.flutterarchive.FlutterArchivePlugin.unzip(FlutterArchivePlugin.kt:359)
W/System.err(11785):    at com.kineapps.flutterarchive.FlutterArchivePlugin$onMethodCall$3$1.invokeSuspend(FlutterArchivePlugin.kt:148)
W/System.err(11785):    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
W/System.err(11785):    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
W/System.err(11785):    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:561)
W/System.err(11785):    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:727)
W/System.err(11785):    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:667)
W/System.err(11785):    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:655)
W/System.err(11785): Caused by: android.system.ErrnoException: open failed: EPERM (Operation not permitted)
W/System.err(11785):    at libcore.io.Linux.open(Native Method)
W/System.err(11785):    at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
W/System.err(11785):    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254)
W/System.err(11785):    at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
W/System.err(11785):    at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7542)
W/System.err(11785):    at libcore.io.IoBridge.open(IoBridge.java:478)
W/System.err(11785):    ... 10 more
E/flutter (11785): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: PlatformException(unzip_error, /storage/emulated/0/Test/c4611_sample_explain 0.pdf: open failed: EPERM (Operation not permitted), java.io.FileNotFoundException: /storage/emulated/0/Test/c4611_sample_explain 0.pdf: open failed: EPERM (Operation not permitted), null)
E/flutter (11785): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:597:7)
E/flutter (11785): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158:18)
E/flutter (11785): <asynchronous suspension>
E/flutter (11785): #2      ZipFile.extractToDirectory (package:flutter_archive/flutter_archive.dart:141:7)
E/flutter (11785): <asynchronous suspension>
E/flutter (11785): 

But on this path /storage/emulated/0/Download/Test , it works fine :

D/FilePickerDelegate(12452): [SingleFilePick] File URI:content://com.android.externalstorage.documents/tree/primary%3ADownload%2FTest/document/primary%3ADownload%2FTest
I/flutter (12452): result: /storage/emulated/0/Download/Test
D/FlutterArchivePlugin(12452): onMethodCall / unzip...
D/FlutterArchivePlugin(12452): destinationDir.path: /storage/emulated/0/Download/Test
D/FlutterArchivePlugin(12452): destinationDir.canonicalPath: /storage/emulated/0/Download/Test
D/FlutterArchivePlugin(12452): destinationDir.absolutePath: /storage/emulated/0/Download/Test
D/FlutterArchivePlugin(12452): zipEntry fileName=c4611_sample_explain 0.pdf, compressedSize=150723, size=177590, crc=2506166364
D/FlutterArchivePlugin(12452): Writing entry to file: /storage/emulated/0/Download/Test/c4611_sample_explain 0.pdf
D/FlutterArchivePlugin(12452): zipEntry fileName=c4611_sample_explain 1.pdf, compressedSize=97717, size=106241, crc=3092968696
D/FlutterArchivePlugin(12452): Writing entry to file: /storage/emulated/0/Download/Test/c4611_sample_explain 1.pdf
D/FlutterArchivePlugin(12452): ...onMethodCall / unzip

Do you have any idea why this is happening? Then please let me know.

Thank you.

kinex commented 3 years ago

I think this is caused by Android permissions (check if adding some permission to manifest fixes it). Most probably not related to this plugin.

bluntmess commented 3 years ago

I think this is caused by Android permissions (check if adding some permission to manifest fixes it). Most probably not related to this plugin.

Thanks for replying. Previously I had "Allow access to media only" permission enabled but after enabling "Allow management of all files" the zip extraction is working fine. But the issue is this permission is generally less preferable due to the new guidelines from Google. And I don't know if in my case(extracting zip) this is really required or not.

So, I was hoping if you can provide a simpler way of extracting the zip in a folder, just like how you have provided a way to save files using the flutter_file-dialog plugin without the "Allow management of all files" permission then it would be a great help.

Thank you for providing this awesome plugin.

kinex commented 3 years ago

From what I know that is not possible. Nice to hear the plugin is useful!

bluntmess commented 3 years ago

Oh, then I will go with the "Allow management of all files" permission option. Btw thanks for letting me know about that and yes your plugins are very useful for my app.