Movatterモバイル変換


[0]ホーム

URL:


std

Modulefs

1.0.0 ·Source
Expand description

Filesystem manipulation operations.

This module contains basic methods to manipulate the contents of the localfilesystem. All methods in this module represent cross-platform filesystemoperations. Extra platform-specific functionality can be found in theextension traits ofstd::os::$platform.

§Time of Check to Time of Use (TOCTOU)

Many filesystem operations are subject to a race condition known as “Time of Check to Time of Use”(TOCTOU). This occurs when a program checks a condition (like file existence or permissions)and then uses the result of that check to make a decision, but the condition may have changedbetween the check and the use.

For example, checking if a file exists and then creating it if it doesn’t is vulnerable toTOCTOU - another process could create the file between your check and creation attempt.

Another example is with symbolic links: when removing a directory, if another process replacesthe directory with a symbolic link between the check and the removal operation, the removalmight affect the wrong location. This is why operations likeremove_dir_all need to useatomic operations to prevent such race conditions.

To avoid TOCTOU issues:

  • Be aware that metadata operations (likemetadata orsymlink_metadata) may be affected bychanges made by other processes.
  • Use atomic operations when possible (likeFile::create_new instead of checking existence then creating).
  • Keep file open for the duration of operations.

Structs§

DirBuilder
A builder used to create directories in various manners.
DirEntry
Entries returned by theReadDir iterator.
File
An object providing access to an open file on the filesystem.
FileTimes
Representation of the various timestamps on a file.
FileType
A structure representing a type of file with accessors for each file type.It is returned byMetadata::file_type method.
Metadata
Metadata information about a file.
OpenOptions
Options and flags which can be used to configure how a file is opened.
Permissions
Representation of the various permissions on a file.
ReadDir
Iterator over the entries in a directory.

Enums§

TryLockError
An enumeration of possible errors which can occur while trying to acquire a lockfrom thetry_lock method andtry_lock_shared method on aFile.

Functions§

canonicalize
Returns the canonical, absolute form of a path with all intermediatecomponents normalized and symbolic links resolved.
copy
Copies the contents of one file to another. This function will alsocopy the permission bits of the original file to the destination file.
create_dir
Creates a new, empty directory at the provided path
create_dir_all
Recursively create a directory and all of its parent components if theyare missing.
exists
ReturnsOk(true) if the path points at an existing entity.
hard_link
Creates a new hard link on the filesystem.
metadata
Given a path, queries the file system to get information about a file,directory, etc.
read
Reads the entire contents of a file into a bytes vector.
read_dir
Returns an iterator over the entries within a directory.
read_link
Reads a symbolic link, returning the file that the link points to.
read_to_string
Reads the entire contents of a file into a string.
remove_dir
Removes an empty directory.
remove_dir_all
Removes a directory at this path, after removing all its contents. Usecarefully!
remove_file
Removes a file from the filesystem.
rename
Renames a file or directory to a new name, replacing the original file ifto already exists.
set_permissions
Changes the permissions found on a file or a directory.
soft_linkDeprecated
Creates a new symbolic link on the filesystem.
symlink_metadata
Queries the metadata about a file without following symlinks.
write
Writes a slice as the entire contents of a file.

[8]ページ先頭

©2009-2025 Movatter.jp