Skip to content

Commit

Permalink
mark several FileSystem APIs as disfavored overloads
Browse files Browse the repository at this point in the history
motivation: help the transition off of TSC Path and FileSystem

changes:
* mark several FileSystem APIs that return AbsolutePath as disfavored overloads
* deprecate Product which is really a SwiftPM construct
  • Loading branch information
tomerd committed May 2, 2023
1 parent 78e53cb commit ff2e82c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/TSCBasic/FileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public enum FileMode: Sendable {
/// - Note: All of these APIs are synchronous and can block.
public protocol FileSystem: Sendable {
/// Check whether the given path exists and is accessible.
@_disfavoredOverload
func exists(_ path: AbsolutePath, followSymlink: Bool) -> Bool

/// Check whether the given path is accessible and a directory.
Expand Down Expand Up @@ -183,6 +184,7 @@ public protocol FileSystem: Sendable {
/// The current working directory can be empty if e.g. the directory became
/// unavailable while the current process was still working in it.
/// This follows the POSIX `getcwd(3)` semantics.
@_disfavoredOverload
var currentWorkingDirectory: AbsolutePath? { get }

/// Change the current working directory.
Expand All @@ -191,12 +193,15 @@ public protocol FileSystem: Sendable {
func changeCurrentWorkingDirectory(to path: AbsolutePath) throws

/// Get the home directory of current user
@_disfavoredOverload
var homeDirectory: AbsolutePath { get throws }

/// Get the caches directory of current user
@_disfavoredOverload
var cachesDirectory: AbsolutePath? { get }

/// Get the temp directory
@_disfavoredOverload
var tempDirectory: AbsolutePath { get throws }

/// Create the given directory.
Expand All @@ -219,16 +224,19 @@ public protocol FileSystem: Sendable {
/// Get the contents of a file.
///
/// - Returns: The file contents as bytes, or nil if missing.
@_disfavoredOverload
func readFileContents(_ path: AbsolutePath) throws -> ByteString

// FIXME: This is obviously not a very efficient or flexible API.
//
/// Write the contents of a file.
@_disfavoredOverload
func writeFileContents(_ path: AbsolutePath, bytes: ByteString) throws

// FIXME: This is obviously not a very efficient or flexible API.
//
/// Write the contents of a file.
@_disfavoredOverload
func writeFileContents(_ path: AbsolutePath, bytes: ByteString, atomically: Bool) throws

/// Recursively deletes the file system entity at `path`.
Expand Down Expand Up @@ -259,6 +267,7 @@ public protocol FileSystem: Sendable {
/// methods).
public extension FileSystem {
/// exists override with default value.
@_disfavoredOverload
func exists(_ path: AbsolutePath) -> Bool {
return exists(path, followSymlink: true)
}
Expand All @@ -275,6 +284,7 @@ public extension FileSystem {

// Unless the file system type provides an override for this method, throw
// if `atomically` is `true`, otherwise fall back to whatever implementation already exists.
@_disfavoredOverload
func writeFileContents(_ path: AbsolutePath, bytes: ByteString, atomically: Bool) throws {
guard !atomically else {
throw FileSystemError(.unsupported, path)
Expand All @@ -283,6 +293,7 @@ public extension FileSystem {
}

/// Write to a file from a stream producer.
@_disfavoredOverload
func writeFileContents(_ path: AbsolutePath, body: (WritableByteStream) -> Void) throws {
let contents = BufferedOutputByteStream()
body(contents)
Expand Down
3 changes: 3 additions & 0 deletions Sources/TSCTestSupport/Product.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import TSCUtility
import class Foundation.Bundle
#endif

@available(*, deprecated, message: "moved to SwiftPM")
public enum SwiftPMProductError: Swift.Error {
case packagePathNotFound
case executionFailure(error: Swift.Error, output: String, stderr: String)
Expand All @@ -26,10 +27,12 @@ public enum SwiftPMProductError: Swift.Error {
/// Defines the executables used by SwiftPM.
/// Contains path to the currently built executable and
/// helper method to execute them.
@available(*, deprecated, message: "moved to SwiftPM")
public protocol Product {
var exec: RelativePath { get }
}

@available(*, deprecated, message: "moved to SwiftPM")
extension Product {
/// Path to currently built binary.
public var path: AbsolutePath {
Expand Down

0 comments on commit ff2e82c

Please sign in to comment.