uvw 3.1.0
Loading...
Searching...
No Matches
Public Member Functions | List of all members
uvw::fs_req Class Referencefinal

The fs request. More...

#include <fs.h>

Inheritance diagram for uvw::fs_req:
Inheritance graph
[legend]
Collaboration diagram for uvw::fs_req:
Collaboration graph
[legend]

Public Member Functions

void unlink (const std::string &path)
 Async unlink.
 
bool unlink_sync (const std::string &path)
 Sync unlink.
 
void mkdir (const std::string &path, int mode)
 Async mkdir.
 
bool mkdir_sync (const std::string &path, int mode)
 Sync mkdir.
 
void mkdtemp (const std::string &tpl)
 Async mktemp.
 
std::pair< bool, const char * > mkdtemp_sync (const std::string &tpl)
 Sync mktemp.
 
void mkstemp (const std::string &tpl)
 Async mkstemp.
 
std::pair< bool, std::pair< std::string, std::size_t > > mkstemp_sync (const std::string &tpl)
 Sync mkstemp.
 
void lutime (const std::string &path, time atime, time mtime)
 Async lutime.
 
bool lutime_sync (const std::string &path, time atime, time mtime)
 Sync lutime.
 
void rmdir (const std::string &path)
 Async rmdir.
 
bool rmdir_sync (const std::string &path)
 Sync rmdir.
 
void scandir (const std::string &path, int flags)
 Async scandir.
 
std::pair< bool, std::size_t > scandir_sync (const std::string &path, int flags)
 Sync scandir.
 
std::pair< bool, std::pair< entry_type, const char * > > scandir_next ()
 Gets entries populated with the next directory entry data.
 
void stat (const std::string &path)
 Async stat.
 
std::pair< bool, file_infostat_sync (const std::string &path)
 Sync stat.
 
void lstat (const std::string &path)
 Async lstat.
 
std::pair< bool, file_infolstat_sync (const std::string &path)
 Sync lstat.
 
void statfs (const std::string &path)
 Async statfs.
 
std::pair< bool, fs_infostatfs_sync (const std::string &path)
 Sync statfs.
 
void rename (const std::string &old, const std::string &path)
 Async rename.
 
bool rename_sync (const std::string &old, const std::string &path)
 Sync rename.
 
void copyfile (const std::string &old, const std::string &path, copy_file_flags flags=copy_file_flags::_UVW_ENUM)
 Copies a file asynchronously from a path to a new one.
 
bool copyfile_sync (const std::string &old, const std::string &path, copy_file_flags flags=copy_file_flags::_UVW_ENUM)
 Copies a file synchronously from a path to a new one.
 
void access (const std::string &path, int mode)
 Async access.
 
bool access_sync (const std::string &path, int mode)
 Sync access.
 
void chmod (const std::string &path, int mode)
 Async chmod.
 
bool chmod_sync (const std::string &path, int mode)
 Sync chmod.
 
void utime (const std::string &path, time atime, time mtime)
 Async utime.
 
bool utime_sync (const std::string &path, time atime, time mtime)
 Sync utime.
 
void link (const std::string &old, const std::string &path)
 Async link.
 
bool link_sync (const std::string &old, const std::string &path)
 Sync link.
 
void symlink (const std::string &old, const std::string &path, symlink_flags flags=symlink_flags::_UVW_ENUM)
 Async symlink.
 
bool symlink_sync (const std::string &old, const std::string &path, symlink_flags flags=symlink_flags::_UVW_ENUM)
 Sync symlink.
 
void readlink (const std::string &path)
 Async readlink.
 
std::pair< bool, std::pair< const char *, std::size_t > > readlink_sync (const std::string &path)
 Sync readlink.
 
void realpath (const std::string &path)
 Async realpath.
 
std::pair< bool, const char * > realpath_sync (const std::string &path)
 Sync realpath.
 
