Skip to content

[path_provider_foundation] Run swift-format on Swift files #5935

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
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,63 @@
import Foundation

#if os(iOS)
import Flutter
import Flutter
#elseif os(macOS)
import FlutterMacOS
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
#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
#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
}
}
}
#endif
#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
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
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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
// found in the LICENSE file.

import XCTest

@testable import path_provider_foundation

#if os(iOS)
import Flutter
import Flutter
#elseif os(macOS)
import FlutterMacOS
import FlutterMacOS
#endif

class RunnerTests: XCTestCase {
Expand Down Expand Up @@ -39,28 +40,28 @@ class RunnerTests: XCTestCase {
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(
#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!))
XCTAssert(path!.hasSuffix("Example"))
#endif
).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 {
Expand Down