Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

List a Java runtime linked into the Java folder where it is

Țugui Dragoș116066fca3bf
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 41e7aae6..f66757ea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -513,6 +513,8 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.
code once though a job or a command runs it.
- A plug-in nothing loads anymore says so instead of offering Rosetta, a universal app that opens as Intel isn't called
Intel only, and a job of an excluded app stays off the page.
+- A Java runtime linked into the Java folder, as Homebrew's `openjdk` asks, is listed where it is, with its real size,
+ rather than as a link of Zero kB.
#### Package Receipts
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift b/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift
index 6fb8333e..1a361b79 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift
@@ -216,9 +216,12 @@ public enum IntelInspector {
))
}
- for runtime in intelOnlyJavaRuntimes(
+ for found in intelOnlyJavaRuntimes(
in: libraryDirectories(environment, folders: [javaRuntimes]), unreadable: &unreadable
- ) where !Task.isCancelled && !exclusions.excludes(runtime) && isNew(runtime) {
+ ) where !Task.isCancelled && !exclusions.excludes(found) {
+ // Homebrew's `openjdk` asks for a link here, and a link says neither where a runtime is nor what it takes.
+ let runtime = found.isSymbolicLink ? PathPattern.canonicalWithoutOpening(found) : found
+ guard !exclusions.excludes(runtime), isNew(runtime) else { continue }
let info = AppInspector.infoDictionary(in: runtime.appending(path: "Contents", directoryHint: .isDirectory))
findings.append(IntelFinding(
url: runtime,
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift
index 43b09798..70b37634 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift
@@ -471,6 +471,43 @@ struct IntelInspectorTests {
#expect(scan.unreadable.isEmpty, "named \(scan.unreadable)")
}
+ @Test func aRuntimeLinkedIntoTheFolderIsListedWhereItIs() async throws {
+ let directory = try TemporaryDirectory()
+ try javaRuntime(directory, "elsewhere/libexec/openjdk.jdk", [intel], name: "Linked JDK")
+ try javaRuntime(directory, "root/Library/Java/JavaVirtualMachines/temurin-17.jdk", [intel], name: nil)
+ let folder = directory.url.appending(path: "root/Library/Java/JavaVirtualMachines", directoryHint: .isDirectory)
+ let runtime = directory.url.appending(path: "elsewhere/libexec/openjdk.jdk", directoryHint: .isDirectory)
+ try FileManager.default.createSymbolicLink(
+ at: folder.appending(path: "openjdk.jdk"), withDestinationURL: runtime
+ )
+ try FileManager.default.createSymbolicLink(
+ at: folder.appending(path: "current.jdk"), withDestinationURL: folder.appending(path: "temurin-17.jdk")
+ )
+ let measured = Mutex<[String]>([])
+
+ let scan = await IntelInspector.scan(
+ installedApps: [],
+ exclusions: .none,
+ environment: SearchEnvironment(
+ homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),
+ rootDirectory: directory.url.appending(path: "root", directoryHint: .isDirectory)
+ ),
+ measure: { url in
+ measured.withLock { $0.append(PathPattern.comparablePath(of: url)) }
+ return 1
+ }
+ )
+
+ let places = scan.findings.map { PathPattern.comparablePath(of: $0.url) }.sorted()
+ let expected = [
+ PathPattern.comparablePath(of: PathPattern.canonical(folder.appending(path: "temurin-17.jdk"))),
+ PathPattern.comparablePath(of: PathPattern.canonical(runtime)),
+ ].sorted()
+ #expect(places == expected)
+ #expect(scan.findings.map(\.name).contains("Linked JDK"))
+ #expect(measured.withLock { $0.sorted() } == expected)
+ }
+
@Test func looksForCommandsUnderTheRootItIsGiven() async throws {
let directory = try TemporaryDirectory()
let tool = try directory.file("root/usr/local/bin/tool", contents: fatHeader([intel]))