void chown (const std::string &path, uid_type uid, gid_type gid)
 Async chown.
 
bool chown_sync (const std::string &path, uid_type uid, gid_type gid)
 Sync chown.
 
void lchown (const std::string &path, uid_type uid, gid_type gid)
 Async lchown.
 
bool lchown_sync (const std::string &path, uid_type uid, gid_type gid)
 Sync lchown.
 
void opendir (const std::string &path)
 Opens a path asynchronously as a directory stream.
 
bool opendir_sync (const std::string &path)
 Opens a path synchronously as a directory stream.
 
void closedir ()
 Closes asynchronously a directory stream.
 
bool closedir_sync ()
 Closes synchronously a directory stream.
 
void readdir ()
 Iterates asynchronously over a directory stream one entry at a time.
 
std::pair< bool, std::pair< entry_type, const char * > > readdir_sync ()
 Iterates synchronously over a directory stream one entry at a time.
 
- Public Member Functions inherited from uvw::request< T, U, E >
int cancel ()
 Cancels a pending request.
 
std::size_t size () const noexcept
 Returns the size of the underlying request type.
 
- Public Member Functions inherited from uvw::resource< T, U, E... >
std::shared_ptr< R > data () const
 Gets user-defined data. uvw won't use this field in any case.
 
void data (std::shared_ptr< void > udata)
 Sets arbitrary data. uvw won't use this field in any case.
 
- Public Member Functions inherited from uvw::uv_type< U >
virtual int init ()
 Initializes the handle.
 
loopparent () const noexcept
 Gets the loop from which the resource was originated.
 
const U * raw () const noexcept
 Gets the underlying raw data structure.
 
U * raw () noexcept
 Gets the underlying raw data structure.
 
- Public Member Functions inherited from uvw::emitter< T, E... >
void on (listener_t< U > f)
 Registers a long-lived listener with the event emitter.
 
void reset () noexcept
 Disconnects the listener for the given event type.
 
void reset () noexcept
 Disconnects all listeners.
 
bool has () const noexcept
 Checks if there is a listener registered for the specific event.
 

Detailed Description

The fs request.

Cross-platform sync and async filesystem operations.
All file operations are run on the threadpool.

To create a fs_req through a loop, no arguments are required.

See the official documentation for further details.

Definition at line 591 of file fs.h.

Member Function Documentation

◆ access()

void uvw::fs_req::access ( const std::string &  path,
int  mode 
)

Async access.

Emit a fs_event event when completed.

Parameters
pathPath, as described in the official documentation.
modeMode, as described in the official documentation.

◆ access_sync()

bool uvw::fs_req::access_sync ( const std::string &  path,
int  mode 
)

Sync access.

Parameters
pathPath, as described in the official documentation.
modeMode, as described in the official documentation.
Returns
True in case of success, false otherwise.

◆ chmod()

void uvw::fs_req::chmod ( const std::string &  path,
int  mode 
)

Async chmod.

Emit a fs_event event when completed.

Parameters
pathPath, as described in the official documentation.
modeMode, as described in the official documentation.

◆ chmod_sync()

bool uvw::fs_req::chmod_sync ( const std::string &  path,
int  mode 
)

Sync chmod.

Parameters
pathPath, as described in the official documentation.
modeMode, as described in the official documentation.
Returns
True in case of success, false otherwise.

◆ chown()

void uvw::fs_req::chown ( const std::string &  path,
uid_type  uid,
gid_type  gid 
)

Async chown.

Emit a fs_event event when completed.

Parameters
pathPath, as described in the official documentation.
uidUID, as described in the official documentation.
gidGID, as described in the official documentation.

◆ chown_sync()

bool uvw::fs_req::chown_sync ( const std::string &  path,
uid_type  uid,
gid_type  gid 
)

Sync chown.

Parameters
pathPath, as described in the official documentation.
uidUID, as described in the official documentation.
gidGID, as described in the official documentation.
Returns
True in case of success, false otherwise.

