From 287afe37837496ce4454c76775dcfb4f745ac871 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Thu, 17 Jun 2021 11:26:51 -0400 Subject: [PATCH 1/2] Fix docs for `ls(.a)` --- Sources/Path+ls.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Path+ls.swift b/Sources/Path+ls.swift index 469a2a6..0725536 100644 --- a/Sources/Path+ls.swift +++ b/Sources/Path+ls.swift @@ -198,6 +198,6 @@ public extension Array where Element == Path { /// Options for `Path.ls(_:)` public enum ListDirectoryOptions { - /// Creates intermediary directories; works the same as `mkdir -p`. + /// Lists hidden files also case a } From f49e5c82c7ff15b40cb59fbacf42d722eba72e62 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Thu, 17 Jun 2021 11:23:53 -0400 Subject: [PATCH 2/2] This seems more correct --- .github/workflows/ci.yml | 11 +++--- Sources/Path+CommonDirectories.swift | 50 ++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4395b0..99fee0b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,12 +54,13 @@ jobs: strategy: matrix: swift: - - '5.1' - - '5.2' - - '5.3' - - '5.4' + - swift:5.1 + - swift:5.2 + - swift:5.3 + - swift:5.4 + - swiftlang/swift:nightly-5.5 container: - image: swift:${{ matrix.swift }} + image: ${{ matrix.swift }} steps: - uses: actions/checkout@v2 - run: useradd -ms /bin/bash mxcl diff --git a/Sources/Path+CommonDirectories.swift b/Sources/Path+CommonDirectories.swift index 2475902..19de620 100644 --- a/Sources/Path+CommonDirectories.swift +++ b/Sources/Path+CommonDirectories.swift @@ -1,16 +1,16 @@ import Foundation /// The `extension` that provides static properties that are common directories. -extension Path { +private enum Foo { //MARK: Common Directories /// Returns a `Path` containing `FileManager.default.currentDirectoryPath`. - public static var cwd: DynamicPath { + static var cwd: DynamicPath { return .init(string: FileManager.default.currentDirectoryPath) } /// Returns a `Path` representing the root path. - public static var root: DynamicPath { + static var root: DynamicPath { return .init(string: "/") } @@ -27,7 +27,7 @@ extension Path { #endif /// Returns a `Path` representing the user’s home directory - public static var home: DynamicPath { + static var home: DynamicPath { let string: String #if os(macOS) if #available(OSX 10.12, *) { @@ -70,7 +70,7 @@ extension Path { - Note: There is no standard location for documents on Linux, thus we return `~/Documents`. - Note: You should create a subdirectory before creating any files. */ - public static var documents: DynamicPath { + static var documents: DynamicPath { return path(for: .documentDirectory) } @@ -79,7 +79,7 @@ extension Path { - Note: On Linux this is `XDG_CACHE_HOME`. - Note: You should create a subdirectory before creating any files. */ - public static var caches: DynamicPath { + static var caches: DynamicPath { return path(for: .cachesDirectory) } @@ -88,7 +88,7 @@ extension Path { - Note: On Linux is `XDG_DATA_HOME`. - Note: You should create a subdirectory before creating any files. */ - public static var applicationSupport: DynamicPath { + static var applicationSupport: DynamicPath { return path(for: .applicationSupportDirectory) } } @@ -108,13 +108,35 @@ func defaultUrl(for searchPath: FileManager.SearchPathDirectory) -> DynamicPath } #endif +/// The `extension` that provides static properties that are common directories. #if swift(>=5.5) -extension Pathish where Self == Path { - static var home: DynamicPath { Path.home } - static var root: DynamicPath { Path.root } - static var cwd: DynamicPath { Path.cwd } - static var documents: DynamicPath { Path.documents } - static var caches: DynamicPath { Path.caches } - static var applicationSupport: DynamicPath { Path.applicationSupport } +public extension Pathish where Self == Path { + static var home: DynamicPath { return Foo.home } + static var root: DynamicPath { return Foo.root } + static var cwd: DynamicPath { return Foo.cwd } + static var documents: DynamicPath { return Foo.documents } + static var caches: DynamicPath { return Foo.caches } + static var applicationSupport: DynamicPath { return Foo.applicationSupport } + static func source(for filePath: String = #filePath) -> (file: DynamicPath, directory: DynamicPath) { + return Foo.source(for: filePath) + } +} +#else +public extension Path { + static var home: DynamicPath { return Foo.home } + static var root: DynamicPath { return Foo.root } + static var cwd: DynamicPath { return Foo.cwd } + static var documents: DynamicPath { return Foo.documents } + static var caches: DynamicPath { return Foo.caches } + static var applicationSupport: DynamicPath { return Foo.applicationSupport } +#if swift(>=5.3) + static func source(for filePath: String = #filePath) -> (file: DynamicPath, directory: DynamicPath) { + return Foo.source(for: filePath) + } +#else + static func source(for file: String = #file) -> (file: DynamicPath, directory: DynamicPath) { + return Foo.source(for: file) + } +#endif } #endif