Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Sources/MacClean/Core/Scanner/TargetedScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,13 @@ public actor TargetedScanner {

private static func makeFileItem(from url: URL, keys: [URLResourceKey]) -> FileItem? {
guard let values = try? url.resourceValues(forKeys: Set(keys)) else { return nil }
// (st_dev, st_ino) let DuplicateDetection collapse hard links. If lstat
// fails (transient permission/race), keep the file with inode/deviceID 0
// rather than dropping it from the scan: 0 is treated as "unknown, never
// a hard-link match", so the file still shows up for the six non-dedup
// modules and is simply never collapsed as a duplicate.
var metadata = stat()
guard lstat(url.path(percentEncoded: false), &metadata) == 0 else { return nil }
let hasIdentity = lstat(url.path(percentEncoded: false), &metadata) == 0

return FileItem(
url: url,
Expand All @@ -206,8 +211,8 @@ public actor TargetedScanner {
contentType: values.contentType,
creationDate: values.creationDate,
modificationDate: values.contentModificationDate,
inode: UInt64(metadata.st_ino),
deviceID: Int32(metadata.st_dev)
inode: hasIdentity ? UInt64(metadata.st_ino) : 0,
deviceID: hasIdentity ? Int32(metadata.st_dev) : 0
)
}
}
15 changes: 15 additions & 0 deletions Sources/MacClean/Views/Performance/ResourceHogsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ struct ResourceHogsView: View {
showStatus = true
return
}
// Guard against PID reuse: the row was captured from an earlier
// snapshot. Re-resolve the live process and confirm it is still the
// same app (and still quittable) before terminating, so a recycled PID
// can never take down a different app.
guard let live = NSRunningApplication(processIdentifier: row.snapshot.pid),
live.bundleIdentifier == row.snapshot.bundleIdentifier,
ResourceHogsPolicy.canQuit(bundleIdentifier: live.bundleIdentifier) else {
statusMessage = L10n.tr(
"该进程已不再运行。",
"That process is no longer running.",
"Этот процесс больше не запущен."
)
showStatus = true
return
}
monitor.forceQuit(pid: row.snapshot.pid)
Task { await refresh() }
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/MacCleanKit/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,5 @@ public enum MCConstants {
// plugin was tried (commit history) but doesn't work under multi-arch
// `swift build --arch arm64 --arch x86_64` because xcbuild doesn't
// execute plugins.
public static let appVersion = "1.20.0"
public static let appVersion = "1.21.0"
}
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.20.0
1.21.0
Loading