A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.
Rust archive-managerdesktop-appdual-paneexplorer-alternativefile-browserfile-explorerfile-managerfluent-designgpu-acceleratedgpuimacosmicaproductivityquick-lookrustrust-guitabswindowswindows-11windows-explorer
Mac: "Programs using it" with Option or Shift held
gelenmedyab79b262811d3
diff --git a/macos/Sources/RustyFiles/FileListController.swift b/macos/Sources/RustyFiles/FileListController.swiftindex bae02fe7..468989b2 100644--- a/macos/Sources/RustyFiles/FileListController.swift+++ b/macos/Sources/RustyFiles/FileListController.swift@@ -1807,6 +1807,11 @@ final class FileListController: NSObject, NSTableViewDataSource, NSTableViewDeleb.add(String(localized: "Bulk rename…"), "pencil-line", key: String(Character(UnicodeScalar(NSF2FunctionKey)!)), mods: []) { [weak self] in self?.bulkRename() }}b.add(String(localized: "Copy item path"), "clipboard-copy", key: "c", mods: [.command, .option]) { MenuActions.copyPaths(urls) }+ // the commands seldom needed come with ⌥ or ⇧ held, as Windows' extended ones with Shift+ if archive == nil, !NSEvent.modifierFlags.intersection([.option, .shift]).isEmpty {+ b.add(String(localized: "Programs using it"), "lock") { [weak self] in Lockers.show(urls, window: self?.card.window) }+ b.add(String(localized: "Delete Immediately…"), "eraser") { [weak self] in self?.deleteImmediately(urls) }+ }if archive == nil { b.add(String(localized: "Add to shelf"), "archive-restore", key: "s", mods: [.command, .shift]) { [weak self] in self?.addToShelf() } }b.add(String(localized: "Make alias"), "link") { [weak self] inself?.run { try urls.map { try FileOps.makeAlias($0) } } done: { made indiff --git a/macos/Sources/RustyFiles/Lockers.swift b/macos/Sources/RustyFiles/Lockers.swiftnew file mode 100644index 00000000..7a822df9--- /dev/null+++ b/macos/Sources/RustyFiles/Lockers.swift@@ -0,0 +1,66 @@+import AppKit++/// "Programs using it" (Windows' lockers, the reason a delete or a move says another program+/// uses a file): the processes that have the items open, or work in a folder, from lsof. GUI+/// apps among them can be asked to quit.+enum Lockers {+ struct Holder: Hashable, Sendable {+ let pid: Int32+ let name: String+ }++ /// The processes holding `urls` open (a folder: its own files and processes working in it).+ nonisolated static func holders(_ urls: [URL]) -> [Holder] {+ var args = ["-F", "pc", "-w"]+ for u in urls {+ var dir: ObjCBool = false+ if FileManager.default.fileExists(atPath: u.path, isDirectory: &dir), dir.boolValue {+ args += ["+d", u.path]+ } else {+ args += ["--", u.path]+ }+ }+ let p = Process()+ p.executableURL = URL(fileURLWithPath: "/usr/sbin/lsof")+ p.arguments = args+ let out = Pipe()+ p.standardOutput = out+ p.standardError = FileHandle.nullDevice+ guard (try? p.run()) != nil else { return [] }+ let data = out.fileHandleForReading.readDataToEndOfFile()+ p.waitUntilExit()+ var found: [Holder] = []+ var pid: Int32?+ for line in String(decoding: data, as: UTF8.self).split(separator: "\n") {+ if line.hasPrefix("p") { pid = Int32(line.dropFirst()) }+ if line.hasPrefix("c"), let pid, pid != getpid() {+ let app = NSRunningApplication(processIdentifier: pid)?.localizedName+ found.append(Holder(pid: pid, name: app ?? String(line.dropFirst())))+ }+ }+ return Array(Set(found)).sorted { $0.name.localizedStandardCompare($1.name) == .orderedAscending }+ }++ @MainActor+ static func show(_ urls: [URL], window: NSWindow?) {+ Task.detached(priority: .userInitiated) {+ let found = holders(urls)+ await MainActor.run {+ let alert = NSAlert()+ let what = urls.count == 1 ? "“\(urls[0].lastPathComponent)”" : String(localized: "\(urls.count) items")+ if found.isEmpty {+ alert.messageText = String(localized: "No program is using \(what)")+ alert.informativeText = String(localized: "Nothing has it open right now.")+ alert.runModal()+ return+ }+ alert.messageText = String(localized: "Programs using \(what)")+ alert.informativeText = found.map { "\($0.name) (\($0.pid))" }.joined(separator: "\n")+ let apps = found.compactMap { NSRunningApplication(processIdentifier: $0.pid) }.filter { $0.activationPolicy == .regular }+ alert.addButton(withTitle: String(localized: "OK"))+ if !apps.isEmpty { alert.addButton(withTitle: String(localized: "Quit the apps")) }+ if alert.runModal() == .alertSecondButtonReturn { apps.forEach { $0.terminate() } }+ }+ }+ }+}diff --git a/macos/Sources/RustyFiles/SelfTest.swift b/macos/Sources/RustyFiles/SelfTest.swiftindex 1ead787e..63618758 100644--- a/macos/Sources/RustyFiles/SelfTest.swift+++ b/macos/Sources/RustyFiles/SelfTest.swift@@ -65,6 +65,16 @@ enum SelfTest {let tq = { (q: String) in TagQuery.eval(TagQuery.parse(TagQuery.expression(q) ?? ""), with: { tagged[$0] ?? [] }, all: { ["/a", "/b", "/c"] }) }check(tq("tag:red AND work") == ["/b"] && tq("tag:red OR work NOT done") == ["/a", "/b"] && tq("etiket:değil done") == ["/a", "/b"],"tag searches with AND, OR and NOT read left to right")+ let held = root.appendingPathComponent("held.txt")+ try? "x".write(to: held, atomically: true, encoding: .utf8)+ let holder = Process()+ holder.executableURL = URL(fileURLWithPath: "/usr/bin/tail")+ holder.arguments = ["-f", held.path]+ holder.standardOutput = FileHandle.nullDevice+ try? holder.run()+ Thread.sleep(forTimeInterval: 0.3)+ check(Lockers.holders([held]).contains { $0.pid == holder.processIdentifier }, "\"Programs using it\" finds a program that has the file open")+ holder.terminate()// 0. the Git look-up ends at the disk's root and finds a repository from inside it (issue 429)check(GitRepo.repoRoot(URL(fileURLWithPath: "/")) == nil, "no repository above the root")