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.

File Search leaves files in iCloud Drive for the person

Țugui Dragoșca3f1d2b770e
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 67167f05..7c1cb4ef 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -115989,6 +115989,112 @@
}
}
},
+ "This file is in iCloud Drive, so moving it to the Trash removes it from iCloud and from your other devices." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tento soubor je na iCloud Drivu, takže přesunutím do koše ho odstraníte z iCloudu i z vašich ostatních zařízení."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Diese Datei liegt in iCloud Drive, daher wird sie aus iCloud und von deinen anderen Geräten entfernt, wenn du sie in den Papierkorb legst."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Este archivo está en iCloud Drive, así que trasladarlo a la papelera lo elimina de iCloud y de tus otros dispositivos."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ce fichier se trouve dans iCloud Drive : le placer dans la corbeille le supprime donc d’iCloud et de vos autres appareils."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Questo file si trova su iCloud Drive, quindi, se lo sposti nel Cestino, viene rimosso da iCloud e dagli altri tuoi dispositivi."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "このファイルはiCloud Driveにあるため、ゴミ箱に入れると、iCloudからも、ほかのデバイスからも削除されます。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "이 파일은 iCloud Drive에 있으므로 휴지통으로 이동하면 iCloud는 물론 다른 기기에서도 삭제됩니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dit bestand staat op iCloud Drive, dus als je het naar de prullenmand verplaatst, verdwijnt het uit iCloud en van je andere apparaten."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ten plik jest na iCloud Drive, więc po przeniesieniu do Kosza zostanie usunięty z iCloud i z Twoich pozostałych urządzeń."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Este arquivo está no iCloud Drive, então, se você o mover para o Lixo, ele será removido do iCloud e dos seus outros dispositivos."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Acest fișier se află pe iCloud Drive, așa că mutarea lui în Coș îl elimină de pe iCloud și de pe celelalte dispozitive ale dvs."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Этот файл находится в iCloud Drive, поэтому, если переместить его в Корзину, он будет удален из iCloud и с других Ваших устройств."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Den här filen ligger i iCloud Drive, så om du flyttar den till papperskorgen tas den bort från iCloud och från dina andra enheter."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bu dosya, iCloud Drive’da olduğu için Çöp Sepeti’ne taşınırsa iCloud’dan ve diğer aygıtlarınızdan silinir."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Цей файл зберігається в iCloud Drive, тож переміщення в Смітник прибирає його з iCloud і з інших ваших пристроїв."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "此文件位于iCloud云盘中,因此将它移到废纸篓后,它会从iCloud和你的其他设备中删除。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "此檔案位於「iCloud雲碟」中,因此丟到「垃圾桶」會將它從iCloud和你的其他裝置上移除。"
+ }
+ }
+ }
+ },
"This frees %@. Nothing is deleted from iCloud: the files stay there, Finder still lists them, and they download again when you open them." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift
index 22d10e7e..f474710e 100644
--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift
@@ -34,7 +34,7 @@ public struct DuplicateFinder: Sendable {
public func canScan(_ folder: URL) -> Bool {
let path = Self.path(of: folder.resolvingSymlinksInPath())
let home = Self.path(of: homeDirectory)
- guard !ProtectedData.refuses(path, home: home), !Self.isInTheCloud(folder), !Self.isInsideAPackage(folder) else { return false }
+ guard !ProtectedData.refuses(path, home: home), !folder.isInTheCloud, !Self.isInsideAPackage(folder) else { return false }
if path.isInside(home) {
return !Self.managedFolders.contains { path.isInside(home + "/" + $0) }
}
@@ -44,13 +44,6 @@ public struct DuplicateFinder: Sendable {
return (try? folder.resourceValues(forKeys: [.volumeIsReadOnlyKey]).volumeIsReadOnly) != true
}
- /// Whether `url` is stored in the cloud, as `isUbiquitousItem` reports. With Desktop and Documents in iCloud,
- /// their files are cloud items even though their paths are in the home folder, and removing one removes it
- /// from every device.
- static func isInTheCloud(_ url: URL) -> Bool {
- (try? url.resourceValues(forKeys: [.isUbiquitousItemKey]).isUbiquitousItem) == true
- }
-
/// Whether `url` is a package, such as an app.
static func isAPackage(_ url: URL) -> Bool {
(try? url.resourceValues(forKeys: [.isPackageKey]).isPackage) == true
@@ -205,7 +198,7 @@ public struct DuplicateFinder: Sendable {
}
continue
}
- guard !exclusions.excludes(url), removalGuard.allowsRemoval(of: url), !Self.isInTheCloud(url) else { continue }
+ guard !exclusions.excludes(url), removalGuard.allowsRemoval(of: url), !url.isInTheCloud else { continue }
var info = stat()
guard
values.isRegularFile == true,
diff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/FolderDuplicates.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/FolderDuplicates.swift
index adbc4610..4faff183 100644
--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/FolderDuplicates.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/FolderDuplicates.swift
@@ -176,7 +176,7 @@ struct FolderDuplicates: Sendable {
folder.isWhole = folder.isWhole && child.isWhole
folder.children.append((entry.lastPathComponent, child))
case S_IFREG:
- guard info.st_flags & UInt32(SF_DATALESS) == 0, !DuplicateFinder.isInTheCloud(entry) else {
+ guard info.st_flags & UInt32(SF_DATALESS) == 0, !entry.isInTheCloud else {
folder.isWhole = false
continue
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Search/FileSearch.swift b/Packages/PeelCore/Sources/PeelCore/Search/FileSearch.swift
index fde7b493..53989d52 100644
--- a/Packages/PeelCore/Sources/PeelCore/Search/FileSearch.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Search/FileSearch.swift
@@ -37,6 +37,9 @@ public struct FoundFile: Sendable, Hashable, Identifiable {
/// True when the file sits in a Library folder, so it is an app's working data rather than something the user
/// made. Such a file is listed last and never selected for the user.
public var belongsToAnApp = false
+ /// True when the file is in iCloud Drive, as Desktop and Documents are when they sync: moving it to the Trash
+ /// removes it from every device. It is never selected for the user.
+ public var isInTheCloud = false
/// The file's identity when it was listed. Results can stay on screen for a long time, and a file written
/// again under the same name is not the one the row describes.
public var identity: FileIdentity?
@@ -103,14 +106,15 @@ public enum FileSearch {
from paths: [String],
environment: SearchEnvironment = .current,
exclusions: Exclusions = .none,
- allows: ((URL) -> Bool)? = nil
+ allows: ((URL) -> Bool)? = nil,
+ isInTheCloud: (URL) -> Bool = { $0.isInTheCloud }
) -> FileSearchResults {
let allows = allows ?? RemovalGuard(environment: environment, exclusions: exclusions).allowsRemoval(of:)
var candidates: [(url: URL, info: stat, belongsToAnApp: Bool)] = []
for path in paths {
guard !Task.isCancelled else { return FileSearchResults(didRun: false) }
var info = stat()
- guard lstat(path, &info) == 0, info.st_mode & S_IFMT == S_IFREG else { continue }
+ guard lstat(path, &info) == 0, info.st_mode & S_IFMT == S_IFREG, holdsItsContentsHere(info) else { continue }
let url = URL(filePath: path)
candidates.append((url, info, isAppData(url, home: environment.homeDirectory)))
}
@@ -134,12 +138,19 @@ public enum FileSearch {
modificationDate: Date(timeIntervalSince1970: TimeInterval(candidate.info.st_mtimespec.tv_sec)),
requiresPrivileges: FileAccess.requiresPrivilegesToRemove(candidate.url),
belongsToAnApp: candidate.belongsToAnApp,
+ isInTheCloud: isInTheCloud(candidate.url),
identity: FileIdentity(candidate.info)
))
}
return results
}
+ /// Whether a file's contents are on this Mac. One whose contents live only in the cloud (`SF_DATALESS`) frees
+ /// nothing here when moved.
+ static func holdsItsContentsHere(_ info: stat) -> Bool {
+ info.st_flags & UInt32(SF_DATALESS) == 0
+ }
+
/// Returns whether `url` is inside the Library folder in `home`, `/Library`, or `/System/Library`, where apps
/// keep the data they work with.
static func isAppData(_ url: URL, home: URL) -> Bool {
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/RealFolder.swift b/Packages/PeelCore/Sources/PeelCore/Support/RealFolder.swift
index 5341ade9..2bbdf640 100644
--- a/Packages/PeelCore/Sources/PeelCore/Support/RealFolder.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Support/RealFolder.swift
@@ -13,4 +13,11 @@ extension URL {
let values = try? resourceValues(forKeys: [.isDirectoryKey, .isSymbolicLinkKey])
return values?.isDirectory == true && values?.isSymbolicLink != true
}
+
+ /// Whether the item is stored in the cloud, as `isUbiquitousItem` reports. With Desktop and Documents in iCloud,
+ /// their files are cloud items even though their paths are in the home folder, and removing one removes it
+ /// from every device.
+ var isInTheCloud: Bool {
+ (try? resourceValues(forKeys: [.isUbiquitousItemKey]).isUbiquitousItem) == true
+ }
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileSearchTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileSearchTests.swift
index 849927a8..e23f87b8 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/FileSearchTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileSearchTests.swift
@@ -123,6 +123,34 @@ struct FileSearchTests {
#expect(!results.isTruncated)
}
+ /// A file in iCloud Drive, as Desktop and Documents are when they sync, is listed with that said: moving it to
+ /// the Trash removes it from every device. A temporary folder holds no iCloud item, so which file is one is
+ /// given here, as macOS would answer.
+ @Test func saysWhichFilesAreInTheCloud() throws {
+ let directory = try TemporaryDirectory()
+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)
+ let synced = try directory.file("home/Documents/Report.pdf", bytes: 9_000)
+ let local = try directory.file("home/Downloads/Setup.dmg", bytes: 1_000)
+
+ let results = FileSearch.results(
+ from: [synced, local].map { $0.path(percentEncoded: false) },
+ environment: SearchEnvironment(homeDirectory: home, rootDirectory: directory.url),
+ isInTheCloud: { $0.lastPathComponent == "Report.pdf" }
+ )
+
+ #expect(results.files.map { "\($0.url.lastPathComponent): \($0.isInTheCloud)" } == ["Report.pdf: true", "Setup.dmg: false"])
+ }
+
+ /// A file whose contents live only in the cloud (`SF_DATALESS`) takes no room on this Mac, so moving it frees
+ /// nothing here and removes it everywhere. It is never listed.
+ @Test func aFileOnlyInTheCloudIsNeverListed() {
+ var info = stat()
+ info.st_mode = S_IFREG
+ #expect(FileSearch.holdsItsContentsHere(info))
+ info.st_flags = UInt32(SF_DATALESS)
+ #expect(!FileSearch.holdsItsContentsHere(info))
+ }
+
/// `MDQuery.h` promises no order, so the results are sorted before the cap applies. Cutting first would keep
/// an arbitrary set of files and call them the largest. The guard allows every file here, since the order is
/// what is checked; `listsOnlyRegularFilesOutsideProtectedLocations` asks the real one.
diff --git a/Peel/Model/FileSearchLibrary.swift b/Peel/Model/FileSearchLibrary.swift
index 66f0ec96..03341e4a 100644
--- a/Peel/Model/FileSearchLibrary.swift
+++ b/Peel/Model/FileSearchLibrary.swift
@@ -51,7 +51,7 @@ final class FileSearchLibrary {
}
results = found
filteredBy = exclusions
- selectableURLs = Set(found.files.filter { !$0.requiresPrivileges && !$0.belongsToAnApp }.map(\.url))
+ selectableURLs = Set(found.files.filter { !$0.requiresPrivileges && !$0.belongsToAnApp && !$0.isInTheCloud }.map(\.url))
sizes = Dictionary(found.files.map { ($0.url, $0.size) }, uniquingKeysWith: { first, _ in first })
selectedURLs.formIntersection(found.files.filter { !$0.requiresPrivileges }.map(\.url))
// The search ran under the exclusions as they were when it started, so leave out anything excluded since.
diff --git a/Peel/Views/FileSearch/FileSearchFileView.swift b/Peel/Views/FileSearch/FileSearchFileView.swift
index e57f1228..1de41b58 100644
--- a/Peel/Views/FileSearch/FileSearchFileView.swift
+++ b/Peel/Views/FileSearch/FileSearchFileView.swift
@@ -35,6 +35,11 @@ struct FileSearchFileView: View {
LabeledContent("Modified") {
Text(file.modificationDate, format: .relative(presentation: .named))
}
+ if file.isInTheCloud {
+ Text("This file is in iCloud Drive, so moving it to the Trash removes it from iCloud and from your other devices.")
+ .font(.callout)
+ .foregroundStyle(.secondary)
+ }
if file.belongsToAnApp {
Text("An app keeps this in its Library folder, and may be using it right now.")
.font(.callout)
diff --git a/Peel/Views/FileSearch/FileSearchList.swift b/Peel/Views/FileSearch/FileSearchList.swift
index 21c3f6d6..725e4bde 100644
--- a/Peel/Views/FileSearch/FileSearchList.swift
+++ b/Peel/Views/FileSearch/FileSearchList.swift
@@ -27,7 +27,9 @@ struct FileSearchList: View {
url: file.url,
icon: .file(file.url),
detail: "Modified \(file.modificationDate, format: .relative(presentation: .named))",
- warning: file.belongsToAnApp
+ warning: file.isInTheCloud
+ ? String(localized: "This file is in iCloud Drive, so moving it to the Trash removes it from iCloud and from your other devices.")
+ : file.belongsToAnApp
? String(localized: "An app keeps this in its Library folder, and may be using it right now.")
: nil,
size: file.size,