From 3212fff7cc21171eb1d1e8312ff106b33f867fc6 Mon Sep 17 00:00:00 2001 From: KaiOelfke Date: Wed, 18 Dec 2024 11:49:40 +0100 Subject: [PATCH 1/8] add func to create symbolic link with RelativePath as destination --- Sources/FileSystem/FileSystem.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/FileSystem/FileSystem.swift b/Sources/FileSystem/FileSystem.swift index 88c07c2..70a4d13 100644 --- a/Sources/FileSystem/FileSystem.swift +++ b/Sources/FileSystem/FileSystem.swift @@ -548,6 +548,14 @@ public struct FileSystem: FileSysteming, Sendable { withDestination: FilePath(to.pathString) ) } + + public func createSymbolicLink(from: AbsolutePath, to: RelativePath) async throws { + logger?.debug("Creating symbolic link from \(from.pathString) to \(to.pathString).") + try await NIOFileSystem.FileSystem.shared.createSymbolicLink( + at: FilePath(from.pathString), + withDestination: FilePath(to.pathString) + ) + } public func resolveSymbolicLink(_ symlinkPath: AbsolutePath) async throws -> AbsolutePath { logger?.debug("Resolving symbolink link at path \(symlinkPath.pathString).") From 31f34962210261adc7c47f3cf40139757061795f Mon Sep 17 00:00:00 2001 From: KaiOelfke Date: Wed, 18 Dec 2024 11:50:39 +0100 Subject: [PATCH 2/8] add failing test with relative sym link --- Tests/FileSystemTests/FileSystemTests.swift | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Tests/FileSystemTests/FileSystemTests.swift b/Tests/FileSystemTests/FileSystemTests.swift index a818573..ba698dc 100644 --- a/Tests/FileSystemTests/FileSystemTests.swift +++ b/Tests/FileSystemTests/FileSystemTests.swift @@ -855,7 +855,41 @@ final class FileSystemTests: XCTestCase, @unchecked Sendable { XCTAssertEqual(got, [symlinkSourceFilePath]) } } + + func test_glob_with_relative_symlink() async throws { + try await subject.runInTemporaryDirectory(prefix: "FileSystem") { temporaryDirectory in + // Given + let frameworkDir = temporaryDirectory.appending(component: "Framework") + let sourceDir = frameworkDir.appending(component: "Source") + let spmResourcesDir = sourceDir.appending(component: "SwiftPackageResources") + let modelSymLinkPath = spmResourcesDir.appending(component: "MyModel.xcdatamodeld") + + let actualResourcesDir = frameworkDir.appending(component: "Resources") + let actualModelPath = actualResourcesDir.appending(component: "MyModel.xcdatamodeld") + let versionPath = actualModelPath.appending(component: "MyModel_0.xcdatamodel") + + try await subject.makeDirectory(at: spmResourcesDir) + try await subject.makeDirectory(at: actualResourcesDir) + try await subject.makeDirectory(at: actualModelPath) + try await subject.touch(versionPath) + + let relativeActualModelPath = try RelativePath(validating: "../../Resources/MyModel.xcdatamodeld") + try await subject.createSymbolicLink(from: modelSymLinkPath, to: relativeActualModelPath) + // When + let got = try await subject.glob( + directory: modelSymLinkPath, + include: ["*.xcdatamodel"] + ) + .collect() + .sorted() + + // Then + XCTAssertEqual(got.count, 1) + XCTAssertEqual(got.map(\.basename), [versionPath.basename]) + } + } + func test_glob_with_double_directory_wildcard() async throws { try await subject.runInTemporaryDirectory(prefix: "FileSystem") { temporaryDirectory in // Given From e3f9d66cd539bc58e83b87cf5e0afc8ca32f6955 Mon Sep 17 00:00:00 2001 From: KaiOelfke Date: Wed, 18 Dec 2024 12:18:38 +0100 Subject: [PATCH 3/8] fix handling of relative symbolic link --- Sources/Glob/GlobSearch.swift | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Sources/Glob/GlobSearch.swift b/Sources/Glob/GlobSearch.swift index d429a5b..28b6864 100644 --- a/Sources/Glob/GlobSearch.swift +++ b/Sources/Glob/GlobSearch.swift @@ -83,17 +83,13 @@ public func search( } let path = baseURL.absoluteString.removingPercentEncoding ?? baseURL.absoluteString - let symbolicLinkDestination: URL? - if let symbolicLinkDestinationAbsoluteString = try? FileManager.default - .destinationOfSymbolicLink(atPath: path) - { - symbolicLinkDestination = URL(string: symbolicLinkDestinationAbsoluteString) - } else { - symbolicLinkDestination = nil - } + let symbolicLinkDestination: URL = URL(filePath: path).resolvingSymlinksInPath() var isDirectory: ObjCBool = false + + let symbolicLinkDestinationPath: String = symbolicLinkDestination.path().removingPercentEncoding ?? symbolicLinkDestination.path() + guard FileManager.default.fileExists( - atPath: symbolicLinkDestination?.absoluteString ?? path, + atPath: symbolicLinkDestinationPath, isDirectory: &isDirectory ), isDirectory.boolValue From f26bb33e829aab030fe54ab20f8d27c0bb649256 Mon Sep 17 00:00:00 2001 From: KaiOelfke Date: Wed, 18 Dec 2024 12:29:18 +0100 Subject: [PATCH 4/8] formatting --- Sources/FileSystem/FileSystem.swift | 2 +- Tests/FileSystemTests/FileSystemTests.swift | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/FileSystem/FileSystem.swift b/Sources/FileSystem/FileSystem.swift index 70a4d13..c81666c 100644 --- a/Sources/FileSystem/FileSystem.swift +++ b/Sources/FileSystem/FileSystem.swift @@ -548,7 +548,7 @@ public struct FileSystem: FileSysteming, Sendable { withDestination: FilePath(to.pathString) ) } - + public func createSymbolicLink(from: AbsolutePath, to: RelativePath) async throws { logger?.debug("Creating symbolic link from \(from.pathString) to \(to.pathString).") try await NIOFileSystem.FileSystem.shared.createSymbolicLink( diff --git a/Tests/FileSystemTests/FileSystemTests.swift b/Tests/FileSystemTests/FileSystemTests.swift index ba698dc..d8fe944 100644 --- a/Tests/FileSystemTests/FileSystemTests.swift +++ b/Tests/FileSystemTests/FileSystemTests.swift @@ -855,7 +855,7 @@ final class FileSystemTests: XCTestCase, @unchecked Sendable { XCTAssertEqual(got, [symlinkSourceFilePath]) } } - + func test_glob_with_relative_symlink() async throws { try await subject.runInTemporaryDirectory(prefix: "FileSystem") { temporaryDirectory in // Given @@ -863,16 +863,16 @@ final class FileSystemTests: XCTestCase, @unchecked Sendable { let sourceDir = frameworkDir.appending(component: "Source") let spmResourcesDir = sourceDir.appending(component: "SwiftPackageResources") let modelSymLinkPath = spmResourcesDir.appending(component: "MyModel.xcdatamodeld") - + let actualResourcesDir = frameworkDir.appending(component: "Resources") let actualModelPath = actualResourcesDir.appending(component: "MyModel.xcdatamodeld") let versionPath = actualModelPath.appending(component: "MyModel_0.xcdatamodel") - + try await subject.makeDirectory(at: spmResourcesDir) try await subject.makeDirectory(at: actualResourcesDir) try await subject.makeDirectory(at: actualModelPath) try await subject.touch(versionPath) - + let relativeActualModelPath = try RelativePath(validating: "../../Resources/MyModel.xcdatamodeld") try await subject.createSymbolicLink(from: modelSymLinkPath, to: relativeActualModelPath) @@ -883,13 +883,13 @@ final class FileSystemTests: XCTestCase, @unchecked Sendable { ) .collect() .sorted() - + // Then XCTAssertEqual(got.count, 1) XCTAssertEqual(got.map(\.basename), [versionPath.basename]) } } - + func test_glob_with_double_directory_wildcard() async throws { try await subject.runInTemporaryDirectory(prefix: "FileSystem") { temporaryDirectory in // Given From e963a817fe853e89c883c0aeb4ffb019a8411597 Mon Sep 17 00:00:00 2001 From: KaiOelfke Date: Fri, 20 Dec 2024 11:51:42 +0100 Subject: [PATCH 5/8] add createSymbolicLink with RelativePath to FileSysteming protocol --- Sources/FileSystem/FileSystem.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/FileSystem/FileSystem.swift b/Sources/FileSystem/FileSystem.swift index c81666c..a82f52a 100644 --- a/Sources/FileSystem/FileSystem.swift +++ b/Sources/FileSystem/FileSystem.swift @@ -219,6 +219,12 @@ public protocol FileSysteming { /// - from: The path where the symlink is created. /// - to: The path the symlink points to. func createSymbolicLink(from: AbsolutePath, to: AbsolutePath) async throws + + /// Creates a relative symlink. + /// - Parameters: + /// - from: The path where the symlink is created. + /// - to: The relative path the symlink points to. + func createSymbolicLink(from: AbsolutePath, to: RelativePath) async throws /// Given a symlink, it resolves it returning the path to the file or directory the symlink is pointing to. /// - Parameter symlinkPath: The absolute path to the symlink. From 09ade56dc54ce098563a501ec3d2f8cb93b504a3 Mon Sep 17 00:00:00 2001 From: KaiOelfke Date: Fri, 20 Dec 2024 11:55:28 +0100 Subject: [PATCH 6/8] add private helper func for creating symbolic links with absolute and relative path --- Sources/FileSystem/FileSystem.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/FileSystem/FileSystem.swift b/Sources/FileSystem/FileSystem.swift index a82f52a..1b14438 100644 --- a/Sources/FileSystem/FileSystem.swift +++ b/Sources/FileSystem/FileSystem.swift @@ -548,18 +548,18 @@ public struct FileSystem: FileSysteming, Sendable { } public func createSymbolicLink(from: AbsolutePath, to: AbsolutePath) async throws { - logger?.debug("Creating symbolic link from \(from.pathString) to \(to.pathString).") - try await NIOFileSystem.FileSystem.shared.createSymbolicLink( - at: FilePath(from.pathString), - withDestination: FilePath(to.pathString) - ) + try await createSymbolicLink(fromPathString: from.pathString, toPathString: to.pathString) } public func createSymbolicLink(from: AbsolutePath, to: RelativePath) async throws { - logger?.debug("Creating symbolic link from \(from.pathString) to \(to.pathString).") + try await createSymbolicLink(fromPathString: from.pathString, toPathString: to.pathString) + } + + private func createSymbolicLink(fromPathString: String, toPathString: String) async throws { + logger?.debug("Creating symbolic link from \(fromPathString) to \(toPathString).") try await NIOFileSystem.FileSystem.shared.createSymbolicLink( - at: FilePath(from.pathString), - withDestination: FilePath(to.pathString) + at: FilePath(fromPathString), + withDestination: FilePath(toPathString) ) } From 7575043bf787c99d40f898b4bfbdbe2b51141c8c Mon Sep 17 00:00:00 2001 From: KaiOelfke Date: Thu, 9 Jan 2025 17:25:18 +0800 Subject: [PATCH 7/8] formatting --- Sources/FileSystem/FileSystem.swift | 8 ++++---- Sources/Glob/GlobSearch.swift | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Sources/FileSystem/FileSystem.swift b/Sources/FileSystem/FileSystem.swift index 1b14438..25a1455 100644 --- a/Sources/FileSystem/FileSystem.swift +++ b/Sources/FileSystem/FileSystem.swift @@ -219,7 +219,7 @@ public protocol FileSysteming { /// - from: The path where the symlink is created. /// - to: The path the symlink points to. func createSymbolicLink(from: AbsolutePath, to: AbsolutePath) async throws - + /// Creates a relative symlink. /// - Parameters: /// - from: The path where the symlink is created. @@ -548,13 +548,13 @@ public struct FileSystem: FileSysteming, Sendable { } public func createSymbolicLink(from: AbsolutePath, to: AbsolutePath) async throws { - try await createSymbolicLink(fromPathString: from.pathString, toPathString: to.pathString) + try await createSymbolicLink(fromPathString: from.pathString, toPathString: to.pathString) } public func createSymbolicLink(from: AbsolutePath, to: RelativePath) async throws { - try await createSymbolicLink(fromPathString: from.pathString, toPathString: to.pathString) + try await createSymbolicLink(fromPathString: from.pathString, toPathString: to.pathString) } - + private func createSymbolicLink(fromPathString: String, toPathString: String) async throws { logger?.debug("Creating symbolic link from \(fromPathString) to \(toPathString).") try await NIOFileSystem.FileSystem.shared.createSymbolicLink( diff --git a/Sources/Glob/GlobSearch.swift b/Sources/Glob/GlobSearch.swift index 28b6864..b41c520 100644 --- a/Sources/Glob/GlobSearch.swift +++ b/Sources/Glob/GlobSearch.swift @@ -83,11 +83,13 @@ public func search( } let path = baseURL.absoluteString.removingPercentEncoding ?? baseURL.absoluteString - let symbolicLinkDestination: URL = URL(filePath: path).resolvingSymlinksInPath() + let symbolicLinkDestination = URL(filePath: path).resolvingSymlinksInPath() var isDirectory: ObjCBool = false - - let symbolicLinkDestinationPath: String = symbolicLinkDestination.path().removingPercentEncoding ?? symbolicLinkDestination.path() - + + let symbolicLinkDestinationPath: String = symbolicLinkDestination + .path() + .removingPercentEncoding ?? symbolicLinkDestination.path() + guard FileManager.default.fileExists( atPath: symbolicLinkDestinationPath, isDirectory: &isDirectory From 2734f7d5e6442c2885b445a5df02d98e63120143 Mon Sep 17 00:00:00 2001 From: fortmarek Date: Thu, 9 Jan 2025 16:04:39 +0100 Subject: [PATCH 8/8] Make authentication optional --- Tuist.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Tuist.swift b/Tuist.swift index f1955d3..1d194d0 100644 --- a/Tuist.swift +++ b/Tuist.swift @@ -1,3 +1,10 @@ import ProjectDescription -let tuist = Tuist(fullHandle: "tuist/FileSystem") +let tuist = Tuist( + fullHandle: "tuist/FileSystem", + project: .tuist( + generationOptions: .options( + optionalAuthentication: true + ) + ) +)