Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit bc0174f

Browse files
[path_provider] Fix iOS getApplicationSupportDirectory regression (#7026)
When switching iOS to share the macOS implementation, the application support path for iOS accidentally changed because I forgot the macOS implementation added an extra subdirectory to it. This fixes that regression by returning iOS to the path `path_provider_ios` used. Fixes flutter/flutter#119133
1 parent 1e5efd1 commit bc0174f

File tree

6 files changed

+33
-14
lines changed

6 files changed

+33
-14
lines changed

packages/path_provider/path_provider_foundation/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
## NEXT
1+
## 2.1.1
22

3-
* Updates minimum Flutter version to 3.0.
3+
* Fixes a regression in the path retured by `getApplicationSupportDirectory` on iOS.
44

55
## 2.1.0
66

packages/path_provider/path_provider_foundation/darwin/Classes/PathProviderPlugin.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,19 @@ public class PathProviderPlugin: NSObject, FlutterPlugin, PathProviderApi {
2424

2525
func getDirectoryPath(type: DirectoryType) -> String? {
2626
var path = getDirectory(ofType: fileManagerDirectoryForType(type))
27+
#if os(macOS)
28+
// In a non-sandboxed app, this is a shared directory where applications are
29+
// expected to use its bundle ID as a subdirectory. (For non-sandboxed apps,
30+
// adding the extra path is harmless).
31+
// This is not done for iOS, for compatibility with older versions of the
32+
// plugin.
2733
if type == .applicationSupport {
2834
if let basePath = path {
2935
let basePathURL = URL.init(fileURLWithPath: basePath)
3036
path = basePathURL.appendingPathComponent(Bundle.main.bundleIdentifier!).path
3137
}
3238
}
39+
#endif
3340
return path
3441
}
3542
}

packages/path_provider/path_provider_foundation/darwin/Tests/RunnerTests.swift renamed to packages/path_provider/path_provider_foundation/darwin/RunnerTests/RunnerTests.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,19 @@ class RunnerTests: XCTestCase {
3939
func testGetApplicationSupportDirectory() throws {
4040
let plugin = PathProviderPlugin()
4141
let path = plugin.getDirectoryPath(type: .applicationSupport)
42-
// The application support directory path should be the system application support
43-
// path with an added subdirectory based on the app name.
42+
#if os(iOS)
43+
// On iOS, the application support directory path should be just the system application
44+
// support path.
45+
XCTAssertEqual(
46+
path,
47+
NSSearchPathForDirectoriesInDomains(
48+
FileManager.SearchPathDirectory.applicationSupportDirectory,
49+
FileManager.SearchPathDomainMask.userDomainMask,
50+
true
51+
).first)
52+
#else
53+
// On macOS, the application support directory path should be the system application
54+
// support path with an added subdirectory based on the app name.
4455
XCTAssert(
4556
path!.hasPrefix(
4657
NSSearchPathForDirectoriesInDomains(
@@ -49,6 +60,7 @@ class RunnerTests: XCTestCase {
4960
true
5061
).first!))
5162
XCTAssert(path!.hasSuffix("Example"))
63+
#endif
5264
}
5365

5466
func testGetLibraryDirectory() throws {

packages/path_provider/path_provider_foundation/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
11-
3380327729784D96002D32AE /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3380327629784D96002D32AE /* RunnerTests.swift */; };
11+
33258D7929818305006BAA98 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33258D7729818302006BAA98 /* RunnerTests.swift */; };
1212
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
1313
569E86265D93B926F433B2DF /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 479D5DD53D431F6BBABA2E43 /* Pods_Runner.framework */; };
1414
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
@@ -45,8 +45,8 @@
4545
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
4646
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
4747
1E28C831B7D8EA9408BFB69A /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = "<group>"; };
48+
33258D7729818302006BAA98 /* RunnerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RunnerTests.swift; path = ../../darwin/RunnerTests/RunnerTests.swift; sourceTree = "<group>"; };
4849
3380327429784D96002D32AE /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
49-
3380327629784D96002D32AE /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RunnerTests.swift; path = ../../../darwin/Tests/RunnerTests.swift; sourceTree = "<group>"; };
5050
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
5151
479D5DD53D431F6BBABA2E43 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5252
5DB8EF5A2759054360D79B8D /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
@@ -87,12 +87,12 @@
8787
/* End PBXFrameworksBuildPhase section */
8888

8989
/* Begin PBXGroup section */
90-
3380327529784D96002D32AE /* RunnerTests */ = {
90+
33258D76298182CC006BAA98 /* RunnerTests */ = {
9191
isa = PBXGroup;
9292
children = (
93-
3380327629784D96002D32AE /* RunnerTests.swift */,
93+
33258D7729818302006BAA98 /* RunnerTests.swift */,
9494
);
95-
path = RunnerTests;
95+
name = RunnerTests;
9696
sourceTree = "<group>";
9797
};
9898
9740EEB11CF90186004384FC /* Flutter */ = {
@@ -111,7 +111,7 @@
111111
children = (
112112
9740EEB11CF90186004384FC /* Flutter */,
113113
97C146F01CF9000F007C117D /* Runner */,
114-
3380327529784D96002D32AE /* RunnerTests */,
114+
33258D76298182CC006BAA98 /* RunnerTests */,
115115
97C146EF1CF9000F007C117D /* Products */,
116116
E1C876D20454FC3A1ED7F7E5 /* Pods */,
117117
C72F144CE69E83C4574EB334 /* Frameworks */,
@@ -365,7 +365,7 @@
365365
isa = PBXSourcesBuildPhase;
366366
buildActionMask = 2147483647;
367367
files = (
368-
3380327729784D96002D32AE /* RunnerTests.swift in Sources */,
368+
33258D7929818305006BAA98 /* RunnerTests.swift in Sources */,
369369
);
370370
runOnlyForDeploymentPostprocessing = 0;
371371
};

packages/path_provider/path_provider_foundation/example/macos/Runner.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = "<group>"; };
8383
33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = "<group>"; };
8484
33EBD3A726728EA70013E557 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
85-
33EBD3A926728EA70013E557 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ../../../darwin/Tests/RunnerTests.swift; sourceTree = "<group>"; };
85+
33EBD3A926728EA70013E557 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ../../../darwin/RunnerTests/RunnerTests.swift; sourceTree = "<group>"; };
8686
33EBD3AB26728EA70013E557 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8787
46139048DB9F59D473B61B5E /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
8888
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = "<group>"; };

packages/path_provider/path_provider_foundation/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: path_provider_foundation
22
description: iOS and macOS implementation of the path_provider plugin
33
repository: https://github.com/flutter/plugins/tree/main/packages/path_provider/path_provider_foundation
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+path_provider%22
5-
version: 2.1.0
5+
version: 2.1.1
66

77
environment:
88
sdk: ">=2.12.0 <3.0.0"
9-
flutter: ">=3.0.0"
9+
flutter: ">=2.10.0"
1010

1111
flutter:
1212
plugin:

0 commit comments

Comments
 (0)