Skip to content

Commit

Permalink
Merge pull request #1457 from twinkles-twinstar/master
Browse files Browse the repository at this point in the history
fix #1412: Picking a folder in iOS causes the original folder to be deleted.
  • Loading branch information
navaronbracke authored Apr 22, 2024
2 parents 0fb60c9 + 0c245b0 commit 137840a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 8.0.2
### iOS
Fixes the bug [#1412](https://github.com/miguelpruivo/flutter_file_picker/issues/1412) that picking a folder in iOS causes the original folder to be deleted.

## 8.0.1
### iOS
Fixes an issue preventing compilation on iOS when using Pod::PICKER_DOCUMENT = false.
Expand Down
40 changes: 23 additions & 17 deletions ios/Classes/FilePickerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -400,27 +400,33 @@ - (void)documentPicker:(UIDocumentPickerViewController *)controller
_result = nil;
return;
}
NSMutableArray<NSURL *> *newUrls = [NSMutableArray new];
for (NSURL *url in urls) {
// Create file URL to temporary folder
NSURL *tempURL = [NSURL fileURLWithPath:NSTemporaryDirectory()];
// Append filename (name+extension) to URL
tempURL = [tempURL URLByAppendingPathComponent:url.lastPathComponent];
NSError *error;
// If file with same name exists remove it (replace file with new one)
if ([[NSFileManager defaultManager] fileExistsAtPath:tempURL.path]) {
[[NSFileManager defaultManager] removeItemAtPath:tempURL.path error:&error];
NSMutableArray<NSURL *> *newUrls;
if(controller.documentPickerMode == UIDocumentPickerModeOpen) {
newUrls = urls;
}
if(controller.documentPickerMode == UIDocumentPickerModeImport) {
newUrls = [NSMutableArray new];
for (NSURL *url in urls) {
// Create file URL to temporary folder
NSURL *tempURL = [NSURL fileURLWithPath:NSTemporaryDirectory()];
// Append filename (name+extension) to URL
tempURL = [tempURL URLByAppendingPathComponent:url.lastPathComponent];
NSError *error;
// If file with same name exists remove it (replace file with new one)
if ([[NSFileManager defaultManager] fileExistsAtPath:tempURL.path]) {
[[NSFileManager defaultManager] removeItemAtPath:tempURL.path error:&error];
if (error) {
NSLog(@"%@", error.localizedDescription);
}
}
// Move file from app_id-Inbox to tmp/filename
[[NSFileManager defaultManager] moveItemAtPath:url.path toPath:tempURL.path error:&error];
if (error) {
NSLog(@"%@", error.localizedDescription);
} else {
[newUrls addObject:tempURL];
}
}
// Move file from app_id-Inbox to tmp/filename
[[NSFileManager defaultManager] moveItemAtPath:url.path toPath:tempURL.path error:&error];
if (error) {
NSLog(@"%@", error.localizedDescription);
} else {
[newUrls addObject:tempURL];
}
}

[self.documentPickerController dismissViewControllerAnimated:YES completion:nil];
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker
repository: https://github.com/miguelpruivo/flutter_file_picker
issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues
version: 8.0.1
version: 8.0.2

dependencies:
flutter:
Expand Down

0 comments on commit 137840a

Please sign in to comment.