mirror of
https://github.com/apple/swift-nio
synced 2026-11-28 05:14:23 +00:00
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:
1 parent
b881f6ec60
commit
8997a24524
20 files changed
+1387
-191
No files matched your search
@@ -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
|
||||
@@ -308,12 +308,13 @@ final class FileHandleTests: XCTestCase {
|
||||
try await FileSystem.shared.removeItem(at: privateTempDirPath, recursively: true)
|
||||
}
|
||||
|
||||
guard mkfifo(privateTempDirPath.appending("fifo").string, 0o644) == 0 else {
|
||||
let fifoPath = FilePath(privateTempDirPath).appending("fifo")
|
||||
guard mkfifo(fifoPath.string, 0o644) == 0 else {
|
||||
XCTFail("Error calling mkfifo.")
|
||||
return
|
||||
}
|
||||
|
||||
try await self.withHandle(forFileAtPath: privateTempDirPath.appending("fifo"), accessMode: .readWrite) {
|
||||
try await self.withHandle(forFileAtPath: fifoPath, accessMode: .readWrite) {
|
||||
handle in
|
||||
let someBytes = ByteBuffer(repeating: 42, count: 1546)
|
||||
try await handle.write(contentsOf: someBytes.readableBytesView, toAbsoluteOffset: 0)
|
||||
@@ -329,12 +330,13 @@ final class FileHandleTests: XCTestCase {
|
||||
try await FileSystem.shared.removeItem(at: privateTempDirPath, recursively: true)
|
||||
}
|
||||
|
||||
guard mkfifo(privateTempDirPath.appending("fifo").string, 0o644) == 0 else {
|
||||
let fifoPath = FilePath(privateTempDirPath).appending("fifo")
|
||||
guard mkfifo(fifoPath.string, 0o644) == 0 else {
|
||||
XCTFail("Error calling mkfifo.")
|
||||
return
|
||||
}
|
||||
|
||||
try await self.withHandle(forFileAtPath: privateTempDirPath.appending("fifo"), accessMode: .readWrite) {
|
||||
try await self.withHandle(forFileAtPath: fifoPath, accessMode: .readWrite) {
|
||||
handle in
|
||||
let someBytes = [UInt8](repeating: 42, count: 10)
|
||||
try await handle.write(contentsOf: someBytes, toAbsoluteOffset: 0)
|
||||
@@ -353,12 +355,13 @@ final class FileHandleTests: XCTestCase {
|
||||
try await FileSystem.shared.removeItem(at: privateTempDirPath, recursively: true)
|
||||
}
|
||||
|
||||
guard mkfifo(privateTempDirPath.appending("fifo").string, 0o644) == 0 else {
|
||||
let fifoPath = FilePath(privateTempDirPath).appending("fifo")
|
||||
guard mkfifo(fifoPath.string, 0o644) == 0 else {
|
||||
XCTFail("Error calling mkfifo.")
|
||||
return
|
||||
}
|
||||
|
||||
try await self.withHandle(forFileAtPath: privateTempDirPath.appending("fifo"), accessMode: .readWrite) {
|
||||
try await self.withHandle(forFileAtPath: fifoPath, accessMode: .readWrite) {
|
||||
handle in
|
||||
let someBytes = [UInt8](repeating: 42, count: 1546)
|
||||
|
||||
@@ -998,7 +1001,7 @@ final class FileHandleTests: XCTestCase {
|
||||
// Takes the path where 'O_TMPFILE' doesn't exist, so materializing the file is done via
|
||||
// creating a temporary file and then renaming it using 'renamex_np'/'renameat2' (Darwin/Linux).
|
||||
let temporaryDirectory = try await FileSystem.shared.temporaryDirectory
|
||||
let path = temporaryDirectory.appending(Self.temporaryFileName().components)
|
||||
let path = FilePath(temporaryDirectory).appending(Self.temporaryFileName().components)
|
||||
let handle = try SystemFileHandle.syncOpenWithMaterialization(
|
||||
atPath: path,
|
||||
mode: .writeOnly,
|
||||
@@ -1020,7 +1023,7 @@ final class FileHandleTests: XCTestCase {
|
||||
// fallback path where 'renameat2' returns EINVAL so the 'rename' is used in combination
|
||||
// with 'stat'. This path is only reachable on Linux.
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
let temporaryDirectory = try await FileSystem.shared.temporaryDirectory
|
||||
let temporaryDirectory = FilePath(try await FileSystem.shared.temporaryDirectory)
|
||||
let path = temporaryDirectory.appending(Self.temporaryFileName().components)
|
||||
let handle = try SystemFileHandle.syncOpenWithMaterialization(
|
||||
atPath: path,
|
||||
|
||||
@@ -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
|
||||
@@ -35,7 +35,7 @@ extension FileSystem {
|
||||
inTemporaryDirectory: Bool = true
|
||||
) async throws -> FilePath {
|
||||
if inTemporaryDirectory {
|
||||
let directory = try await self.temporaryDirectory
|
||||
let directory = (try await self.temporaryDirectory).underlying
|
||||
return self.temporaryFilePath(function, inDirectory: directory)
|
||||
} else {
|
||||
return self.temporaryFilePath(function, inDirectory: nil)
|
||||
@@ -505,14 +505,14 @@ final class FileSystemTests: XCTestCase {
|
||||
|
||||
func testCurrentWorkingDirectory() async throws {
|
||||
let directory = try await self.fs.currentWorkingDirectory
|
||||
XCTAssert(!directory.isEmpty)
|
||||
XCTAssert(directory.isAbsolute)
|
||||
XCTAssert(!directory.underlying.isEmpty)
|
||||
XCTAssert(directory.underlying.isAbsolute)
|
||||
}
|
||||
|
||||
func testTemporaryDirectory() async throws {
|
||||
let directory = try await self.fs.temporaryDirectory
|
||||
XCTAssert(!directory.isEmpty)
|
||||
XCTAssert(directory.isAbsolute)
|
||||
XCTAssert(!directory.underlying.isEmpty)
|
||||
XCTAssert(directory.underlying.isAbsolute)
|
||||
}
|
||||
|
||||
func testInfo() async throws {
|
||||
@@ -1318,7 +1318,7 @@ final class FileSystemTests: XCTestCase {
|
||||
|
||||
let createdPath = try await fs.withTemporaryDirectory { directory, path in
|
||||
let root = try await fs.temporaryDirectory
|
||||
XCTAssert(path.starts(with: root))
|
||||
XCTAssert(path.starts(with: root.underlying))
|
||||
return path
|
||||
}
|
||||
|
||||
@@ -1329,7 +1329,7 @@ final class FileSystemTests: XCTestCase {
|
||||
|
||||
func testWithTemporaryDirectoryPrefix() async throws {
|
||||
let fs = FileSystem.shared
|
||||
let prefix = try await fs.currentWorkingDirectory
|
||||
let prefix = (try await fs.currentWorkingDirectory).underlying
|
||||
|
||||
let createdPath = try await fs.withTemporaryDirectory(prefix: prefix) { directory, path in
|
||||
XCTAssert(path.starts(with: prefix))
|
||||
@@ -1685,7 +1685,7 @@ extension FileSystemTests {
|
||||
if let envTmpDir = getenv("TMPDIR") {
|
||||
let envTmpDirString = String(cString: envTmpDir)
|
||||
let fsTempDirectory = try await fs.temporaryDirectory
|
||||
XCTAssertEqual(fsTempDirectory, FilePath(envTmpDirString))
|
||||
XCTAssertEqual(fsTempDirectory.underlying, FilePath(envTmpDirString))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user