Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Leave TypeScript's .mts files out of Movies
Țugui Dragoș3d2aa29d19b4
diff --git a/Packages/PeelCore/Sources/PeelCore/Search/FileSearch.swift b/Packages/PeelCore/Sources/PeelCore/Search/FileSearch.swiftindex 8532ceec..7cab5b29 100644--- a/Packages/PeelCore/Sources/PeelCore/Search/FileSearch.swift+++ b/Packages/PeelCore/Sources/PeelCore/Search/FileSearch.swift@@ -279,9 +279,9 @@ public enum FileSearch {return .leftOut(syncKeeper(url) != nil ? .syncs : LeftOut(refused))}- /// macOS gives TypeScript's `.ts` the type of an MPEG-2 transport stream, a movie, so such a file is one only when- /// it begins as one: packets that each start with the byte 0x47, every 188 bytes, or every 192 after the 4-byte- /// header Blu-ray adds (ISO/IEC 13818-1).+ /// macOS gives TypeScript's `.ts` and `.mts` the type of an MPEG-2 transport stream, a movie, so such a file is one+ /// only when it begins as one: packets that each start with the byte 0x47, every 188 bytes, or every 192 after the+ /// 4-byte header Blu-ray adds (ISO/IEC 13818-1).static func isAMovie(_ url: URL) -> Bool {guard isTypedAsATransportStream(url) else { return true }guard let bytes = BoundedRead.prefix(of: url, count: 197).map(Array.init) else { return false }@@ -292,7 +292,7 @@ public enum FileSearch {}static func isTypedAsATransportStream(_ url: URL) -> Bool {- UTType(filenameExtension: url.pathExtension) == .mpeg2TransportStream+ UTType(filenameExtension: url.pathExtension)?.conforms(to: .mpeg2TransportStream) == true}/// Whether a file's contents are on this Mac. One whose contents live only in the cloud (`SF_DATALESS`) freesdiff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileSearchTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileSearchTests.swiftindex c8dac6c4..66f80839 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/FileSearchTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileSearchTests.swift@@ -187,6 +187,23 @@ struct FileSearchTests {#expect(Set(anything.files.map(\.url.lastPathComponent)) == ["index.ts", "clip.ts", "recording.ts"])}+ @Test func moviesLeaveOutTypeScriptModulesMacOSTypesAsAnAVCHDStream() throws {+ let directory = try TemporaryDirectory()+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)+ let module = try directory.file("home/Projects/app/lib.mts", contents: Data("export const answer = 42\n".utf8))+ let types = try directory.file("home/Projects/app/index.d.mts", contents: Data("export {}\n".utf8))+ var packets = [UInt8](repeating: 0xFF, count: 192 * 3)+ for start in stride(from: 4, to: packets.count, by: 192) { packets[start] = 0x47 }+ let camera = try directory.file("home/Movies/00001.mts", contents: Data(packets))+ let blueRay = try directory.file("home/Movies/00002.m2ts", contents: Data(packets))+ let paths = [module, types, camera, blueRay].map { $0.path(percentEncoded: false) }+ let environment = SearchEnvironment(homeDirectory: home, rootDirectory: directory.url)++ let movies = FileSearch.results(from: paths, kind: .movies, environment: environment, refusal: { _ in nil })++ #expect(Set(movies.files.map(\.url.lastPathComponent)) == ["00001.mts", "00002.m2ts"])+ }+@Test func neverListsAFileThatSyncsToTheCloud() throws {let directory = try TemporaryDirectory()let home = directory.url.appending(path: "home", directoryHint: .isDirectory)