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.

Count a sync app's marker only while the app is on this Mac

Țugui Dragoșad9e2c25fea2
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index f5048c85..f78af756 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -234,10 +234,11 @@ A handful of ideas carry most of the weight. Each is enforced in one place and t
another app's container makes macOS ask for that app's data. A path is read name by name (`PathComponents`),
never as text, since a slash and a combining mark after it are one Swift `Character`. The guard also refuses
anything that syncs to other devices (`SyncedFolders`): what iCloud or a File Provider keeps, and what sits in a
- folder Syncthing, Resilio Sync, Synology Drive Client, MEGA, or Dropbox outside File Provider keeps in step, since
- the Trash would take it from those devices too. It looks a level or two inside a folder for a library, a wallet, or
- work kept only in a cache, and refuses a folder holding a folder macOS won't let Peel list, unless only the helper can
- move it, which looks inside as root (`ProtectedData.Finding`).
+ folder Syncthing, Resilio Sync, Synology Drive Client, MEGA, or Dropbox outside File Provider keeps in step while
+ that app is on this Mac (`SyncApp.isOnThisMac`), since the Trash would take it from those devices too. It looks a
+ level or two inside a folder for a library, a wallet, or work kept only in a cache, and refuses a folder holding a
+ folder macOS won't let Peel list, unless only the helper can move it, which looks inside as root
+ (`ProtectedData.Finding`).
- **Exclusions everywhere.** The user's exclusions reach every scanner, so an excluded item never appears (but an
excluded app's jobs, which Background Items lists marked and acts on none of, since that tab says what runs), and
a folder with something excluded inside is never moved, nor one Peel can't look into for an excluded app, since the
diff --git a/GUIDE.md b/GUIDE.md
index ff6101bc..519a5b37 100644
--- a/GUIDE.md
+++ b/GUIDE.md
@@ -147,8 +147,9 @@ Space shows what fills your disk, area by area, and what each area is.
what Desktop and Documents hold when they are in iCloud, is listed and never moved, since the Trash would take it
from your other devices too: beside a copy on this Mac it is marked Stays, and a group whose every copy syncs is
listed under Synced to Other Devices. When a sync app such as Syncthing keeps the folder in step, the copy's note
- names the app and the entry it keeps at that folder's root, such as `~/.stfolder`. A chosen folder Peel doesn't scan, such as a repository, is named with why, in
- Scan Settings and with the result.
+ names the app and the entry it keeps at that folder's root, such as `~/.stfolder`; an entry whose app isn't on this
+ Mac, such as one left after the app was removed or copied over with a folder, holds nothing back. A chosen folder
+ Peel doesn't scan, such as a repository, is named with why, in Scan Settings and with the result.
- **Installers and Backups:** disk images and packages in Downloads, Desktop, Documents, Public, and Shared, and in
the folders directly inside them, where installers are usually left, with archives there that hold an app or an
installer. It also lists the packages and the disk and system images an app keeps in Application Support, and the
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
index 340b7872..4c8d669c 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
@@ -1152,7 +1152,7 @@ public enum ProjectArtifacts {
next = 0
}
let answer = await SlowRead.answer(within: FileSize.budget) { _ in
- look(in: folder, exclusions: exclusions, listing: listing)
+ look(in: folder, exclusions: exclusions, keepers: keepers, listing: listing)
}
// A folder that went away during the walk held nothing; one still there and not read is not known.
guard let look = answer ?? nil else {
@@ -1317,10 +1317,12 @@ public enum ProjectArtifacts {
}
/// Lists `folder` and finds the artifacts in it, or nil when it cannot be listed.
- private static func look(in folder: URL, exclusions: Exclusions, listing: (URL) -> [URL]?) -> Look? {
+ private static func look(
+ in folder: URL, exclusions: Exclusions, keepers: SyncedFolders, listing: (URL) -> [URL]?
+ ) -> Look? {
guard let entries = listing(folder) else { return nil }
// What a folder another app keeps in step holds would go from the other devices too.
- guard !SyncedFolders.marksAFolder(entries) else { return Look(entries: [], found: [], isKeptInStep: true) }
+ guard !keepers.marksAFolder(entries) else { return Look(entries: [], found: [], isKeptInStep: true) }
let names = Set(entries.map(\.lastPathComponent))
var artifactNames: Set<String> = []
var found: [Found] = []
diff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/FolderDuplicates.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/FolderDuplicates.swift
index 7f7bc796..0b780380 100644
--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/FolderDuplicates.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/FolderDuplicates.swift
@@ -13,6 +13,7 @@ struct FolderDuplicates: Sendable {
private let managed: Set<String>
private let neverProjects: Set<String>
private let isDataless: @Sendable (URL) -> Bool
+ private let synced = SyncedFolders()
init(
managed: Set<String> = [],
@@ -186,7 +187,7 @@ struct FolderDuplicates: Sendable {
return folder
}
// What a folder another app keeps in step holds would go from the other devices too.
- guard !SyncedFolders.marksAFolder(contents.entries) else {
+ guard !synced.marksAFolder(contents.entries) else {
folder.isWhole = false
return folder
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/SyncedFolders.swift b/Packages/PeelCore/Sources/PeelCore/Support/SyncedFolders.swift
index d622f948..8948e74f 100644
--- a/Packages/PeelCore/Sources/PeelCore/Support/SyncedFolders.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Support/SyncedFolders.swift
@@ -61,13 +61,82 @@ public enum SyncApp: String, Sendable, Hashable, CaseIterable {
case .dropbox: ".dropbox.cache"
}
}
+
+ /// The identifiers of the app's bundles: those Homebrew's casks quit (`syncthing-app`, `resilio-sync`,
+ /// `synology-drive`, `megasync`, `dropbox`), Synctrain's (pixelspark/sushitrain) and MEGAcmd's (meganz/MEGAcmd).
+ var bundleIdentifiers: [String] {
+ switch self {
+ case .syncthing: ["com.github.xor-gate.syncthing-macosx", "nl.t-shaped.Sushitrain"]
+ case .resilioSync: ["com.resilio.Sync"]
+ case .synologyDrive: ["com.synology.CloudStation"]
+ case .mega: ["mega.mac", "megacmd.mac"]
+ case .dropbox: ["com.getdropbox.dropbox"]
+ }
+ }
+
+ /// The program that runs the app outside a bundle: Syncthing's, from Homebrew's formula or MacPorts' port.
+ var program: String? {
+ self == .syncthing ? "syncthing" : nil
+ }
+
+ /// Whether the app is on this Mac. Only the app keeps a folder in step, and its marker stays behind when it goes
+ /// and comes along when a folder is copied, so a marker counts only while the app is here.
+ @Sendable static func isOnThisMac(_ app: SyncApp) -> Bool {
+ isOnThisMac(bundleIdentifiers: app.bundleIdentifiers, program: app.program)
+ }
+
+ /// Whether macOS knows a bundle of one of `bundleIdentifiers` outside a Trash, or `program` is in the folders
+ /// Homebrew (on Apple silicon and on Intel) and MacPorts link programs into, or runs. A list of processes that
+ /// can't be read says the program may run.
+ static func isOnThisMac(
+ bundleIdentifiers: [String],
+ program: String?,
+ programFolders: [String] = ["/opt/homebrew/bin", "/usr/local/bin", "/opt/local/bin"]
+ ) -> Bool {
+ if bundleIdentifiers.contains(where: { !AppInspector.applicationURLs(forBundleIdentifier: $0).isEmpty }) {
+ return true
+ }
+ guard let program else { return false }
+ if programFolders.contains(where: { FileManager.default.isExecutableFile(atPath: $0 + "/" + program) }) {
+ return true
+ }
+ return runs(program) ?? true
+ }
+
+ /// Whether a process runs a program named `name`, or nil when the processes can't be listed.
+ private static func runs(_ name: String) -> Bool? {
+ var pids = [pid_t](repeating: 0, count: 8_192)
+ let count = Int(proc_listallpids(&pids, Int32(pids.count * MemoryLayout<pid_t>.size)))
+ guard count > 0 else { return nil }
+ return pids.prefix(count).contains { pid in
+ pid > 0 && RunningProgram.path(of: pid).map { URL(filePath: $0).lastPathComponent == name } == true
+ }
+ }
+
+ /// Whether each app is on this Mac, in place of this Mac's answer, for a test: no test can install a sync app.
+ @TaskLocal static var standIn: (@Sendable (SyncApp) -> Bool)?
}
/// What syncs to the person's other devices, where moving it to the Trash would remove it there too: what iCloud and
-/// File Provider keep (`isUbiquitousItem`), and what sits in a folder another app keeps in step, known by the entry
-/// the app writes at that folder's root. Each folder is asked once for the life of an instance.
+/// File Provider keep (`isUbiquitousItem`), and what sits in a folder another app on this Mac keeps in step, known by
+/// the entry the app writes at that folder's root. Each folder and each app are asked once for the life of an
+/// instance.
final class SyncedFolders: Sendable {
private let answers = Mutex<[String: SyncKeeper?]>([:])
+ private let lookUp: @Sendable (SyncApp) -> Bool
+ private let appsOnThisMac = Mutex<[SyncApp: Bool]>([:])
+
+ init() {
+ lookUp = SyncApp.standIn ?? SyncApp.isOnThisMac
+ }
+
+ /// Whether `app` is on this Mac, asked only once a marker of its own was found.
+ private func isOnThisMac(_ app: SyncApp) -> Bool {
+ if let known = appsOnThisMac.withLock({ $0[app] }) { return known }
+ let isHere = lookUp(app)
+ appsOnThisMac.withLock { $0[app] = isHere }
+ return isHere
+ }
func syncsToOtherDevices(_ url: URL) -> Bool {
keeper(of: url) != nil
@@ -81,14 +150,16 @@ final class SyncedFolders: Sendable {
return keeper(ofFolder: FileAccess.isARealFolder(url) ? names[...] : names.dropLast())
}
- /// Whether the folder whose entries are `entries` holds one of the markers, read from a listing already made.
- static func marksAFolder(_ entries: [URL]) -> Bool {
+ /// Whether the folder whose entries are `entries` holds the marker of an app on this Mac, read from a listing
+ /// already made.
+ func marksAFolder(_ entries: [URL]) -> Bool {
entries.contains { entry in
SyncApp.allCases.contains { app in
let parts = app.marker.split(separator: "/", maxSplits: 1).map(String.init)
guard entry.lastPathComponent == parts[0] else { return false }
var info = stat()
- return parts.count == 1 || lstat(entry.path(percentEncoded: false) + "/" + parts[1], &info) == 0
+ return (parts.count == 1 || lstat(entry.path(percentEncoded: false) + "/" + parts[1], &info) == 0)
+ && isOnThisMac(app)
}
}
}
@@ -99,7 +170,7 @@ final class SyncedFolders: Sendable {
let folder = "/" + names.joined(separator: "/")
if let known = answers.withLock({ $0[folder] }) { return known }
var info = stat()
- let keeper = SyncApp.allCases.first { lstat(folder + "/" + $0.marker, &info) == 0 }
+ let keeper = SyncApp.allCases.first { lstat(folder + "/" + $0.marker, &info) == 0 && isOnThisMac($0) }
.map { SyncKeeper.app($0, marker: URL(filePath: folder + "/" + $0.marker)) }
?? keeper(ofFolder: names.dropLast())
answers.withLock { $0[folder] = keeper }
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift
index 3654ef03..09246dad 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift
@@ -682,7 +682,7 @@ struct AttackRemovalGuardTests {
}
- @Test func whatAFolderASyncAppKeepsInStepHoldsStaysToo() throws {
+ @Test(.everySyncAppOnThisMac) func whatAFolderASyncAppKeepsInStepHoldsStaysToo() throws {
let directory = try TemporaryDirectory()
let home = directory.url.appending(path: "home", directoryHint: .isDirectory)
try directory.directory("home/Sync/.stfolder")
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
index da9654f8..640bc917 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
@@ -1062,7 +1062,7 @@ struct CommandLineTests {
#expect(UninstallPlan.make(kept, keepLeftovers: false, refusal: { _ in nil }).items.isEmpty)
}
- @Test func aDryRunWritesThePlanAndWhyWhenTheAppItselfWouldStay() async throws {
+ @Test(.everySyncAppOnThisMac) func aDryRunWritesThePlanAndWhyWhenTheAppItselfWouldStay() async throws {
let directory = try TemporaryDirectory()
_ = try directory.directory("Synced/.stfolder")
let info: [String: Any] = ["CFBundleIdentifier": "org.example.kept", "CFBundleName": "Kept"]
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift
index 4c9e4194..bf9f9a4f 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift
@@ -382,7 +382,7 @@ struct DuplicateFinderTests {
#expect(inside.groups.isEmpty, "a folder inside a repository was scanned")
}
- @Test func tellsACloudFromASyncApp() async throws {
+ @Test(.everySyncAppOnThisMac) func tellsACloudFromASyncApp() async throws {
let directory = try TemporaryDirectory()
let contents = randomData(count: 3_000)
try directory.directory("home/Synced/.stfolder")
@@ -404,7 +404,7 @@ struct DuplicateFinderTests {
#expect(copies["Documents"]?.syncsThroughACloud == false)
}
- @Test func countsOnlyTheGroupsWithSomethingToMove() async throws {
+ @Test(.everySyncAppOnThisMac) func countsOnlyTheGroupsWithSomethingToMove() async throws {
let directory = try TemporaryDirectory()
let synced = randomData(count: 3_000)
let local = randomData(count: 3_000)
@@ -423,7 +423,7 @@ struct DuplicateFinderTests {
/// A folder that syncs to other devices is scanned, and each copy found in it is listed and held back: a copy
/// moved there would be removed from every device. Nothing in such a group is suggested, since the one copy that
/// could move is the only one that stays on this Mac.
- @Test func listsACopyThatSyncsApartAndNeverSelectsIt() async throws {
+ @Test(.everySyncAppOnThisMac) func listsACopyThatSyncsApartAndNeverSelectsIt() async throws {
let directory = try TemporaryDirectory()
let contents = randomData(count: 3_000)
try directory.directory("home/Synced/.stfolder")
@@ -447,7 +447,7 @@ struct DuplicateFinderTests {
#expect(DuplicateScan.canChange(local, in: group, selected: []))
}
- @Test func aCopyInADropboxFolderOutsideFileProviderIsHeldBack() async throws {
+ @Test(.everySyncAppOnThisMac) func aCopyInADropboxFolderOutsideFileProviderIsHeldBack() async throws {
let directory = try TemporaryDirectory()
let contents = randomData(count: 3_000)
try directory.directory("home/Dropbox/.dropbox.cache")
@@ -462,7 +462,7 @@ struct DuplicateFinderTests {
}
/// A group whose every copy syncs is listed too, under its own heading in the app, with nothing to free.
- @Test func listsAGroupWhoseEveryCopySyncs() async throws {
+ @Test(.everySyncAppOnThisMac) func listsAGroupWhoseEveryCopySyncs() async throws {
let directory = try TemporaryDirectory()
let contents = randomData(count: 3_000)
try directory.directory("home/.stfolder")
@@ -483,6 +483,26 @@ struct DuplicateFinderTests {
#expect(group.files.map { $0.syncedBy?.resolved } == [syncthing.resolved, syncthing.resolved])
}
+ @Test func aMarkerLeftByASyncAppThatIsGoneHoldsNoCopyBack() async throws {
+ let directory = try TemporaryDirectory()
+ let contents = randomData(count: 3_000)
+ try directory.directory("home/.stfolder")
+ try directory.file("home/Documents/pdf/Chemistry/furnace.pdf", contents: contents)
+ try directory.file("home/Documents/Chemicals/books/furnace.pdf", contents: contents)
+ try directory.file("home/Documents/Chemicals/books/notes.txt")
+
+ let scan = try await SyncApp.$standIn.withValue({ _ in false }) {
+ try await scan(directory, folders: ["home/Documents"])
+ }
+ let group = try #require(scan.groups.first)
+
+ #expect(group.files.count == 2)
+ #expect(group.files.allSatisfy { $0.heldBack == nil && $0.syncedBy == nil })
+ #expect(!group.holdsASyncedCopy)
+ #expect(group.movableFiles.count == 2)
+ #expect(group.reclaimableSize == group.files[0].reclaimableSize)
+ }
+
/// A chosen folder that is not there, as a folder on a disk that isn't connected, is named rather than passed over.
@Test func namesAChosenFolderThatIsNotThere() async throws {
let directory = try TemporaryDirectory()
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
index 168b2c57..604c32fd 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
@@ -552,7 +552,7 @@ struct FileCommandTests {
/// A copy in a folder that syncs to other devices is listed as one that stays, and never moved; the JSON names
/// it apart from the copies that may move.
- @Test func listsACopyThatSyncsAsOneThatStays() async throws {
+ @Test(.everySyncAppOnThisMac) func listsACopyThatSyncsAsOneThatStays() async throws {
let directory = try TemporaryDirectory()
let logs = logs(in: directory)
let contents = Data((0..<4_000).map { _ in UInt8.random(in: 0...255) })
@@ -791,7 +791,7 @@ struct FileCommandTests {
})
}
- @Test func namesTheAppThatSyncsTheCopiesItLeavesAlone() async throws {
+ @Test(.everySyncAppOnThisMac) func namesTheAppThatSyncsTheCopiesItLeavesAlone() async throws {
let directory = try TemporaryDirectory()
let contents = Data((0..<3_000).map { _ in UInt8.random(in: 0...255) })
try directory.directory("home/.stfolder")
@@ -853,7 +853,7 @@ struct FileCommandTests {
#expect(message.contains("extensions: Peel doesn't look for projects in .editor or anything inside it, since apps and tools keep their own files in hidden folders"))
}
- @Test func saysThereIsNothingToMoveWhenEveryOtherCopySyncs() async throws {
+ @Test(.everySyncAppOnThisMac) func saysThereIsNothingToMoveWhenEveryOtherCopySyncs() async throws {
let directory = try TemporaryDirectory()
let logs = logs(in: directory)
let contents = Data((0..<4_000).map { _ in UInt8.random(in: 0...255) })
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileSearchTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileSearchTests.swift
index 08f0fbf1..481e106a 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/FileSearchTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileSearchTests.swift
@@ -342,7 +342,7 @@ struct FileSearchTests {
#expect(results.leftOut == [.syncs: 1])
}
- @Test func namesTheAppThatSyncsWhatItLeftOut() throws {
+ @Test(.everySyncAppOnThisMac) func namesTheAppThatSyncsWhatItLeftOut() throws {
let directory = try TemporaryDirectory()
let home = directory.url.appending(path: "home", directoryHint: .isDirectory)
try directory.file("home/Sync/.megaignore")
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FolderDuplicateTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FolderDuplicateTests.swift
index a3df0bbf..7eee5b53 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/FolderDuplicateTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/FolderDuplicateTests.swift
@@ -107,7 +107,7 @@ struct FolderDuplicateTests {
}
- @Test func offersNoFolderASyncAppKeepsInStep() async throws {
+ @Test(.everySyncAppOnThisMac) func offersNoFolderASyncAppKeepsInStep() async throws {
let directory = try TemporaryDirectory()
try trip(in: directory)
try directory.file("home/Pictures/.megaignore")
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
index 26c0d2ee..4821c541 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
@@ -394,7 +394,7 @@ struct InstallersTests {
}
- @Test func namesTheAppThatSyncsAnInstallerItLeavesAlone() async throws {
+ @Test(.everySyncAppOnThisMac) func namesTheAppThatSyncsAnInstallerItLeavesAlone() async throws {
let directory = try TemporaryDirectory()
try directory.file("Documents/.megaignore")
try directory.file("Documents/Tool-2.dmg", bytes: 400_000)
@@ -433,7 +433,7 @@ struct InstallersTests {
#expect(items.filter(\.canBeMoved).map(\.name) == ["Tool.dmg", "Old.iso"])
}
- @Test func anInstallerInAFolderASyncAppKeepsInStepCannotBeSelected() async throws {
+ @Test(.everySyncAppOnThisMac) func anInstallerInAFolderASyncAppKeepsInStepCannotBeSelected() async throws {
let directory = try TemporaryDirectory()
try directory.directory("Documents/.stfolder")
try directory.file("Documents/Tool-2.dmg", bytes: 400_000)
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
index 65cefff5..d6d5124a 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
@@ -1337,7 +1337,7 @@ struct LeftoverScannerTests {
}
- @Test func aLeftoverInAFolderASyncAppKeepsInStepCannotBeSelected() async throws {
+ @Test(.everySyncAppOnThisMac) func aLeftoverInAFolderASyncAppKeepsInStepCannotBeSelected() async throws {
let directory = try TemporaryDirectory()
try directory.file("home/Projects/.megaignore")
let synced = try directory.directory("home/Projects/Example")
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
index 2a459c9b..3846263f 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
@@ -1486,7 +1486,7 @@ struct ProjectArtifactsTests {
}
- @Test func leavesWhatASyncAppKeepsInStep() async throws {
+ @Test(.everySyncAppOnThisMac) func leavesWhatASyncAppKeepsInStep() async throws {
let directory = try TemporaryDirectory()
for project in ["Code/kept", "Code/synced", "Shared/app"] {
try directory.file("\(project)/package.json")
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SyncedFoldersTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SyncedFoldersTests.swift
index fc46a342..f8fe99f0 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/SyncedFoldersTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/SyncedFoldersTests.swift
@@ -3,7 +3,7 @@ import Foundation
import Testing
struct SyncedFoldersTests {
- @Test func knowsWhatEachSyncAppKeepsInStep() throws {
+ @Test(.everySyncAppOnThisMac) func knowsWhatEachSyncAppKeepsInStep() throws {
let directory = try TemporaryDirectory()
let roots = [
"Syncthing": ".stfolder/", "Resilio": ".sync/ID", "Synology": ".SynologyWorkingDirectory/", "MEGA": ".megaignore",
@@ -29,7 +29,7 @@ struct SyncedFoldersTests {
#expect(!synced.syncsToOtherDevices(directory.url.appending(path: "home/Plain/Projects/notes.txt")))
}
- @Test func namesTheAppThatKeepsAFolderInStepAndItsMarker() throws {
+ @Test(.everySyncAppOnThisMac) func namesTheAppThatKeepsAFolderInStepAndItsMarker() throws {
let directory = try TemporaryDirectory()
try directory.directory("home/.stfolder")
try directory.file("home/Documents/notes.txt")
@@ -52,6 +52,47 @@ struct SyncedFoldersTests {
#expect(synced.keeper(of: directory.url.appending(path: "notes.txt")) == nil)
}
+ @Test func aMarkerCountsOnlyWhileItsAppIsOnThisMac() throws {
+ let directory = try TemporaryDirectory()
+ try directory.directory("home/.stfolder")
+ try directory.file("home/Music/.megaignore")
+ let notes = try directory.file("home/Documents/notes.txt")
+ let set = try directory.file("home/Music/Live/set.txt")
+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)
+
+ SyncApp.$standIn.withValue({ $0 == .mega }) {
+ let synced = SyncedFolders()
+ #expect(synced.keeper(of: notes) == nil)
+ #expect(synced.keeper(of: set) == .app(.mega, marker: home.appending(path: "Music/.megaignore")))
+ #expect(!synced.marksAFolder([home.appending(path: ".stfolder"), notes]))
+ #expect(synced.marksAFolder([home.appending(path: "Music/.megaignore"), set]))
+ }
+ }
+
+ @Test func findsASyncAppWhereTheMacKeepsIt() throws {
+ let directory = try TemporaryDirectory()
+ let name = "org-example-sync-\(UUID().uuidString)"
+ let folder = PathPattern.comparablePath(of: try directory.directory("bin"))
+
+ #expect(SyncApp.isOnThisMac(bundleIdentifiers: ["com.apple.TextEdit"], program: nil))
+ #expect(!SyncApp.isOnThisMac(bundleIdentifiers: ["org.example.sync"], program: nil))
+ #expect(!SyncApp.isOnThisMac(bundleIdentifiers: [], program: name, programFolders: [folder]))
+ let program = try directory.file("bin/\(name)")
+ try FileManager.default.setAttributes(
+ [.posixPermissions: 0o755], ofItemAtPath: program.path(percentEncoded: false)
+ )
+ #expect(SyncApp.isOnThisMac(bundleIdentifiers: [], program: name, programFolders: [folder]))
+ }
+
+ @Test func findsASyncAppByTheProgramThatRuns() throws {
+ let directory = try TemporaryDirectory()
+ let name = "org-example-sync-\(UUID().uuidString.prefix(8))"
+ let process = try directory.runningProgram("Elsewhere/\(name)")
+ defer { process.terminate() }
+
+ #expect(SyncApp.isOnThisMac(bundleIdentifiers: [], program: name, programFolders: []))
+ }
+
@Test func aRefusalLogReadsBackTheAppAndItsMarker() {
let keeper = SyncKeeper.app(.dropbox, marker: URL(filePath: "/Users/me/Dropbox/.dropbox.cache"))
@@ -69,7 +110,7 @@ struct SyncedFoldersTests {
#expect(!SyncedFolders().syncsToOtherDevices(notes))
}
- @Test func readsAFolderAsSyncedFromItsListingAlone() throws {
+ @Test(.everySyncAppOnThisMac) func readsAFolderAsSyncedFromItsListingAlone() throws {
let directory = try TemporaryDirectory()
try directory.file("Resilio/.sync/ID")
try directory.file("Tool/.sync/settings.json")
@@ -79,13 +120,27 @@ struct SyncedFoldersTests {
)
}
- #expect(SyncedFolders.marksAFolder(try listing("Resilio")))
- #expect(!SyncedFolders.marksAFolder(try listing("Tool")))
- #expect(SyncedFolders.marksAFolder([URL(filePath: "/Sync/.stfolder"), URL(filePath: "/Sync/notes.txt")]))
- #expect(!SyncedFolders.marksAFolder([URL(filePath: "/Sync/notes.txt")]))
+ let synced = SyncedFolders()
+ #expect(synced.marksAFolder(try listing("Resilio")))
+ #expect(!synced.marksAFolder(try listing("Tool")))
+ #expect(synced.marksAFolder([URL(filePath: "/Sync/.stfolder"), URL(filePath: "/Sync/notes.txt")]))
+ #expect(!synced.marksAFolder([URL(filePath: "/Sync/notes.txt")]))
+ }
+}
+
+/// Counts every sync app as on this Mac for the test it marks, since no test can install one.
+struct EverySyncAppOnThisMac: TestTrait, TestScoping {
+ func provideScope(
+ for test: Test, testCase: Test.Case?, performing function: @concurrent @Sendable () async throws -> Void
+ ) async throws {
+ try await SyncApp.$standIn.withValue({ _ in true }) { try await function() }
}
}
+extension Trait where Self == EverySyncAppOnThisMac {
+ static var everySyncAppOnThisMac: Self { Self() }
+}
+
extension SyncKeeper {
/// The keeper with its marker's links resolved, since a folder's listing names `/var` as `/private/var`.
var resolved: SyncKeeper {
diff --git a/SAFETY.md b/SAFETY.md
index c29d2917..31299a80 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -84,11 +84,13 @@ level or two down: see [Crypto wallets](#crypto-wallets).
Anything that syncs to your other devices stays too, wherever it is: what iCloud or another cloud service keeps, such as
what is on your Desktop and in Documents when they are in iCloud Drive, and what is in a folder Syncthing, Resilio Sync,
Synology Drive Client, MEGA, or Dropbox outside File Provider keeps in step, known by the entry each writes at that
-folder's root (`.stfolder`, `.sync/ID`, `.SynologyWorkingDirectory`, `.megaignore`, `.dropbox.cache`). The Trash would
-take it from your other devices too. Its row says so, File Search doesn't list it and says how many such files it left
-out, and Duplicates lists such a copy marked Stays, never selected and never moved. Where an app's entry is the reason,
-Peel names the app and the entry's path, in the app and from `peel`, so an entry left behind by an app you no longer
-use, or copied over with a folder, can be found.
+folder's root (`.stfolder`, `.sync/ID`, `.SynologyWorkingDirectory`, `.megaignore`, `.dropbox.cache`) while that app is
+on this Mac: macOS knows it, or Syncthing's program is where Homebrew or MacPorts put it, or runs. Only the app keeps
+the folder in step, and its entry stays behind when the app goes and comes along when a folder is copied, so an entry
+whose app isn't here counts for nothing. The Trash would take it from your other devices too. Its row says so, File
+Search doesn't list it and says how many such files it left out, and Duplicates lists such a copy marked Stays, never
+selected and never moved. Where an app's entry is the reason, Peel names the app and the entry's path, in the app and
+from `peel`.
Also refused: work that an app keeps inside a *cache* folder and nowhere else. A JetBrains IDE and Android Studio keep a
history of your changes in `LocalHistory`, beside their caches, which no repository may hold, Deno keeps `localStorage`