Files
Stepan Ulyanin 182ae0b4f9 Add the replaceExisting to the _NIOFileSystem copyItem (#3535)
Adds the changes from https://github.com/apple/swift-nio/pull/3508 to
the `_NIOFileSystem`.
### Motivation:

We have added capability to overwrite regular files and symbolic links
to `NIOFS` `FileSystem.copyItem` in
https://github.com/apple/swift-nio/pull/3508. Now we want to port the
same logic to `_NIOFileSystem`.

### Modifications:

- Adds a new `FileSystemProtocol.copyItem` requirement with
`replaceExisting: bool` parameter along with a default implementation.
- Adds an implementation of the new `FileSystemProtocol.copyItem`
requirement to `_NIOFileSystem`'s `FileSystem` struct for regular files
and symbolic links.

### Notes

It seems that the tests for `FileSystem` are only in `NIOFS` - so no
tests are added in this PR.
2026-03-09 10:59:41 +00:00

48 lines
1.3 KiB
Markdown

# ``_NIOFileSystem/FileSystemProtocol``
## Topics
### Opening files with managed lifecycles
Files and directories can be opened and have their lifecycles managed by using the
following methods:
- ``withFileHandle(forReadingAt:options:execute:)``
- ``withFileHandle(forWritingAt:options:execute:)``
- ``withFileHandle(forReadingAndWritingAt:options:execute:)``
- ``withDirectoryHandle(atPath:options:execute:)``
### Opening files
Files and directories can be opened using the following methods. The caller is responsible for
closing it to avoid leaking resources.
- ``openFile(forReadingAt:)``
- ``openFile(forWritingAt:options:)``
- ``openFile(forReadingAndWritingAt:options:)``
- ``openDirectory(atPath:options:)``
### File information
- ``info(forFileAt:infoAboutSymbolicLink:)``
### Symbolic links
- ``createSymbolicLink(at:withDestination:)``
- ``destinationOfSymbolicLink(at:)``
### Managing files
- ``copyItem(at:to:strategy:shouldProceedAfterError:shouldCopyItem:)``
- ``copyItem(at:to:strategy:replaceExisting:shouldProceedAfterError:shouldCopyItem:)``
- ``removeItem(at:)``
- ``moveItem(at:to:)``
- ``replaceItem(at:withItemAt:)``
- ``createDirectory(at:withIntermediateDirectories:permissions:)``
### System directories
- ``currentWorkingDirectory``
- ``temporaryDirectory``
- ``withTemporaryDirectory(prefix:options:execute:)``