Required Instance Methodswift-nio 2.72.0_NIOFileSystem

    copyItem(at:to:strategy:shouldProceedAfterError:shouldCopyItem:)

    Copies the item at the specified path to a new location.

    FileSystemProtocol.swift:232
    iOS
    13.0+
    macOS
    10.15+
    tvOS
    13.0+
    watchOS
    6.0+
    func copyItem(at sourcePath: FilePath, to destinationPath: FilePath, strategy copyStrategy: CopyStrategy, shouldProceedAfterError: @escaping (_ source: DirectoryEntry, _ error: Error) async throws -> Void, shouldCopyItem: @escaping (_ source: DirectoryEntry, _ destination: FilePath) async -> Bool) async throws

    Parameters

    sourcePath

    The path to the item to copy.

    destinationPath

    The path at which to place the copy.

    strategy

    How to deal with concurrent aspects of the copy, only relevant to directories.

    shouldProceedAfterError

    A closure which is executed to determine whether to continue copying files if an error is encountered during the operation. See Errors section for full details.

    shouldCopyItem

    A closure which is executed before each copy to determine whether each item should be copied. See Filtering section for full details

    The following error codes may be thrown:

    • notFound if the item at sourcePath does not exist,

    • invalidArgument if an item at destinationPath exists prior to the copy or its parent directory does not exist.

    Note that other errors may also be thrown.

    If sourcePath is a symbolic link then only the link is copied. The copied file will preserve permissions and any extended attributes (if supported by the file system).

    Errors

    No errors should be throw by implementors without first calling shouldProceedAfterError, if that returns without throwing this is taken as permission to continue and the error is swallowed. If instead the closure throws then copyItem(at:to:strategy:shouldProceedAfterError:shouldCopyItem:) will throw and copying will stop, though the precise semantics of this can depend on the strategy.

    if using parallel(maxDescriptors:) Already started work may continue for an indefinite period of time. In particular, after throwing an error it is possible that invocations of shouldCopyItem may continue to occur!

    If using sequential only one invocation of any of the should* closures will occur at a time, and an error will immediately stop further activity.

    The specific error thrown from copyItem is undefined, it does not have to be the same error thrown from shouldProceedAfterError. In the event of any errors (ignored or otherwise) implementations are under no obbligation to attempt to ‘tidy up’ after themselves. The state of the file system within destinationPath after an aborted copy should is undefined.

    When calling shouldProceedAfterError implementations of this method MUST:

    • Do so once and only once per item.

    • Not hold any locks when doing so. MAY:

    • invoke the function multiple times concurrently (except when using sequential)

    Filtering

    When invoking shouldCopyItem implementations of this method MUST:

    • Do so once and only once per item.

    • Do so before attempting any operations related to the copy (including determining if they can do so).

    • Not hold any locks when doing so.

    • Check parent directories before items within them,

      • if a parent is ignored no items within it should be considered or checked

    • Skip all contents of a directory which is filtered out.

    • Invoke it for the sourcePath itself. MAY:

    • invoke the function multiple times concurrently (except when using sequential)

    • invoke the function an arbitrary point before actually trying to copy the file

    Other requirements

    Type members

    Instance members