File operations v0.1.0

Source
Deleting, renaming, copying and linking files by name.

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.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
pathPaththe 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.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
fromPaththe path that exists now
toPaththe path it should have afterwards

Returns: success when the file is at its new path

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.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
existingPaththe file that exists now
linkPaththe link to create

Returns: success when the new name refers to the same file

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.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
targetPaththe path the link will point at, which need not exist
linkPaththe link to create
targetIsDirectoryboolwhether 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.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the storage comes from
fromPaththe path that exists now
toPaththe path it should have afterwards

Returns: success when the destination holds a copy