◆ closedir()

void uvw::fs_req::closedir ( )

Closes asynchronously a directory stream.

Emit a fs_event event when completed.

It frees also the memory allocated internally when a path has been opened as a directory stream.

◆ closedir_sync()

bool uvw::fs_req::closedir_sync ( )

Closes synchronously a directory stream.

It frees also the memory allocated internally when a path has been opened as a directory stream.

Returns
True in case of success, false otherwise.

◆ copyfile()

void uvw::fs_req::copyfile ( const std::string &  old,
const std::string &  path,
copy_file_flags  flags = copy_file_flags::_UVW_ENUM 
)

Copies a file asynchronously from a path to a new one.

Emit a fs_event event when completed.

Available flags are:

  • fs_req::copy_file_flags::EXCL: it fails if the destination path already exists (the default behavior is to overwrite the destination if it exists).
  • fs_req::copy_file_flags::FICLONE: If present, it will attempt to create a copy-on-write reflink. If the underlying platform does not support copy-on-write, then a fallback copy mechanism is used.
  • fs_req::copy_file_flags::FICLONE_FORCE: If present, it will attempt to create a copy-on-write reflink. If the underlying platform does not support copy-on-write, then an error is returned.
Warning
If the destination path is created, but an error occurs while copying the data, then the destination path is removed. There is a brief window of time between closing and removing the file where another process could access the file.
Parameters
oldOld path, as described in the official documentation.
pathNew path, as described in the official documentation.
flagsOptional additional flags.

◆ copyfile_sync()

bool uvw::fs_req::copyfile_sync ( const std::string &  old,
const std::string &  path,
copy_file_flags  flags = copy_file_flags::_UVW_ENUM 
)

Copies a file synchronously from a path to a new one.

Available flags are:

  • fs_req::copy_file_flags::EXCL: it fails if the destination path already exists (the default behavior is to overwrite the destination if it exists).

If the destination path is created, but an error occurs while copying the data, then the destination path is removed. There is a brief window of time between closing and removing the file where another process could access the file.

Parameters
oldOld path, as described in the official documentation.
pathNew path, as described in the official documentation.
flagsOptional additional flags.
Returns
True in case of success, false otherwise.

◆ lchown()

void uvw::fs_req::lchown ( const std::string &  path,
uid_type  uid,
gid_type  gid 
)

Async lchown.

Emit a fs_event event when completed.

Parameters
pathPath, as described in the official documentation.
uidUID, as described in the official documentation.
gidGID, as described in the official documentation.

◆ lchown_sync()

bool uvw::fs_req::lchown_sync ( const std::string &  path,
uid_type  uid,
gid_type  gid 
)

Sync lchown.

Parameters
pathPath, as described in the official documentation.
uidUID, as described in the official documentation.
gidGID, as described in the official documentation.
Returns
True in case of success, false otherwise.

◆ link()

void uvw::fs_req::link ( const std::string &  old,
const std::string &  path 
)

Async link.

Emit a fs_event event when completed.

Parameters
oldOld path, as described in the official documentation.
pathNew path, as described in the official documentation.

◆ link_sync()

bool uvw::fs_req::link_sync ( const std::string &  old,
const std::string &  path 
)

Sync link.

Parameters
oldOld path, as described in the official documentation.
pathNew path, as described in the official documentation.
Returns
True in case of success, false otherwise.

◆ lstat()

void uvw::fs_req::lstat ( const std::string &  path)

Async lstat.

Emit a fs_event event when completed.

Parameters
pathPath, as described in the official documentation.

◆ lstat_sync()

std::pair< bool, file_info > uvw::fs_req::lstat_sync ( const std::string &  path)

Sync lstat.

Parameters
pathPath, as described in the official documentation.
Returns
A std::pair composed as it follows:
  • A boolean value that is true in case of success, false otherwise.
  • An initialized instance of file_info.

