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 the folders Spring Boot's servers leave in the temporary folder

Țugui Dragoș52845de846dd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d7ee852c..4509a808 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -37,6 +37,9 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.
#### Developer
+- Spring Boot, with the working folders its servers leave in the temporary folder each time they start (`tomcat.`,
+ `tomcat-docbase.` or `jetty-docbase.` with the port and a number). One something wrote to in the last 15 minutes is
+ listed and not selected, since a server still running may be using it.
- Lists the templates create-expo-app keeps in the temporary folder, and the Chrome that agent-browser downloads, which
`agent-browser install` fetches again.
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
index ff66dc2c..6bb2c1b8 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
@@ -161,12 +161,15 @@ public enum DeveloperCaches {
/// Where a Git clone here comes from when it is the tool's own, as `ToolSettings.gitAddress` writes it. A clone
/// of anything else, which the person may have added under the same name, is listed and never selected.
let clonedFrom: String?
+ /// True for a folder a running program may use without holding it open, which is listed and not selected
+ /// while something wrote to it within `HoldBack.stillInUse`.
+ let holdsBackRecentWrites: Bool
init(
_ path: String, _ kind: DeveloperEnvironment.ContentKind, source: String, storeInside: String? = nil,
rowsDepth: Int = 0, rowEnding: String? = nil, rowsAreDerivedData: Bool = false,
rowsAreProjectState: Bool = false, movedBy: Relocation? = nil, base: Base = .home,
- launchers: [String] = [], clonedFrom: String? = nil
+ launchers: [String] = [], clonedFrom: String? = nil, holdsBackRecentWrites: Bool = false
) {
self.path = path
self.kind = kind
@@ -180,6 +183,7 @@ public enum DeveloperCaches {
self.base = base
self.launchers = launchers
self.clonedFrom = clonedFrom
+ self.holdsBackRecentWrites = holdsBackRecentWrites
}
/// Whether what is at `url` is the tool's own, as far as where it was cloned from says.
@@ -690,6 +694,25 @@ public enum DeveloperCaches {
Folder(".coursier/cache/v1", .downloads, source: "https://github.com/coursier/coursier/blob/d3006393e44af0dc0165813f262de2de51e17a46/doc/docs/cache.md#L48-L54"),
Folder("Library/Caches/sbt", .buildData, source: "https://github.com/sbt/sbt/blob/f4618946c5b7055083f8c74bf84e4d1ad5e6a1e9/main/src/main/scala/sbt/internal/SysProp.scala#L231-L245"),
]),
+ // A Spring Boot server makes these each time it starts, named for its port and a random number
+ // (`AbstractConfigurableWebServerFactory.TempDirs`), and before Spring Boot 4.1 left them behind.
+ Definition(id: "springboot", name: "Spring Boot", systemImage: "cup.and.saucer", appBundleIdentifiers: [], folders: [
+ Folder(
+ "tomcat.*.*/", .cache,
+ source: "https://github.com/spring-projects/spring-boot/blob/e5e959e3b66bba353aa87f49d9b8036ebb63f0dc/module/spring-boot-tomcat/src/main/java/org/springframework/boot/tomcat/TomcatWebServerFactory.java#L412",
+ base: .userTemporary, holdsBackRecentWrites: true
+ ),
+ Folder(
+ "tomcat-docbase.*.*/", .cache,
+ source: "https://github.com/spring-projects/spring-boot/blob/e5e959e3b66bba353aa87f49d9b8036ebb63f0dc/module/spring-boot-tomcat/src/main/java/org/springframework/boot/tomcat/servlet/TomcatServletWebServerFactory.java#L191",
+ base: .userTemporary, holdsBackRecentWrites: true
+ ),
+ Folder(
+ "jetty-docbase.*.*/", .cache,
+ source: "https://github.com/spring-projects/spring-boot/blob/e5e959e3b66bba353aa87f49d9b8036ebb63f0dc/module/spring-boot-jetty/src/main/java/org/springframework/boot/jetty/servlet/JettyServletWebServerFactory.java#L305",
+ base: .userTemporary, holdsBackRecentWrites: true
+ ),
+ ]),
// Java Web Start keeps the applications a person installed in its cache, beside the ones it only cached.
Definition(id: "oraclejava", name: "Java Web Start", systemImage: "cup.and.saucer", appBundleIdentifiers: [], folders: [
Folder("Library/Application Support/Oracle/Java/Deployment/cache", .environments, source: "https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/jcp.html"),
@@ -1579,6 +1602,8 @@ public enum DeveloperCaches {
isTheTools: derived?.isXcodes ?? folder.isTheTools(at: url),
lastWritten: contents.flatMap { $0.couldNotBeRead ? nil : $0.newestChange },
heldBack: contents.flatMap(HoldBack.secret(in:))
+ ?? (folder.holdsBackRecentWrites && HoldBack.wasWrittenRecently(url, contents: contents)
+ ? .writtenRecently : nil)
))
}
guard !locations.isEmpty else { return nil }
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
index 0cb71899..c367dadc 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
@@ -165,6 +165,17 @@ public enum HoldBack: String, Sendable, Hashable {
if contents.holdsWallet { return .holdsAWallet }
return contents.holdsPasswordDatabase ? .holdsAPasswordDatabase : nil
}
+
+ /// How long after a write a program may still be using what it wrote (`writtenRecently`).
+ static let stillInUse: TimeInterval = 15 * 60
+
+ /// Whether something wrote to `url` within `stillInUse`. The folder's own date counts too: it moves when an entry
+ /// is added or removed.
+ static func wasWrittenRecently(_ url: URL, contents: FolderContents?) -> Bool {
+ let own = (try? url.resourceValues(forKeys: [.contentModificationDateKey]))?.contentModificationDate
+ guard let written = [own, contents?.newestChange].compactMap(\.self).max() else { return false }
+ return Date.now.timeIntervalSince(written) < stillInUse
+ }
}
public struct LeftoverMatch: Sendable, Hashable {
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift
index 4993b670..5c2bad4c 100644
--- a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift
@@ -96,7 +96,7 @@ public enum SpaceRemoval {
let beyond: HoldBack? = needsAnAdministrator && reach.isBeyond(child) ? .beyondTheHelper : nil
heldBack[child] = beyond ?? item.heldBack
?? (systemCaches.keeps(child) ? .keptByMacOS : HoldBack.seen(in: contents))
- ?? (item.holdsBackRecentWrites && wasWrittenRecently(child, contents: contents)
+ ?? (item.holdsBackRecentWrites && HoldBack.wasWrittenRecently(child, contents: contents)
? .writtenRecently : nil)
}
return Plan(
@@ -108,15 +108,6 @@ public enum SpaceRemoval {
)
}
- static let stillInUse: TimeInterval = 15 * 60
-
- /// The folder's own date counts too: it moves when an entry is added or removed.
- private static func wasWrittenRecently(_ child: URL, contents: FolderContents?) -> Bool {
- let own = (try? child.resourceValues(forKeys: [.contentModificationDateKey]))?.contentModificationDate
- guard let written = [own, contents?.newestChange].compactMap(\.self).max() else { return false }
- return Date.now.timeIntervalSince(written) < stillInUse
- }
-
@concurrent
public static func sizesLeftToDeveloper(in plan: Plan) async -> [URL: Int64] {
await sizesLeftToDeveloper(in: plan, measure: LeftoverScanner.walk)
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/SpaceReport.swift b/Packages/PeelCore/Sources/PeelCore/Space/SpaceReport.swift
index d370157d..2ffa68b8 100644
--- a/Packages/PeelCore/Sources/PeelCore/Space/SpaceReport.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Space/SpaceReport.swift
@@ -31,7 +31,7 @@ public struct SpaceItem: Sendable, Hashable, Identifiable {
/// True when what macOS keeps in its folders for its own services is neither measured nor offered: there they run
/// as other accounts, whose open files Peel cannot see, or keep caches not even Full Disk Access can read.
public var leavesMacOSsOwn = false
- /// A child something wrote to in the last few minutes is held back (`SpaceRemoval.stillInUse`).
+ /// A child something wrote to in the last few minutes is held back (`HoldBack.stillInUse`).
public var holdsBackRecentWrites = false
/// The folders of `urls` where macOS files reports into folders of its own, so only their files are offered.
public var onlyFilesIn: [URL] = []
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
index 574ec658..658c913c 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
@@ -486,7 +486,7 @@ struct DeveloperCachesTests {
".ccache", ".electron-gyp", ".gitlibs", ".node-gyp", ".virtualenvs", "nltk_data", "tensorflow_datasets",
".zcompdump*", ".pnpm-store", "playwright_*dev_profile-*/", "playwright-artifacts-*/", "metro-cache/",
"metro-file-map-*", "node-compile-cache/", "tfhub_modules/", ".electron", "gensim-data", "stanza_resources",
- ".u2net", ".create-expo-app",
+ ".u2net", ".create-expo-app", "tomcat.*.*/", "tomcat-docbase.*.*/", "jetty-docbase.*.*/",
]
for definition in DeveloperCaches.definitions {
for path in definition.folders.map(\.path) {
@@ -1715,6 +1715,39 @@ struct DeveloperCachesTests {
#expect(locations.allSatisfy { $0.kind == .cache && $0.isRecommended })
}
+ @Test func offersWhatSpringBootsServersLeftInTheTemporaryFolderAndHoldsBackOneStillWritten() async throws {
+ let directory = try TemporaryDirectory()
+ let temporary = try directory.directory("var/T")
+ let anHourAgo = Date.now.addingTimeInterval(-3600)
+ for name in [
+ "tomcat.8080.10018690101673077448", "tomcat-docbase.8080.10054962961815905490",
+ "jetty-docbase.8080.10339006057543989247", "tomcat-native",
+ ] {
+ let file = try directory.file("var/T/\(name)/work/SESSIONS.ser", bytes: 400_000)
+ let work = file.deletingLastPathComponent()
+ for url in [file, work, work.deletingLastPathComponent()] {
+ try FileManager.default.setAttributes(
+ [.modificationDate: anHourAgo], ofItemAtPath: url.path(percentEncoded: false)
+ )
+ }
+ }
+ try directory.file("var/T/tomcat.8081.10600000000000000000/work/upload.tmp", bytes: 400_000)
+ let springBoot = DeveloperCaches.definitions.filter { $0.id == "springboot" }
+
+ let locations = await DeveloperCaches.scan(
+ springBoot, homeDirectory: directory.url.appending(path: "home"), userTemporaryDirectory: temporary,
+ openFiles: OpenFiles(excluding: nil)
+ ).flatMap(\.locations)
+
+ #expect(Set(locations.map(\.url.lastPathComponent)) == [
+ "tomcat.8080.10018690101673077448", "tomcat-docbase.8080.10054962961815905490",
+ "jetty-docbase.8080.10339006057543989247", "tomcat.8081.10600000000000000000",
+ ])
+ let running = try #require(locations.first { $0.url.lastPathComponent.hasPrefix("tomcat.8081.") })
+ #expect(running.heldBack == .writtenRecently && !running.isRecommended)
+ #expect(locations.filter { $0.url != running.url }.allSatisfy { $0.kind == .cache && $0.isRecommended })
+ }
+
@Test func offersMetrosCachesInTheTemporaryFolderAndNothingInUse() async throws {
let directory = try TemporaryDirectory()
let temporary = try directory.directory("var/T")
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DocumentationTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DocumentationTests.swift
index 388caf7a..28c333f2 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DocumentationTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DocumentationTests.swift
@@ -36,7 +36,7 @@ struct DocumentationTests {
let records = RemovalLog.maximumRecords.formatted(.number.locale(Locale(identifier: "en_US")))
let idle = Int(HelperLifetime.standardIdleTimeout)
let results = FileSearch.maximumResults.formatted(.number.locale(Locale(identifier: "en_US")))
- let minutes = Int(SpaceRemoval.stillInUse / 60)
+ let minutes = Int(HoldBack.stillInUse / 60)
let days = Int(ProjectArtifacts.recentlyActive / (24 * 60 * 60))
#expect(Installers.stillDownloading == 24 * 60 * 60, "the documents say a download that changed in the last day")
#expect(Homebrew.autoUpdateInterval == 24 * 60 * 60, "the documents say what Homebrew says counts for a day")