From d90bf8529a6df69ad59d93b929d2b0d254c4c847 Mon Sep 17 00:00:00 2001 From: Si Beaumont Date: Fri, 6 May 2022 11:39:58 +0100 Subject: [PATCH] fixup: Move FileDescriptor.fileSize() to an internal extension in SystemTests --- Sources/System/FileHelpers.swift | 14 ----------- Tests/SystemTests/FileDescriptorExtras.swift | 25 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 Tests/SystemTests/FileDescriptorExtras.swift diff --git a/Sources/System/FileHelpers.swift b/Sources/System/FileHelpers.swift index 6f7885f..0825f83 100644 --- a/Sources/System/FileHelpers.swift +++ b/Sources/System/FileHelpers.swift @@ -122,18 +122,4 @@ extension FileDescriptor { return .success(buffer.count) } } - - /// Return the current size of the file. - /// - /// - Returns: The current size of the file, in bytes. - @_alwaysEmitIntoClient - @discardableResult - public func fileSize( - retryOnInterrupt: Bool = true - ) throws -> Int64 { - let current = try seek(offset: 0, from: .current) - let size = try seek(offset: 0, from: .end) - try seek(offset: current, from: .start) - return size - } } diff --git a/Tests/SystemTests/FileDescriptorExtras.swift b/Tests/SystemTests/FileDescriptorExtras.swift new file mode 100644 index 0000000..b72816f --- /dev/null +++ b/Tests/SystemTests/FileDescriptorExtras.swift @@ -0,0 +1,25 @@ +/* + This source file is part of the Swift System open source project + + Copyright (c) 2020 Apple Inc. and the Swift System project authors + Licensed under Apache License v2.0 with Runtime Library Exception + + See https://swift.org/LICENSE.txt for license information +*/ + +#if SYSTEM_PACKAGE +@testable import SystemPackage +#else +@testable import System +#endif + +extension FileDescriptor { + internal func fileSize( + retryOnInterrupt: Bool = true + ) throws -> Int64 { + let current = try seek(offset: 0, from: .current) + let size = try seek(offset: 0, from: .end) + try seek(offset: current, from: .start) + return size + } +}