Update FilePath references to NIOFilePath (#3333)

Motivation:

Currently, file paths are represented by the `SystemPackage.FilePath`
type in `NIOFileSystem`. Following from #3322, we want to use
`NIOFilePath` instead.

Modifications:

This change provides `NIOFilePath` accepting/returning variants to all
existing public methods that accept/return `SystemPackage.FilePath`.

The bulk of the changes are in `FileSystemProtocol` and
`FileHandleProtocol`, and their conforming types. The protocols have
been modified to require `NIOFilePath` accepting/returning methods.
Default implementations are provided for `SystemPackage.FilePath`
accepting/returning methods---these call through to the `NIOFilePath`
variants.

Result:

`NIOFilePath` path representations can now be used with the methods for
interacting with the file system.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
This commit is contained in:
aryan-25andGeorge Barnett authored and GitHub committed 2025-08-11 17:29:02 +01:00
1 parent b881f6ec60
commit 8997a24524
20 files changed
+1387 -191

No files matched your search

+22 -5
View File
@@ -2,7 +2,7 @@
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2023 Apple Inc. and the SwiftNIO project authors
// Copyright (c) 2025 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
@@ -19,7 +19,14 @@ public struct DirectoryEntry: Sendable, Hashable, Equatable {
/// The path of the directory entry.
///
/// - Precondition: The path must have at least one component.
public let path: FilePath
public let filePath: NIOFilePath
/// The path of the directory entry.
///
/// - Note: This property returns the underlying `SystemPackage.FilePath` instance of ``filePath``.
public var path: FilePath {
self.filePath.underlying
}
/// The name of the entry; the final component of the ``path``.
///
@@ -36,12 +43,22 @@ public struct DirectoryEntry: Sendable, Hashable, Equatable {
/// - Parameters:
/// - path: The path of the directory entry which must contain at least one component.
/// - type: The type of entry.
public init?(path: FilePath, type: FileType) {
if path.components.isEmpty {
public init?(path: NIOFilePath, type: FileType) {
if path.underlying.components.isEmpty {
return nil
}
self.path = path
self.filePath = path
self.type = type
}
/// Creates a directory entry; returns `nil` if `path` has no components.
///
/// - Parameters:
/// - path: The path of the directory entry which must contain at least one component.
/// - type: The type of entry.
@_disfavoredOverload
public init?(path: FilePath, type: FileType) {
self.init(path: .init(path), type: type)
}
}