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 atsourcePath
does not exist,invalidArgument
if an item atdestinationPath
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
associatedtype DirectoryFileHandle
The type of
DirectoryFileHandleProtocol
to return when opening directories.associatedtype ReadFileHandle
The type of
ReadableFileHandleProtocol
to return when opening files for reading.associatedtype ReadWriteFileHandle
The type of
ReadableAndWritableFileHandleProtocol
to return when opening files for reading and writing.associatedtype WriteFileHandle
The type of
WritableFileHandleProtocol
to return when opening files for writing.
Instance members
var currentWorkingDirectory: FilePath
Returns the current working directory.
var temporaryDirectory: FilePath
Returns the path of the temporary directory.
func createDirectory(at: FilePath, withIntermediateDirectories: Bool, permissions: FilePermissions?
) async throws Create a directory at the given path.
func createSymbolicLink(at: FilePath, withDestination: FilePath
) async throws Creates a symbolic link that points to the destination.
func createTemporaryDirectory(template: FilePath
) async throws -> FilePath Create a temporary directory at the given path, from a template.
func destinationOfSymbolicLink(at: FilePath
) async throws -> FilePath Returns the path of the item pointed to by a symbolic link.
func info(forFileAt: FilePath, infoAboutSymbolicLink: Bool
) async throws -> FileInfo? Returns information about the file at the given path, if it exists; nil otherwise.
func moveItem(at: FilePath, to: FilePath
) async throws Moves the file or directory at the specified path to a new location.
func openDirectory(atPath: FilePath, options: OpenOptions.Directory
) async throws -> DirectoryFileHandle Opens the directory at
path
and returns a handle to it.func openFile(forReadingAndWritingAt: FilePath, options: OpenOptions.Write
) async throws -> ReadWriteFileHandle Opens the file at
path
for reading and writing and returns a handle to it.func openFile(forReadingAt: FilePath, options: OpenOptions.Read
) async throws -> ReadFileHandle Opens the file at
path
for reading and returns a handle to it.func openFile(forWritingAt: FilePath, options: OpenOptions.Write
) async throws -> WriteFileHandle Opens the file at
path
for writing and returns a handle to it.func removeItem(at: FilePath, recursively: Bool
) async throws -> Int Deletes the file or directory (and its contents) at
path
.func replaceItem(at: FilePath, withItemAt: FilePath
) async throws Replaces the item at
destinationPath
with the item atexistingPath
.