Skip to content

Commit

Permalink
Add readChildren() function to FileNode
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Aug 25, 2024
1 parent e816593 commit e71ca21
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions CotEditor/Sources/FileNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,18 @@ struct FileNode: Equatable {
self.isWritable = resourceValues.isWritable ?? true
self.fileURL = fileURL

guard self.isDirectory, self.kind != .gitDirectory else { return }
self.children = try self.readChildren()
}


/// Reads the contents of the directory at the receiver's `fileURL`.
///
/// - Returns: The child nodes, or `nil` if the receiver is not a directory.
private func readChildren() throws -> [FileNode]? {

guard self.isDirectory, self.kind != .gitDirectory else { return nil }

self.children = try FileManager.default
return try FileManager.default
.contentsOfDirectory(at: fileURL, includingPropertiesForKeys: [.isDirectoryKey, .isWritableKey])
.map { try FileNode(at: $0, paths: paths + [self.name]) }
.sorted(using: SortDescriptor(\.name, comparator: .localizedStandard))
Expand Down

0 comments on commit e71ca21

Please sign in to comment.