From c9b48350f33fdacaff47251a30cea6104e741b9e Mon Sep 17 00:00:00 2001 From: Jeremy Greenwood Date: Tue, 30 May 2023 14:23:52 -0400 Subject: [PATCH 1/6] symlink resource artifacts --- Sources/MintKit/Mint.swift | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/Sources/MintKit/Mint.swift b/Sources/MintKit/Mint.swift index cff2622..0519e16 100644 --- a/Sources/MintKit/Mint.swift +++ b/Sources/MintKit/Mint.swift @@ -293,6 +293,7 @@ public class Mint { try linkPackage(package, executable: executable, overwrite: overwrite) } } + try linkResources(package) checkLinkPath() } return false @@ -390,6 +391,7 @@ public class Mint { try linkPackage(package, executable: executable, overwrite: overwrite) } } + try linkResources(package) checkLinkPath() } @@ -406,12 +408,7 @@ public class Mint { pathsToCopy.append(executablePath) } - let copiedExtensions: Set = ["bundle", "resources", "dylib"] - for path in try buildPath.children() { - if let ext = path.extension, copiedExtensions.contains(ext) { - pathsToCopy.append(path) - } - } + try pathsToCopy.append(contentsOf: getResources(from: buildPath)) for path in pathsToCopy { let destinationPath = installPath + path.lastComponent @@ -422,6 +419,18 @@ public class Mint { try Task.run(bash: "cp -R \(path.string) \(destinationPath.string)") } } + + private func getResources(from path: Path) throws -> [Path] { + let extensions: Set = ["bundle", "resources", "dylib"] + + return try path.children().filter { + guard let ext = $0.extension, extensions.contains(ext) else { + return false + } + + return true + } + } private func checkLinkPath() { if let path = ProcessInfo.processInfo.environment["PATH"], !path.contains(linkPath.string) { @@ -491,6 +500,22 @@ public class Mint { output(confirmation.green) } + func linkResources(_ package: PackageReference) throws { + let packagePath = PackagePath(path: packagesPath, package: package) + let resources = try getResources(from: packagePath.installPath) + + for resource in resources { + let installPath = linkPath + resource.lastComponent + + do { + try Task.run(bash: "ln -s \"\(packagePath.installPath + resource.lastComponent)\" \"\(installPath.string)\"") + } catch { + errorOutput("Could not link \(resource.lastComponent) to \(installPath.string)".red) + return + } + } + } + public func bootstrap(link: Bool = false, overwrite: Bool? = nil) throws { let mintFile = try Mintfile(path: mintFilePath) From ef19cb1fad9892677da3bcab047a0dd648cafc48 Mon Sep 17 00:00:00 2001 From: Jeremy Greenwood Date: Tue, 30 May 2023 14:43:33 -0400 Subject: [PATCH 2/6] remove resource artifact link on uninstall --- Sources/MintKit/Mint.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sources/MintKit/Mint.swift b/Sources/MintKit/Mint.swift index 0519e16..807dd5d 100644 --- a/Sources/MintKit/Mint.swift +++ b/Sources/MintKit/Mint.swift @@ -564,6 +564,11 @@ public class Mint { let option = Input.readOption(options: packages.map { $0.gitRepo }, prompt: "There are multiple packages matching '\(name)', which one would you like to uninstall?") package = packages.first { $0.gitRepo == option }! } + + let resources = try package.versionDirs + .map { try getResources(from: $0.path) } + .flatMap { $0 } + try package.path.delete() output("\(package.name) was uninstalled") @@ -576,5 +581,11 @@ public class Mint { let installPath = linkPath + executable.name try installPath.delete() } + + // remove resource artifact link + for resource in resources { + let installPath = linkPath + resource.lastComponent + try installPath.delete() + } } } From 49ed2a0bb90a184091b772423831c6f6decded18 Mon Sep 17 00:00:00 2001 From: Jeremy Greenwood Date: Thu, 5 Oct 2023 12:32:53 -0400 Subject: [PATCH 3/6] overwrite resource symlink --- Sources/MintKit/Mint.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/MintKit/Mint.swift b/Sources/MintKit/Mint.swift index 807dd5d..3d08175 100644 --- a/Sources/MintKit/Mint.swift +++ b/Sources/MintKit/Mint.swift @@ -508,7 +508,7 @@ public class Mint { let installPath = linkPath + resource.lastComponent do { - try Task.run(bash: "ln -s \"\(packagePath.installPath + resource.lastComponent)\" \"\(installPath.string)\"") + try Task.run(bash: "ln -s -f \"\(packagePath.installPath + resource.lastComponent)\" \"\(installPath.string)\"") } catch { errorOutput("Could not link \(resource.lastComponent) to \(installPath.string)".red) return From 0488c979ece318b64eba80a46723d323bb7aba4b Mon Sep 17 00:00:00 2001 From: Jeremy Greenwood Date: Thu, 5 Oct 2023 13:37:30 -0400 Subject: [PATCH 4/6] =?UTF-8?q?use=20don=E2=80=99t=20follow=20link=20optio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/MintKit/Mint.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/MintKit/Mint.swift b/Sources/MintKit/Mint.swift index 3d08175..30440f6 100644 --- a/Sources/MintKit/Mint.swift +++ b/Sources/MintKit/Mint.swift @@ -508,7 +508,7 @@ public class Mint { let installPath = linkPath + resource.lastComponent do { - try Task.run(bash: "ln -s -f \"\(packagePath.installPath + resource.lastComponent)\" \"\(installPath.string)\"") + try Task.run(bash: "ln -s -f -h \"\(packagePath.installPath + resource.lastComponent)\" \"\(installPath.string)\"") } catch { errorOutput("Could not link \(resource.lastComponent) to \(installPath.string)".red) return From 099b362bdbf3ba9e4f3dae321bb69f5faa774b3e Mon Sep 17 00:00:00 2001 From: Jeremy Greenwood Date: Thu, 5 Oct 2023 13:37:53 -0400 Subject: [PATCH 5/6] suppress delete symlink errors --- Sources/MintKit/Mint.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/MintKit/Mint.swift b/Sources/MintKit/Mint.swift index 30440f6..71080b9 100644 --- a/Sources/MintKit/Mint.swift +++ b/Sources/MintKit/Mint.swift @@ -565,6 +565,7 @@ public class Mint { package = packages.first { $0.gitRepo == option }! } + // get resources across all installed versions let resources = try package.versionDirs .map { try getResources(from: $0.path) } .flatMap { $0 } @@ -582,10 +583,13 @@ public class Mint { try installPath.delete() } - // remove resource artifact link + // remove all resource artifact links for resource in resources { let installPath = linkPath + resource.lastComponent - try installPath.delete() + + /* `try?` to suppress error in console, which will + happen when same resource is deleted from multiple versions */ + try? installPath.delete() } } } From 758c8f0772a75712ff7aa4ad54ad4c80b6e1d09f Mon Sep 17 00:00:00 2001 From: Jeremy Greenwood Date: Thu, 5 Oct 2023 13:59:18 -0400 Subject: [PATCH 6/6] better deletion handling --- Sources/MintKit/Mint.swift | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Sources/MintKit/Mint.swift b/Sources/MintKit/Mint.swift index 71080b9..79d6530 100644 --- a/Sources/MintKit/Mint.swift +++ b/Sources/MintKit/Mint.swift @@ -566,9 +566,11 @@ public class Mint { } // get resources across all installed versions - let resources = try package.versionDirs - .map { try getResources(from: $0.path) } - .flatMap { $0 } + let resources = Set( + try package.versionDirs + .map { try getResources(from: $0.path) } + .flatMap { $0 } + ) try package.path.delete() output("\(package.name) was uninstalled") @@ -586,10 +588,7 @@ public class Mint { // remove all resource artifact links for resource in resources { let installPath = linkPath + resource.lastComponent - - /* `try?` to suppress error in console, which will - happen when same resource is deleted from multiple versions */ - try? installPath.delete() + try installPath.delete() } } }