-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[path_provider] Revert iOS/macOS to plugin-based implementation #10517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
auto-submit
merged 5 commits into
flutter:main
from
stuartmorgan-g:path-provider-foundation-revert-ffi
Nov 25, 2025
+905
−1,408
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2cce8fe
Revert to pre-ffi version
stuartmorgan-g c8a36ba
Bump version
stuartmorgan-g dd51015
Update for new style rules
stuartmorgan-g 4363a88
Adjust changelog wording
stuartmorgan-g b5bc5fa
Update packages/path_provider/path_provider_foundation/CHANGELOG.md
stuartmorgan-g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
packages/path_provider/path_provider_foundation/CONTRIBUTING.md
This file was deleted.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
packages/path_provider/path_provider_foundation/darwin/RunnerTests/RunnerTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import XCTest | ||
|
|
||
| @testable import path_provider_foundation | ||
|
|
||
| #if os(iOS) | ||
| import Flutter | ||
| #elseif os(macOS) | ||
| import FlutterMacOS | ||
| #endif | ||
|
|
||
| class RunnerTests: XCTestCase { | ||
| func testGetTemporaryDirectory() throws { | ||
| let plugin = PathProviderPlugin() | ||
| let path = plugin.getDirectoryPath(type: .temp) | ||
| XCTAssertEqual( | ||
| path, | ||
| NSSearchPathForDirectoriesInDomains( | ||
| FileManager.SearchPathDirectory.cachesDirectory, | ||
| FileManager.SearchPathDomainMask.userDomainMask, | ||
| true | ||
| ).first) | ||
| } | ||
|
|
||
| func testGetApplicationDocumentsDirectory() throws { | ||
| let plugin = PathProviderPlugin() | ||
| let path = plugin.getDirectoryPath(type: .applicationDocuments) | ||
| XCTAssertEqual( | ||
| path, | ||
| NSSearchPathForDirectoriesInDomains( | ||
| FileManager.SearchPathDirectory.documentDirectory, | ||
| FileManager.SearchPathDomainMask.userDomainMask, | ||
| true | ||
| ).first) | ||
| } | ||
|
|
||
| func testGetApplicationSupportDirectory() throws { | ||
| let plugin = PathProviderPlugin() | ||
| let path = plugin.getDirectoryPath(type: .applicationSupport) | ||
| #if os(iOS) | ||
| // On iOS, the application support directory path should be just the system application | ||
| // support path. | ||
| XCTAssertEqual( | ||
| path, | ||
| NSSearchPathForDirectoriesInDomains( | ||
| FileManager.SearchPathDirectory.applicationSupportDirectory, | ||
| FileManager.SearchPathDomainMask.userDomainMask, | ||
| true | ||
| ).first) | ||
| #else | ||
| // On macOS, the application support directory path should be the system application | ||
| // support path with an added subdirectory based on the app name. | ||
| XCTAssert( | ||
| path!.hasPrefix( | ||
| NSSearchPathForDirectoriesInDomains( | ||
| FileManager.SearchPathDirectory.applicationSupportDirectory, | ||
| FileManager.SearchPathDomainMask.userDomainMask, | ||
| true | ||
| ).first!)) | ||
| XCTAssert(path!.hasSuffix("Example")) | ||
| #endif | ||
| } | ||
|
|
||
| func testGetLibraryDirectory() throws { | ||
| let plugin = PathProviderPlugin() | ||
| let path = plugin.getDirectoryPath(type: .library) | ||
| XCTAssertEqual( | ||
| path, | ||
| NSSearchPathForDirectoriesInDomains( | ||
| FileManager.SearchPathDirectory.libraryDirectory, | ||
| FileManager.SearchPathDomainMask.userDomainMask, | ||
| true | ||
| ).first) | ||
| } | ||
|
|
||
| func testGetDownloadsDirectory() throws { | ||
| let plugin = PathProviderPlugin() | ||
| let path = plugin.getDirectoryPath(type: .downloads) | ||
| XCTAssertEqual( | ||
| path, | ||
| NSSearchPathForDirectoriesInDomains( | ||
| FileManager.SearchPathDirectory.downloadsDirectory, | ||
| FileManager.SearchPathDomainMask.userDomainMask, | ||
| true | ||
| ).first) | ||
| } | ||
| } | ||
26 changes: 26 additions & 0 deletions
26
packages/path_provider/path_provider_foundation/darwin/path_provider_foundation.podspec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # | ||
| # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html | ||
| # | ||
| Pod::Spec.new do |s| | ||
| s.name = 'path_provider_foundation' | ||
| s.version = '0.0.1' | ||
| s.summary = 'An iOS and macOS implementation of the path_provider plugin.' | ||
| s.description = <<-DESC | ||
| An iOS and macOS implementation of the Flutter plugin for getting commonly used locations on the filesystem. | ||
| DESC | ||
| s.homepage = 'https://github.com/flutter/packages/tree/main/packages/path_provider/path_provider_foundation' | ||
| s.license = { :type => 'BSD', :file => '../LICENSE' } | ||
| s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } | ||
| s.source = { :http => 'https://github.com/flutter/packages/tree/main/packages/path_provider/path_provider_foundation' } | ||
| s.source_files = 'path_provider_foundation/Sources/path_provider_foundation/**/*.swift' | ||
| s.ios.dependency 'Flutter' | ||
| s.osx.dependency 'FlutterMacOS' | ||
| s.ios.deployment_target = '13.0' | ||
| s.osx.deployment_target = '10.15' | ||
| s.ios.xcconfig = { | ||
| 'LIBRARY_SEARCH_PATHS' => '$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)/ $(SDKROOT)/usr/lib/swift', | ||
| 'LD_RUNPATH_SEARCH_PATHS' => '/usr/lib/swift', | ||
| } | ||
| s.swift_version = '5.0' | ||
| s.resource_bundles = {'path_provider_foundation_privacy' => ['path_provider_foundation/Sources/path_provider_foundation/Resources/PrivacyInfo.xcprivacy']} | ||
| end |
28 changes: 28 additions & 0 deletions
28
...ages/path_provider/path_provider_foundation/darwin/path_provider_foundation/Package.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // swift-tools-version: 5.9 | ||
|
|
||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "path_provider_foundation", | ||
| platforms: [ | ||
| .iOS("13.0"), | ||
| .macOS("10.15"), | ||
| ], | ||
| products: [ | ||
| .library(name: "path-provider-foundation", targets: ["path_provider_foundation"]) | ||
| ], | ||
| dependencies: [], | ||
| targets: [ | ||
| .target( | ||
| name: "path_provider_foundation", | ||
| dependencies: [], | ||
| resources: [ | ||
| .process("Resources") | ||
| ] | ||
| ) | ||
| ] | ||
| ) |
75 changes: 75 additions & 0 deletions
75
...darwin/path_provider_foundation/Sources/path_provider_foundation/PathProviderPlugin.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import Foundation | ||
|
|
||
| #if os(iOS) | ||
| import Flutter | ||
| #elseif os(macOS) | ||
| import FlutterMacOS | ||
| #endif | ||
|
|
||
| public class PathProviderPlugin: NSObject, FlutterPlugin, PathProviderApi { | ||
| public static func register(with registrar: FlutterPluginRegistrar) { | ||
| let instance = PathProviderPlugin() | ||
| // Workaround for https://github.com/flutter/flutter/issues/118103. | ||
| #if os(iOS) | ||
| let messenger = registrar.messenger() | ||
| #else | ||
| let messenger = registrar.messenger | ||
| #endif | ||
| PathProviderApiSetup.setUp(binaryMessenger: messenger, api: instance) | ||
| } | ||
|
|
||
| func getDirectoryPath(type: DirectoryType) -> String? { | ||
| var path = getDirectory(ofType: fileManagerDirectoryForType(type)) | ||
| #if os(macOS) | ||
| // In a non-sandboxed app, these are shared directories where applications are | ||
| // expected to use its bundle ID as a subdirectory. (For non-sandboxed apps, | ||
| // adding the extra path is harmless). | ||
| // This is not done for iOS, for compatibility with older versions of the | ||
| // plugin. | ||
| if type == .applicationSupport || type == .applicationCache { | ||
| if let basePath = path { | ||
| let basePathURL = URL.init(fileURLWithPath: basePath) | ||
| path = basePathURL.appendingPathComponent(Bundle.main.bundleIdentifier!).path | ||
stuartmorgan-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| #endif | ||
| return path | ||
| } | ||
|
|
||
| // Returns the path for the container of the specified app group. | ||
| func getContainerPath(appGroupIdentifier: String) -> String? { | ||
| return FileManager.default.containerURL( | ||
| forSecurityApplicationGroupIdentifier: appGroupIdentifier)?.path | ||
| } | ||
| } | ||
|
|
||
| /// Returns the FileManager constant corresponding to the given type. | ||
| private func fileManagerDirectoryForType(_ type: DirectoryType) -> FileManager.SearchPathDirectory { | ||
| switch type { | ||
| case .applicationCache: | ||
| return FileManager.SearchPathDirectory.cachesDirectory | ||
| case .applicationDocuments: | ||
| return FileManager.SearchPathDirectory.documentDirectory | ||
| case .applicationSupport: | ||
| return FileManager.SearchPathDirectory.applicationSupportDirectory | ||
| case .downloads: | ||
| return FileManager.SearchPathDirectory.downloadsDirectory | ||
| case .library: | ||
| return FileManager.SearchPathDirectory.libraryDirectory | ||
| case .temp: | ||
| return FileManager.SearchPathDirectory.cachesDirectory | ||
| } | ||
| } | ||
|
|
||
| /// Returns the user-domain directory of the given type. | ||
| private func getDirectory(ofType directory: FileManager.SearchPathDirectory) -> String? { | ||
| let paths = NSSearchPathForDirectoriesInDomains( | ||
| directory, | ||
| FileManager.SearchPathDomainMask.userDomainMask, | ||
| true) | ||
| return paths.first | ||
| } | ||
14 changes: 14 additions & 0 deletions
14
...path_provider_foundation/Sources/path_provider_foundation/Resources/PrivacyInfo.xcprivacy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>NSPrivacyTrackingDomains</key> | ||
| <array/> | ||
| <key>NSPrivacyAccessedAPITypes</key> | ||
| <array/> | ||
| <key>NSPrivacyCollectedDataTypes</key> | ||
| <array/> | ||
| <key>NSPrivacyTracking</key> | ||
| <false/> | ||
| </dict> | ||
| </plist> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.