Skip to content

Commit

Permalink
Symlink support
Browse files Browse the repository at this point in the history
  • Loading branch information
NSAntoine committed Sep 13, 2022
1 parent f12045d commit d29740a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
16 changes: 10 additions & 6 deletions Santander/Other/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ extension URL {
}

var contents: [URL] {
let _contents = try? FileManager.default.contentsOfDirectory(at: self, includingPropertiesForKeys: [])
let _contents = try? FileManager.default.contentsOfDirectory(at: self.resolvedURL, includingPropertiesForKeys: [])
return _contents ?? []
}

var isDirectory: Bool {
let resolvedURL = URL(fileURLWithPath: self.realPath ?? self.path)
return (try? resolvedURL.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory ?? false
return (try? resolvedURL.resourceValues(forKeys: [.isDirectoryKey]).isDirectory) ?? false
}

var creationDate: Date? {
Expand Down Expand Up @@ -69,9 +68,14 @@ extension URL {
return FileManager.default.displayName(atPath: self.path)
}

/// The path, resolved if a symbolic link
var realPath: String? {
return try? FileManager.default.destinationOfSymbolicLink(atPath: self.path)
/// The URL, resolved if a symbolic link
var resolvedURL: URL {
if let realPath = try? FileManager.default.destinationOfSymbolicLink(atPath: self.path),
let resolved = URL(string: realPath, relativeTo: deletingLastPathComponent()) {
return resolved
}

return self
}

static var root: URL = URL(fileURLWithPath: "/")
Expand Down
7 changes: 3 additions & 4 deletions Santander/UI/Path/PathInformationTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@ class PathInformationTableViewController: UITableViewController {
conf.secondaryText = showDisplayName ? self.path.displayName : self.path.lastPathComponent
case (0, 1):
conf.text = showRealPath ? "Real Path" : "Path"
let pathString: String = showRealPath ? (self.path.realPath ?? "N/A") : self.path.path
if pathString == "N/A" {
conf.secondaryText = "N/A"
if showRealPath {
conf.secondaryText = path.resolvedURL.path
} else {
conf.secondaryText = URL(fileURLWithPath: pathString).path
conf.secondaryText = self.path.path
}

case (0, 2):
Expand Down
24 changes: 10 additions & 14 deletions Santander/UI/Path/SubPathsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -552,16 +552,11 @@ class SubPathsTableViewController: UITableViewController {
}

/// Returns the cell row to be used to display a path
func pathCellRow(forURL fsItem: URL, displayFullPathAsSubtitle: Bool = false) -> UITableViewCell {
let cell: UITableViewCell

// If we should display the full path as a subtitle, init with the style as `subtitle`
if displayFullPathAsSubtitle {
cell = UITableViewCell(style: .subtitle, reuseIdentifier: nil)
} else {
cell = UITableViewCell()
}

func pathCellRow(
forURL fsItem: URL,
displayFullPathAsSubtitle useSubtitle: Bool = false
) -> UITableViewCell {
let cell = UITableViewCell(style: useSubtitle ? .subtitle : .default, reuseIdentifier: nil)
var cellConf = cell.defaultContentConfiguration()
defer {
cell.contentConfiguration = cellConf
Expand All @@ -581,17 +576,18 @@ class SubPathsTableViewController: UITableViewController {
return cell
}

cellConf.text = fsItem.lastPathComponent
let pathName = fsItem.lastPathComponent
cellConf.text = pathName

// if the item starts is a dotfile / dotdirectory
// if the item name starts is a dotfile / dotdirectory
// ie, .conf or .zshrc,
// display the label as gray
if fsItem.lastPathComponent.first == "." {
if pathName.first == "." {
cellConf.textProperties.color = .gray
cellConf.secondaryTextProperties.color = .gray
}

if displayFullPathAsSubtitle {
if useSubtitle {
cellConf.secondaryText = fsItem.path // Display full path as the subtitle text if we should
}

Expand Down

0 comments on commit d29740a

Please sign in to comment.