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.

Stop reading a Tomcat working folder as an app's identifier

Țugui Dragoș2567a9757a16
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 55a4d25a..d7ee852c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -181,6 +181,8 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.
#### Orphaned Files
+- The folders a Spring Boot server's embedded Tomcat leaves in the temporary folder, named `tomcat.` with the port and a
+ number, are no longer taken for apps' files, each listed as a gone app of its own.
- Lists what an app with a tool's identifier left while another such app is installed.
#### Orphaned Files and Storage
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift
index 00d4d646..d2c12856 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Naming.swift
@@ -107,15 +107,17 @@ enum Identifier {
}
/// Whether a name found on disk reads as an app's identifier, "com.example.app": at least three components and a
- /// lowercase top-level domain after any `catalystPrefix`. Stricter than `isValid`, since a name nobody declared
- /// is only a guess.
+ /// lowercase top-level domain after any `catalystPrefix`, and a name among the components after it, not only
+ /// numbers, as in a server's folder named for its port and a random number (`tomcat.8080.10018690101673077448`).
+ /// Stricter than `isValid`, since a name nobody declared is only a guess.
static func isReverseDNS(_ identifier: String) -> Bool {
let components = withoutCatalystPrefix(identifier).split(separator: ".", omittingEmptySubsequences: false)
guard
components.count >= 3,
let domain = components.first,
(2...6).contains(domain.count),
- domain.allSatisfy({ $0.isASCII && $0.isLowercase })
+ domain.allSatisfy({ $0.isASCII && $0.isLowercase }),
+ components.dropFirst().contains(where: { component in component.contains { !$0.isNumber } })
else { return false }
return components.allSatisfy { component in
!component.isEmpty
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
index 4383439e..9ba260b2 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
@@ -961,11 +961,32 @@ struct OrphanScannerTests {
("maccatalyst.org.example.notes", .containers, "maccatalyst.org.example.notes"),
("maccatalyst.org.example", .caches, nil),
("maccatalyst.com.apple.news", .containers, nil),
+ ("tomcat.8080.10018690101673077448", .temporaryItems, nil),
+ ("tomcat.8080.10018690101673077448", .caches, nil),
+ ("com.sublimetext.4", .caches, "com.sublimetext.4"),
+ ("xyz.960960.koodo", .caches, "xyz.960960.koodo"),
] as [(String, SearchLocation.Kind, String?)])
func identifiesAppShapedNames(key: String, kind: SearchLocation.Kind, expected: String?) {
#expect(OrphanScanner.orphanIdentifier(forKey: key, kind: kind) == expected)
}
+ @Test func leavesTheFoldersSpringBootsServersMakeInTheTemporaryFolderAlone() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("var/T/tomcat.8080.10018690101673077448/work/Tomcat/localhost/ROOT/SESSIONS.ser")
+ try directory.file("var/T/tomcat.8080.10054962961815905490/work/Tomcat/localhost/ROOT/SESSIONS.ser")
+ try directory.file("var/T/com.gone.app/cache.db")
+ let environment = SearchEnvironment(
+ homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),
+ rootDirectory: directory.url.appending(path: "root", directoryHint: .isDirectory),
+ userTemporaryDirectory: directory.url.appending(path: "var/T", directoryHint: .isDirectory)
+ )
+
+ let scan = await OrphanScanner(environment: environment, isRegisteredApp: { _ in false }, systemApps: [])
+ .scan(installedApps: installed)
+
+ #expect(scan.groups.map(\.identifier) == ["com.gone.app"])
+ }
+
@Test func findsWhatAMacCatalystBuildLeft() async throws {
let directory = try TemporaryDirectory()
try directory.file("home/Library/Containers/maccatalyst.org.example.notes/Data/Library/Caches/cache.db")