◆ lutime()

void uvw::fs_req::lutime ( const std::string &  path,
time  atime,
time  mtime 
)

Async lutime.

Emit a fs_event event when completed.

Parameters
pathPath, as described in the official documentation.
atimestd::chrono::duration<double>, having the same meaning as described in the official documentation.
mtimestd::chrono::duration<double>, having the same meaning as described in the official documentation.

◆ lutime_sync()

bool uvw::fs_req::lutime_sync ( const std::string &  path,
time  atime,
time  mtime 
)

Sync lutime.

Parameters
pathPath, as described in the official documentation.
atimestd::chrono::duration<double>, having the same meaning as described in the official documentation.
mtimestd::chrono::duration<double>, having the same meaning as described in the official documentation.
Returns
True in case of success, false otherwise.

◆ mkdir()

void uvw::fs_req::mkdir ( const std::string &  path,
int  mode 
)

Async mkdir.

Emit a fs_event event when completed.

Parameters
pathPath, as described in the official documentation.
modeMode, as described in the official documentation.

◆ mkdir_sync()

bool uvw::fs_req::mkdir_sync ( const std::string &  path,
int  mode 
)

Sync mkdir.

Parameters
pathPath, as described in the official documentation.
modeMode, as described in the official documentation.
Returns
True in case of success, false otherwise.

◆ mkdtemp()

void uvw::fs_req::mkdtemp ( const std::string &  tpl)

Async mktemp.

Emit a fs_event event when completed.

Parameters
tplTemplate, as described in the official documentation.

◆ mkdtemp_sync()

std::pair< bool, const char * > uvw::fs_req::mkdtemp_sync ( const std::string &  tpl)

Sync mktemp.

Parameters
tplTemplate, as described in the official documentation.
Returns
A std::pair composed as it follows:
  • A boolean value that is true in case of success, false otherwise.
  • The actual path of the newly created directory.

◆ mkstemp()

void uvw::fs_req::mkstemp ( const std::string &  tpl)

Async mkstemp.

Emit a fs_event event when completed.

Parameters
tplTemplate, as described in the official documentation.

◆ mkstemp_sync()

std::pair< bool, std::pair< std::string, std::size_t > > uvw::fs_req::mkstemp_sync ( const std::string &  tpl)

Sync mkstemp.

Returns a composed value where:

  • The first parameter indicates the created file path.
  • The second parameter is the file descriptor as an integer.

See the official documentation for further details.

Parameters
tplTemplate, as described in the official documentation.
Returns
A pair where:
  • The first parameter is a boolean value that is true in case of success, false otherwise.
  • The second parameter is a composed value (see above).

◆ opendir()

void uvw::fs_req::opendir ( const std::string &  path)

Opens a path asynchronously as a directory stream.

Emit a fs_event event when completed.

The contents of the directory can be iterated over by means of the readdir od readdir_sync member functions. The memory allocated by this function must be freed by calling closedir or closedir_sync.

Parameters
pathThe path to open as a directory stream.

◆ opendir_sync()

bool uvw::fs_req::opendir_sync ( const std::string &  path)

Opens a path synchronously as a directory stream.

The contents of the directory can be iterated over by means of the readdir od readdir_sync member functions. The memory allocated by this function must be freed by calling closedir or closedir_sync.

Parameters
pathThe path to open as a directory stream.
Returns
True in case of success, false otherwise.

◆ readdir()

void uvw::fs_req::readdir ( )

Iterates asynchronously over a directory stream one entry at a time.

Emit a fs_event event when completed.

This function isn't thread safe. Moreover, it doesn't return the . and .. entries.

◆ readdir_sync()

std::pair< bool, std::pair< entry_type, const char * > > uvw::fs_req::readdir_sync ( )

Iterates synchronously over a directory stream one entry at a time.

