File operations v0.1.0
DeleteFile
pub func DeleteFile(
allocator: Allocator,
path: Path
) -> ! IoError
Deletes the file path names. Removing the name does not disturb any handle still open on the file.
Parameters
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
path | Path | the path to act on |
Returns: success when the file is gone
Rename
pub func Rename(
allocator: Allocator,
from: Path,
to: Path
) -> ! IoError
Renames from to to, moving it between directories if the paths differ there.
An existing to is replaced, atomically within one volume: a reader sees the old file or the new, never a
gap. Across volumes Windows copies and deletes instead — not atomic — and the Unix systems refuse.
Parameters
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
from | Path | the path that exists now |
to | Path | the path it should have afterwards |
Returns: success when the file is at its new path
CreateHardLink
pub func CreateHardLink(
allocator: Allocator,
existing: Path,
link: Path
) -> ! IoError
Creates link as a hard link: a second name for the file existing names.
The two names are then equals — neither is "the original" — and the content lives until the last name is
deleted. A symbolic link at existing is not followed: the link is made to the name given. Directories
cannot be hard-linked on any supported system.
Parameters
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
existing | Path | the file that exists now |
link | Path | the link to create |
Returns: success when the new name refers to the same file
CreateSymbolicLink
pub func CreateSymbolicLink(
allocator: Allocator,
target: Path,
link: Path,
targetIsDirectory: bool
) -> ! IoError
Creates link as a symbolic link holding target as its text.
The target is stored, not checked: a dangling link is created as readily as a good one. targetIsDirectory
matters only on Windows, which types its links; the Unix systems ignore it. Windows also gates creation
behind a privilege unless the machine runs Developer Mode, so PermissionDenied here is an environment, not
a bug.
Parameters
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
target | Path | the path the link will point at, which need not exist |
link | Path | the link to create |
targetIsDirectory | bool | whether the target is a directory, which Windows must be told in advance |
Returns: success when the link was created; Windows needs a privilege for this
CopyFile
pub func CopyFile(
allocator: Allocator,
from: Path,
to: Path
) -> ! IoError
Copies the file from names to to, following a symbolic link to the bytes it points at.
An existing to is replaced. The copy is the bytes and nothing else: permissions, timestamps and the rest of
the metadata are the destination's own, fresh — carrying them is a policy the metadata work owns.
Parameters
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
from | Path | the path that exists now |
to | Path | the path it should have afterwards |
Returns: success when the destination holds a copy