Function finish [src]

On Windows, this function introduces a period of time where some file system operations on the destination file will result in error.AccessDenied, including rename operations (such as the one used in this function).

Prototype

pub fn finish(self: *AtomicFile) FinishError!void

Parameters

self: *AtomicFile

Possible Errors

AccessDenied RenameError

In WASI, this error may occur when the file descriptor does not hold the required rights to rename a resource by path relative to it.

On Windows, this error may be returned instead of PathAlreadyExists when renaming a directory over an existing directory.

AntivirusInterference RenameError

On Windows, antivirus software is enabled by default. It can be disabled, but Windows Update sometimes ignores the user's preference and re-enables it. When enabled, antivirus software on Windows intercepts file system operations and makes them significantly slower in addition to possibly failing with this error code.

BadPathName RenameError
DiskQuota RenameError
FileBusy RenameError
FileNotFound RenameError
InvalidUtf8 RenameError

WASI-only; file paths must be valid UTF-8.

InvalidWtf8 RenameError

Windows-only; file paths provided by the user must be valid WTF-8. https://simonsapin.github.io/wtf-8/

IsDir RenameError
LinkQuotaExceeded RenameError
NameTooLong RenameError
NetworkNotFound RenameError

On Windows, \\server or \\server\share was not found.

NoDevice RenameError
NoSpaceLeft RenameError
NotDir RenameError
PathAlreadyExists RenameError
PermissionDenied RenameError
PipeBusy RenameError
ReadOnlyFileSystem RenameError
RenameAcrossMountPoints RenameError
SharingViolation RenameError
SymLinkLoop RenameError
SystemResources RenameError
Unexpected UnexpectedError

The Operating System returned an undocumented error code.

This error is in theory not possible, but it would be better to handle this error than to invoke undefined behavior.

When this error code is observed, it usually means the Zig Standard Library needs a small patch to add the error code to the error set for the respective function.

Source

pub fn finish(self: *AtomicFile) FinishError!void { assert(self.file_exists); if (self.file_open) { self.file.close(); self.file_open = false; } try posix.renameat(self.dir.fd, self.tmp_path_buf[0..], self.dir.fd, self.dest_basename); self.file_exists = false; }