CppCommon  1.0.4.1
C++ Common Library
Public Member Functions | Static Public Member Functions | Friends | List of all members
CppCommon::Symlink Class Reference

Filesystem symlink. More...

#include <symlink.h>

Inheritance diagram for CppCommon::Symlink:
CppCommon::Path

Public Member Functions

 Symlink ()
 Initialize symbolic link with an empty path. More...
 
 Symlink (const Path &path)
 Initialize symbolic link with a given path. More...
 
 Symlink (const Symlink &)=default
 
 Symlink (Symlink &&)=default
 
 ~Symlink ()=default
 
Symlinkoperator= (const Path &path)
 
Symlinkoperator= (const Symlink &)=default
 
Symlinkoperator= (Symlink &&)=default
 
 operator bool () const noexcept
 Check if the symlink is present. More...
 
Path target () const
 Read symlink target path. More...
 
bool IsSymlinkExists () const
 Is the symlink exists? More...
 
bool IsTargetExists () const
 Is the target exists? More...
 
void swap (Symlink &symlink) noexcept
 Swap two instances. More...
 
- Public Member Functions inherited from CppCommon::Path
 Path ()
 Initialize path with an empty value. More...
 
 Path (const char *path)
 Initialize path with a given C-string value. More...
 
 Path (const std::string &path)
 Initialize path with a given string value. More...
 
 Path (const wchar_t *path)
 Initialize path with a given wide C-string value. More...
 
 Path (const std::wstring &path)
 Initialize path with a given wide string value. More...
 
 Path (const Path &)=default
 
 Path (Path &&)=default
 
 ~Path ()=default
 
Pathoperator= (const Path &)=default
 
Pathoperator= (Path &&)=default
 
 operator bool () const noexcept
 Check if the path is not empty. More...
 
Pathoperator/= (const Path &path)
 
Pathoperator+= (const Path &path)
 
const std::string & string () const noexcept
 Get the path value as UTF-8 string. More...
 
std::wstring wstring () const
 Get the path value as a wide string. More...
 
Path root () const
 Decompose root path from the current path. More...
 
Path relative () const
 Decompose relative path from the current path. More...
 
Path parent () const
 Decompose parent path from the current path. More...
 
Path filename () const
 Decompose filename from the current path. More...
 
Path stem () const
 Decompose stem from the current path. More...
 
Path extension () const
 Decompose extension from the current path. More...
 
Path absolute () const
 Transform the current path to the real path on a filesystem. More...
 
Path canonical () const
 Transform the current path and replace all '.' and '..' properly. More...
 
Path validate (char placeholder='_') const
 Transform the current path and replace all deprecated characters with a given placeholder (default is '_') More...
 
FileType type () const
 Get the path file type. More...
 
Flags< FileAttributesattributes () const
 Get the path file attributes. More...
 
Flags< FilePermissionspermissions () const
 Get the path file permissions. More...
 
UtcTimestamp created () const
 Get the path created UTC timestamp. More...
 
UtcTimestamp modified () const
 Get the path modified UTC timestamp. More...
 
size_t hardlinks () const
 Get the path count of hardlinks. More...
 
SpaceInfo space () const
 Get the path space information. More...
 
bool empty () const noexcept
 Is the path empty? More...
 
bool HasRoot () const
 Has root path? More...
 
bool HasRelative () const
 Has relative path? More...
 
bool HasParent () const
 Has parent path? More...
 
bool HasFilename () const
 Has filename? More...
 
bool HasStem () const
 Has stem? More...
 
bool HasExtension () const
 Has extension? More...
 
bool IsAbsolute () const
 Is absolute path? More...
 
bool IsRelative () const
 Is relative path? More...
 
bool IsExists () const
 Is the path exists? More...
 
bool IsRegularFile () const
 Is the path points to regular file? More...
 
bool IsDirectory () const
 Is the path points to directory? More...
 
bool IsSymlink () const
 Is the path points to symbolic link? More...
 
