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.

Read a read-only Spotlight index as an index

Țugui Dragoș48a2e066ebf6
diff --git a/Packages/PeelCore/Sources/PeelCore/Search/SpotlightIndex.swift b/Packages/PeelCore/Sources/PeelCore/Search/SpotlightIndex.swift
index 4b8c799f..d2b70ece 100644
--- a/Packages/PeelCore/Sources/PeelCore/Search/SpotlightIndex.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Search/SpotlightIndex.swift
@@ -11,7 +11,8 @@ enum SpotlightIndex {
/// What `mdutil -s` printed about a volume: indexed or not, or nil when it couldn't say.
static func isIndexing(mdutil output: String) -> Bool? {
- if output.contains("Indexing enabled.") { return true }
+ // A read-only index, on a full or read-only volume, still answers searches with what it holds.
+ if output.contains("Indexing enabled.") || output.contains("Index is read-only.") { return true }
if output.contains("Indexing disabled.") || output.contains("Indexing and searching disabled") { return false }
return nil
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SpotlightIndexTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SpotlightIndexTests.swift
index 929a784d..630e4a97 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/SpotlightIndexTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/SpotlightIndexTests.swift
@@ -5,6 +5,7 @@ import Testing
struct SpotlightIndexTests {
@Test func readsWhatMdutilPrints() {
#expect(SpotlightIndex.isIndexing(mdutil: "/:\n\tIndexing enabled. \n") == true)
+ #expect(SpotlightIndex.isIndexing(mdutil: "/System/Volumes/Data:\n\tIndex is read-only.\n") == true)
#expect(SpotlightIndex.isIndexing(mdutil: "/Volumes/Backup:\n\tIndexing disabled.\n") == false)
#expect(SpotlightIndex.isIndexing(mdutil: "/Volumes/Backup:\n\tIndexing and searching disabled.\n") == false)
let neverIndexed = "/Volumes/Backup:\n\tIndexing and searching disabled because of \".metadata_never_index\" "