Returns a composed value where:

  • The first parameter indicates the entry type (see below).
  • The second parameter is a string that contains the actual value.

Available entry types are:

  • fs_req::entry_type::UNKNOWN
  • fs_req::entry_type::FILE
  • fs_req::entry_type::DIR
  • fs_req::entry_type::LINK
  • fs_req::entry_type::FIFO
  • fs_req::entry_type::SOCKET
  • fs_req::entry_type::CHAR
  • fs_req::entry_type::BLOCK

See the official documentation for further details.

This function isn't thread safe. Moreover, it doesn't return the . and .. entries.

Returns
A pair where:
  • The first parameter is a boolean value that indicates if the current entry is still valid.
  • The second parameter is a composed value (see above).

◆ readlink()

void uvw::fs_req::readlink ( const std::string &  path)

Async readlink.

Emit a fs_event event when completed.

Parameters
pathPath, as described in the official documentation.

◆ readlink_sync()

std::pair< bool, std::pair< const char *, std::size_t > > uvw::fs_req::readlink_sync ( const std::string &  path)

Sync readlink.

Parameters
pathPath, as described in the official documentation.
Returns
A std::pair composed as it follows:
  • A boolean value that is true in case of success, false otherwise.
  • A std::pair composed as it follows:
    • A bunch of data read from the given path.
    • The amount of data read from the given path.

◆ realpath()

void uvw::fs_req::realpath ( const std::string &  path)

Async realpath.

Emit a fs_event event when completed.

Parameters
pathPath, as described in the official documentation.

◆ realpath_sync()

std::pair< bool, const char * > uvw::fs_req::realpath_sync ( const std::string &  path)

Sync realpath.

Parameters
pathPath, as described in the official documentation.
Returns
A std::pair composed as it follows:
  • A boolean value that is true in case of success, false otherwise.
  • The canonicalized absolute pathname.

◆ rename()

void uvw::fs_req::rename ( const std::string &  old,
const std::string &  path 
)

Async rename.

Emit a fs_event event when completed.

Parameters
oldOld path, as described in the official documentation.
pathNew path, as described in the official documentation.

◆ rename_sync()

bool uvw::fs_req::rename_sync ( const std::string &  old,
const std::string &  path 
)

Sync rename.

Parameters
oldOld path, as described in the official documentation.
pathNew path, as described in the official documentation.
Returns
True in case of success, false otherwise.

◆ rmdir()

void uvw::fs_req::rmdir ( const std::string &  path)

Async rmdir.

Emit a fs_event event when completed.

Parameters
pathPath, as described in the official documentation.

◆ rmdir_sync()

bool uvw::fs_req::rmdir_sync ( const std::string &  path)

Sync rmdir.

Parameters
pathPath, as described in the official documentation.
Returns
True in case of success, false otherwise.

◆ scandir()

void uvw::fs_req::scandir ( const std::string &  path,
int  flags 
)

Async scandir.

Emit a fs_event event when completed.

Parameters
pathPath, as described in the official documentation.
flagsFlags, as described in the official documentation.

◆ scandir_next()

std::pair< bool, std::pair< entry_type, const char * > > uvw::fs_req::scandir_next ( )

Gets entries populated with the next directory entry data.

Returns a composed value where:

  • The first parameter indicates the entry type (see below).
  • The second parameter is a string that contains the actual value.

Available entry types are:

  • fs_req::entry_type::UNKNOWN
  • fs_req::entry_type::FILE
  • fs_req::entry_type::DIR
  • fs_req::entry_type::LINK
  • fs_req::entry_type::FIFO
  • fs_req::entry_type::SOCKET
  • fs_req::entry_type::CHAR
  • fs_req::entry_type::BLOCK

See the official documentation for further details.

Returns
A pair where:
  • The first parameter is a boolean value that indicates if the current entry is still valid.
  • The second parameter is a composed value (see above).

◆ scandir_sync()

