Skip to content

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.

Inside-itself check: resolved paths where a disk gives no file identity; exFAT test

og-orca903c2012f163
diff --git a/macos/Sources/RustyFiles/FileOps.swift b/macos/Sources/RustyFiles/FileOps.swift
index d0328f0e..ba2f9f5f 100644
--- a/macos/Sources/RustyFiles/FileOps.swift
+++ b/macos/Sources/RustyFiles/FileOps.swift
@@ -29,17 +29,22 @@ enum FileOps {
return url
}
- /// Whether `dir` is `src` or lies inside it. The paths are compared first, then the folders
- /// up from `dir` by file identity, so a link or other letter case on a disk that ignores
- /// case can't hide `src` (issue 759). A link as `src` is
- /// copied as a link, so it is compared by its own path only.
+ /// Whether `dir` is `src` or lies inside it. The folders up from `dir` (links resolved) are
+ /// compared with `src` by file identity, so a link or other letter case on a disk that
+ /// ignores case can't hide `src` (issue 759). Where the disk gives no identity, the resolved
+ /// paths are compared, without case when the disk ignores it. A link as `src` is copied as
+ /// a link, so it is compared by its own path only.
static func isInside(_ dir: URL, _ src: URL) -> Bool {
- let s = src.standardizedFileURL.path, d = dir.standardizedFileURL.path
- if d == s || d.hasPrefix(s + "/") { return true }
- let keys: Set<URLResourceKey> = [.fileResourceIdentifierKey, .isSymbolicLinkKey]
- guard let values = try? src.resourceValues(forKeys: keys), values.isSymbolicLink != true,
- let id = values.fileResourceIdentifier else { return false }
- var u = dir.resolvingSymlinksInPath()
+ func within(_ d: String, _ s: String) -> Bool { d == s || d.hasPrefix(s + "/") }
+ if within(dir.standardizedFileURL.path, src.standardizedFileURL.path) { return true }
+ let keys: Set<URLResourceKey> = [.fileResourceIdentifierKey, .isSymbolicLinkKey, .volumeSupportsCaseSensitiveNamesKey]
+ guard let values = try? src.resourceValues(forKeys: keys), values.isSymbolicLink != true else { return false }
+ let to = dir.resolvingSymlinksInPath()
+ guard let id = values.fileResourceIdentifier else {
+ let s = src.resolvingSymlinksInPath().path, d = to.path
+ return values.volumeSupportsCaseSensitiveNames == false ? within(d.lowercased(), s.lowercased()) : within(d, s)
+ }
+ var u = to
while true {
if let other = try? u.resourceValues(forKeys: [.fileResourceIdentifierKey]).fileResourceIdentifier,
other.isEqual(id) { return true }
diff --git a/macos/Sources/RustyFiles/SelfTest.swift b/macos/Sources/RustyFiles/SelfTest.swift
index 0953fafd..45e4390d 100644
--- a/macos/Sources/RustyFiles/SelfTest.swift
+++ b/macos/Sources/RustyFiles/SelfTest.swift
@@ -370,7 +370,27 @@ enum SelfTest {
let pasted = (try? FileOps.paste([toBox], into: sub, move: false))?.first
check(pasted.flatMap { try? fm.destinationOfSymbolicLink(atPath: $0.path) } != nil,
"a link to a folder pastes into that folder as a link")
- done()
+ // the same two ways in on exFAT, a disk without APFS's file identities of its own
+ let image = root.appendingPathComponent("inside.dmg"), volume = root.appendingPathComponent("inside")
+ guard hdiutil(["create", "-size", "8m", "-fs", "ExFAT", "-volname", "RFTEST3", image.path]),
+ hdiutil(["attach", "-nobrowse", "-mountpoint", volume.path, image.path]) else {
+ check(false, "a test exFAT image mounts")
+ return done()
+ }
+ let xbox = volume.appendingPathComponent("Box"), xsub = xbox.appendingPathComponent("sub")
+ let xlink = volume.appendingPathComponent("to-sub")
+ try? fm.createDirectory(at: xsub, withIntermediateDirectories: true)
+ fm.createFile(atPath: xbox.appendingPathComponent("f.txt").path, contents: Data("f".utf8))
+ try? fm.createSymbolicLink(at: xlink, withDestinationURL: xsub)
+ var xdone1 = false, xdone2 = false
+ Transfer(.copy, [xbox], into: xlink).start(window: nil) { _ in xdone1 = true }
+ Transfer(.copy, [xbox], into: volume.appendingPathComponent("box/sub")).start(window: nil) { _ in xdone2 = true }
+ DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
+ check(!xdone1 && !xdone2 && !fm.fileExists(atPath: xsub.appendingPathComponent("Box").path),
+ "on exFAT a copy into its own subfolder by a link or other letter case is refused")
+ _ = hdiutil(["detach", volume.path])
+ done()
+ }
}
}
}