bool IsOther () const
 Is the path points to special file (block, character, FIFO, socket)? More...
 
bool IsEquivalent (const Path &path) const
 Is the current path is equivalent to the given one (points to the same node on a filesystem)? More...
 
void Clear () noexcept
 Clear the path content. More...
 
PathAssign (const Path &path)
 Assign the given path to the current one. More...
 
PathAppend (const Path &path)
 Append the given path to the current one. More...
 
PathConcat (const Path &path)
 Concatenate the given path to the current one. More...
 
PathMakePreferred ()
 Convert all path separators to system ones ('\' for Windows or '/' for Unix) More...
 
PathReplaceFilename (const Path &filename)
 Replace the current path filename with a given one. More...
 
PathReplaceExtension (const Path &extension)
 Replace the current path extension with a given one. More...
 
PathRemoveFilename ()
 Remove the current path filename. More...
 
PathRemoveExtension ()
 Remove the current path extension. More...
 
PathRemoveTrailingSeparators ()
 Remove all trailing separators form the current path. More...
 
void swap (Path &path) noexcept
 Swap two instances. More...
 

Static Public Member Functions

static Symlink CreateSymlink (const Path &src, const Path &dst)
 Create a new symlink. More...
 
static Path CreateHardlink (const Path &src, const Path &dst)
 Create a new hardlink. More...
 
static Symlink CopySymlink (const Path &src, const Path &dst)
 Copy the current symlink to another destination path. More...
 
- Static Public Member Functions inherited from CppCommon::Path
static bool deprecated (char character) noexcept
 Is the given character is deprecated by the filesystem? More...
 
static bool deprecated (wchar_t character) noexcept
 Is the given wide character is deprecated by the filesystem? More...
 
static std::string deprecated ()
 Get filesystem deprecated characters ('\', '/', '?', '', '*', ':', '|', '"', '<', '>') More...
 
static char separator () noexcept
 Get the system path separator character ('\' for Windows or '/' for Unix) More...
 
static Path initial ()
 Get the initial path of the process. More...
 
static Path current ()
 Get the current path of the process. More...
 
static Path executable ()
 Get the executable path of the process. More...
 
static Path home ()
 Get the home path of the process. More...
 
static Path temp ()
 Get the temporary path of the process. More...
 
static Path unique ()
 Get the unique filename in UUID format "00000000-0000-0000-0000-000000000000". More...
 
static Path Copy (const Path &src, const Path &dst, bool overwrite=false)
 Copy the given source path to destination path (file, empty directory, symlink, etc) More...
 
static Path CopyIf (const Path &src, const Path &dst, const std::string &pattern="", bool overwrite=false)
 Copy all matched files from the the given source path to destination path (files, directories, symlinks, etc) More...
 
static Path CopyAll (const Path &src, const Path &dst, bool overwrite=false)
 Recursively copy the given source path to destination path (files, directories, symlinks, etc) More...
 
static Path Rename (const Path &src, const Path &dst)
 Rename the given source path to destination path (file, empty directory, symlink, etc) More...
 
static Path Remove (const Path &path)
 Remove the given path (file, empty directory, symlink, etc) from the filesystem. More...
 
static Path RemoveAll (const Path &path)
 Recursively remove the given path (file, empty directory, symlink, etc) from the filesystem. More...
 
static Path RemoveIf (const Path &path, const std::string &pattern="")
 Recursively remove the given path matched to the given pattern (file, empty directory, symlink, etc) from the filesystem. More...
 
static void SetAttributes (const Path &path, const Flags< FileAttributes > &attributes)
 Set file attributes for the given path. More...
 
static void SetPermissions (const Path &path, const Flags< FilePermissions > &permissions)
 Set file permissions for the given path. More...
 
static void SetCreated (const Path &path, const UtcTimestamp &timestamp)
 Set created UTC timestamp for the given path. More...
 
static void SetModified (const Path &path, const UtcTimestamp &timestamp)
 Set modified UTC timestamp for the given path. More...
 
static void SetCurrent (const Path &path)
 Set the given path of the process as a current one. More...
 
static void Touch (const Path &path)
 Touch the given path and set its modified UTC timestamp to the current value. More...
 

Friends

void swap (Symlink &symlink1, Symlink &symlink2) noexcept
 

Additional Inherited Members

- Protected Attributes inherited from CppCommon::Path
std::string _path
 Path string. More...
 

Detailed Description

Filesystem symlink.

Filesystem symlink wraps link management operations (create symlink, read symlink target, copy symlink, create hardlink).

Not thread-safe.

Examples
filesystem_symlink.cpp.

Definition at line 23 of file symlink.h.

Constructor & Destructor Documentation

◆ Symlink() [1/4]

CppCommon::Symlink::Symlink ( )
inline

Initialize symbolic link with an empty path.

Definition at line 27 of file symlink.h.

◆ Symlink() [2/4]

CppCommon::Symlink::Symlink ( const Path path)
inline

Initialize symbolic link with a given path.

Parameters
path- Symbolic link path

Definition at line 32 of file symlink.h.

◆ Symlink() [3/4]

CppCommon::Symlink::Symlink ( const Symlink )
default

◆ Symlink() [4/4]

CppCommon::Symlink::Symlink ( Symlink &&  )
default

◆ ~Symlink()

CppCommon::Symlink::~Symlink ( )
default

Member Function Documentation

◆ CopySymlink()

static Symlink CppCommon::Symlink::CopySymlink ( const Path src,
const Path dst 
)
inlinestatic

Copy the current symlink to another destination path.

If the source path is a symlink then a new destination symlink will be created based on its target. Otherwise symlink will be created explicitly based on the source path.

Parameters
src- Source path
dst- Destination path
Returns
Copied symlink

Definition at line 79 of file symlink.h.

◆ CreateHardlink()

Path CppCommon::Symlink::CreateHardlink ( const Path src,
const Path dst 
)
static

Create a new hardlink.

Parameters
src- Source path
dst- Destination path
Returns
Created hardlink

Definition at line 168 of file symlink.cpp.

◆ CreateSymlink()

Symlink CppCommon::Symlink::CreateSymlink ( const Path src,
const Path dst 
)
static

Create a new symlink.

Parameters
src- Source path
dst- Destination path
Returns
Created symlink
Examples
filesystem_symlink.cpp.

Definition at line 142 of file symlink.cpp.

◆ IsSymlinkExists()

bool CppCommon::Symlink::IsSymlinkExists ( ) const

Is the symlink exists?

Definition at line 116 of file symlink.cpp.

◆ IsTargetExists()

bool CppCommon::Symlink::IsTargetExists ( ) const
inline

Is the target exists?

Definition at line 51 of file symlink.h.

◆ operator bool()

CppCommon::Symlink::operator bool ( ) const
inlineexplicitnoexcept

Check if the symlink is present.

Definition at line 43 of file symlink.h.

◆ operator=() [1/3]

Symlink& CppCommon::Symlink::operator= ( const Path path)
inline

Definition at line 37 of file symlink.h.

◆ operator=() [2/3]

Symlink& CppCommon::Symlink::operator= ( const Symlink )
default

◆ operator=() [3/3]

Symlink& CppCommon::Symlink::operator= ( Symlink &&  )
default

◆ swap()

void CppCommon::Symlink::swap ( Symlink symlink)
inlinenoexcept

Swap two instances.

Definition at line 11 of file symlink.inl.

◆ target()

Path CppCommon::Symlink::target ( ) const

Read symlink target path.

Examples
filesystem_symlink.cpp.

Definition at line 66 of file symlink.cpp.

Friends And Related Function Documentation

◆ swap

void swap ( Symlink symlink1,
Symlink symlink2 
)
friend

Definition at line 17 of file symlink.inl.


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