std::pair< bool, std::size_t > uvw::fs_req::scandir_sync ( const std::string &  path,
int  flags 
)

Sync scandir.

Parameters
pathPath, as described in the official documentation.
flagsFlags, as described in the official documentation.
Returns
A std::pair composed as it follows:
  • A boolean value that is true in case of success, false otherwise.
  • The number of directory entries selected.

◆ stat()

void uvw::fs_req::stat ( const std::string &  path)

Async stat.

Emit a fs_event event when completed.

Parameters
pathPath, as described in the official documentation.

◆ stat_sync()

std::pair< bool, file_info > uvw::fs_req::stat_sync ( const std::string &  path)

Sync stat.

Parameters
pathPath, as described in the official documentation.
Returns
A std::pair composed as it follows:
  • A boolean value that is true in case of success, false otherwise.
  • An initialized instance of file_info.

◆ statfs()

void uvw::fs_req::statfs ( const std::string &  path)

Async statfs.

Emit a fs_event event when completed.

Any fields in the resulting object that are not supported by the underlying operating system are set to zero.

Parameters
pathPath, as described in the official documentation.

◆ statfs_sync()

std::pair< bool, fs_info > uvw::fs_req::statfs_sync ( const std::string &  path)

Sync statfs.

Any fields in the resulting object that are not supported by the underlying operating system are set to zero.

Parameters
pathPath, as described in the official documentation.
Returns
A std::pair composed as it follows:
  • A boolean value that is true in case of success, false otherwise.
  • An initialized instance of fs_info.

◆ symlink()

void uvw::fs_req::symlink ( const std::string &  old,
const std::string &  path,
symlink_flags  flags = symlink_flags::_UVW_ENUM 
)

Async symlink.

Emit a fs_event event when completed.

Available flags are:

  • fs_req::symlink_flags::DIR: it indicates that the old path points to a directory.
  • fs_req::symlink_flags::JUNCTION: it requests that the symlink is created using junction points.
Parameters
oldOld path, as described in the official documentation.
pathNew path, as described in the official documentation.
flagsOptional additional flags.

◆ symlink_sync()

bool uvw::fs_req::symlink_sync ( const std::string &  old,
const std::string &  path,
symlink_flags  flags = symlink_flags::_UVW_ENUM 
)

Sync symlink.

Available flags are:

  • fs_req::symlink_flags::DIR: it indicates that the old path points to a directory.
  • fs_req::symlink_flags::JUNCTION: it requests that the symlink is created using junction points.
Parameters
oldOld path, as described in the official documentation.
pathNew path, as described in the official documentation.
flagsFlags, as described in the official documentation.
Returns
True in case of success, false otherwise.

◆ unlink()

void uvw::fs_req::unlink ( const std::string &  path)

Async unlink.

Emit a fs_event event when completed.

Parameters
pathPath, as described in the official documentation.

◆ unlink_sync()

bool uvw::fs_req::unlink_sync ( const std::string &  path)

Sync unlink.

Parameters
pathPath, as described in the official documentation.
Returns
True in case of success, false otherwise.

◆ utime()

void uvw::fs_req::utime ( const std::string &  path,
time  atime,
time  mtime 
)

Async utime.

Emit a fs_event event when completed.

Parameters
pathPath, as described in the official documentation.
atimestd::chrono::duration<double>, having the same meaning as described in the official documentation.
mtimestd::chrono::duration<double>, having the same meaning as described in the official documentation.

◆ utime_sync()

bool uvw::fs_req::utime_sync ( const std::string &  path,
time  atime,
time  mtime 
)

Sync utime.

Parameters
pathPath, as described in the official documentation.
atimestd::chrono::duration<double>, having the same meaning as described in the official documentation.
mtimestd::chrono::duration<double>, having the same meaning as described in the official documentation.
Returns
True in case of success, false otherwise.

The documentation for this class was generated from the following file: