miguelpruivo/flutter_file_picker

`FilePicker.platform.getDirectoryPath()` seems to be moving the original directory to `tmp` directory [IOS]

hasanmhallak opened this issue · 46 comments

Describe the bug
It seems like the FilePicker.platform.getDirectoryPath() will move the original directory instead of copying it to tmp/cache directory.

Platform

  • Android
  • iOS
  • Web
  • Desktop

Platform OS version
IOS 17.2

How are you picking?

final path = await FilePicker.platform.getDirectoryPath();
       print(path);

Details to reproduce the issue
Try to use FilePicker.platform.getDirectoryPath() on any directory.

Error Log
N/A

Screenshots and/or video

Screen.Recording.2024-01-29.at.10.16.31.AM-1.mov

Flutter Version details

[✓] Flutter (Channel stable, 3.16.4, on macOS 13.5.2 22G91 darwin-arm64, locale
    en-EG)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 15.1)
[✓] Chrome - develop for the web
[!] Android Studio (version unknown)
    ✗ Unable to determine Android Studio version.
    ✗ Unable to find bundled Java version.
[✓] VS Code (version 1.85.2)
[✓] Connected device (3 available)
[✓] Network resources

Additional context
When invoking FilePicker.platform.getDirectoryPath(); on Android, it successfully returns the actual path of any selected directory.

However, on iOS, due to the limitations you've outlined in your FAQ, one must copy the file or directory to a temporary directory for access.

An issue arises with FilePicker.platform.getDirectoryPath(); on iOS, where it moves the directory instead of copying it, contrary to the expected behavior. As a result, the user will permanently lose access to that directory.

same here. any update on the issue?

This issue is stale because it has been open for 14 days with no activity.

The FilePicker works fine on Android but on iOS it crashes my app with no permission to access "tmp", whether I want to pick an internal directory or an iCloud.

iOS 15.3.1

Error log after picking a folder "Test" in the internal directory structure:

“Test” couldn’t be moved because you don’t have permission to access “tmp”.
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x1808e10fc 0x199131d64 0x1809ea564 0x1808770e4 0x104dd361c 0x1836ec2dc 0x18309a524 0x1835e2748 0x182f31f18 0x183144998 0x182f9b190 0x182fb5dd0 0x182e812e8 0x182e95a5c 0x182e95bc4 0x18466aa08 0x180553670 0x180561b70 0x180899d84 0x180853f5c 0x180867468 0x19c40b38c 0x18320a5d0 0x182f88f74 0x102efcb28 0x10434daa4)
libc++abi: terminating with uncaught exception of type NSException
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00000001b7ecc964 libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`:
->  0x1b7ecc964 <+8>:  b.lo   0x1b7ecc984               ; <+40>
    0x1b7ecc968 <+12>: pacibsp 
    0x1b7ecc96c <+16>: stp    x29, x30, [sp, #-0x10]!
    0x1b7ecc970 <+20>: mov    x29, sp
Target 0: (Runner) stopped.
Lost connection to device.

Exited.

Why is it even trying to move the "Test" directory? I just picked it as a target to save a file into at a later step, nothing else...

any updated here ? I met same issue :(

very frustrating this issue is seemingly ignored. this library is basically the only way to access files/folders with flutter

Same here, any solutions? @miguelpruivo

I tested some older versions of this library and it seems to yield the same issue, perhaps there has been a breaking change in newer iOS versions?

I tested some older versions of this library and it seems to yield the same issue, perhaps there has been a breaking change in newer iOS versions?

I'm trying on ios 16 (physical device) and experiencing it

Same here, we need a fix please.

This issue is stale because it has been open for 14 days with no activity.

This issue is stale because it has been open for 7 days with no activity.

Bumped

What's the status of this? Haven't experienced any issue in the meantime. Does this only happen on iOS 17.0? I'm not sure if I correctly understood the issue, it doesn't pick the path, is that it?

@miguelpruivo The issue is present on iOS 15 and newer, not Android. Picking any directory results in the missing permissions for "tmp" error message for me (as seen in my error log above), not sure about what others get.

I guess I'll have to try to replicate in order to fix it or some issue a PR.

Any reproducible example or steps to?

Simply calling FilePicker.platform.getDirectoryPath(); and picking -any- directory, whether internal or on iCloud, was enough for me. The issue happened every time.

For me on real devices the issue is reproducible. Works fine for simulator.

Simply calling FilePicker.platform.getDirectoryPath(); and picking -any- directory, whether internal or on iCloud, was enough for me. The issue happened every time.

But what is exactly the issue?

@miguelpruivo selecting the directory crashes the app and throws the error that I pasted above.

hey @miguelpruivo, sorry for the late replay.

When invoking FilePicker.platform.getDirectoryPath(); on Android, it successfully returns the actual path of any selected directory.

However, on iOS, due to the limitations you've outlined in your FAQ, one must copy the file or directory to a temporary directory for access.

An issue arises with FilePicker.platform.getDirectoryPath(); on iOS, where it moves the directory instead of copying it, contrary to the expected behavior. As a result, the user will permanently lose access to that directory.

This concern is addressed in the issue that I've opened.

Edit:

This making me wonder if we was able to move the original folder why we are copying the file in first place?

This issue is stale because it has been open for 7 days with no activity.

Bump

This issue is stale because it has been open for 7 days with no activity.

This issue is stale because it has been open for 7 days with no activity.

This issue is stale because it has been open for 7 days with no activity.

bump

This issue is stale because it has been open for 7 days with no activity.

@miguelpruivo
Here is the error

“Test” couldn’t be moved because you don’t have permission to access “tmp”.
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x1a115bf24 0x199012018 0x1a10fd2d8 0x10220f740 0x1a3ca3740 0x1a36157d4 0x1a3615278 0x1a366ec40 0x1a37127f4 0x1a3712478 0x1a33ee56c 0x1a33ee450 0x1a33ed168 0x1a33fa844 0x1a33fa8b4 0x1a27a11ac 0x1036067bc 0x103616d58 0x10361690c 0x1a112e750 0x1a112b954 0x1a112ad18 0x1e5c9e1a8 0x1a3767058 0x1a381b04c 0x10211c798 0x1c4b6fe4c)
libc++abi: terminating due to uncaught exception of type NSException

I think problem is that it's trying to move the directory, I did not find a way to add permissions to tmp, everything points that it's already should be granted.

@miguelpruivo Here is the error

“Test” couldn’t be moved because you don’t have permission to access “tmp”.
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x1a115bf24 0x199012018 0x1a10fd2d8 0x10220f740 0x1a3ca3740 0x1a36157d4 0x1a3615278 0x1a366ec40 0x1a37127f4 0x1a3712478 0x1a33ee56c 0x1a33ee450 0x1a33ed168 0x1a33fa844 0x1a33fa8b4 0x1a27a11ac 0x1036067bc 0x103616d58 0x10361690c 0x1a112e750 0x1a112b954 0x1a112ad18 0x1e5c9e1a8 0x1a3767058 0x1a381b04c 0x10211c798 0x1c4b6fe4c)
libc++abi: terminating due to uncaught exception of type NSException

I think problem is that it's trying to move the directory, I did not find a way to add permissions to tmp, everything points that it's already should be granted.

Also experiencing this

This issue is stale because it has been open for 7 days with no activity.

bump

This issue is stale because it has been open for 7 days with no activity.

bump

This issue is stale because it has been open for 7 days with no activity.

Are we seriously not getting any file saving support on iOS thanks to this package malfunctioning? Are there any suitable alternatives to this, if this issue isn't getting resolved?

This issue is stale because it has been open for 7 days with no activity.