lfilesystem  0.0.1
C++ filesystem library
lfilesystem_SymLink.h
Go to the documentation of this file.
1 /*
2  * ======================================================================================
3  * __ ____ __ __ ____ ___
4  * ( ) (_ _)( \/ )( ___)/ __)
5  * )(__ _)(_ ) ( )__) \__ \
6  * (____)(____)(_/\/\_)(____)(___/
7  *
8  * This file is part of the Limes open source library and is licensed under the terms of the GNU Public License.
9  *
10  * Commercial licenses are available; contact the maintainers at ben.the.vining@gmail.com to inquire for details.
11  *
12  * ======================================================================================
13  */
14 
15 #pragma once
16 
17 #include <functional> // for std::hash
18 #include <optional>
19 #include "lfilesystem/lfilesystem_Export.h"
21 
28 namespace limes::files
29 {
30 
31 class Directory;
32 
40 class LFILE_EXPORT SymLink final : public FilesystemEntry
41 {
42 public:
44 
45  SymLink (const SymLink&) = default;
46  SymLink& operator= (const SymLink&) = default;
47 
48  SymLink (SymLink&&) = default;
49  SymLink& operator= (SymLink&&) = default;
50 
63  explicit SymLink (const Path& symLinkPath, const FilesystemEntry& linkTarget);
64 
75  [[nodiscard]] FilesystemEntry follow (std::size_t recursionDepth = 50) const noexcept;
76 
83  [[nodiscard]] bool references (const FilesystemEntry& entry, std::size_t recursionDepth = 50) const noexcept;
84 
88  [[nodiscard]] bool referencesSameLocationAs (const SymLink& other) const;
89 
91  [[nodiscard]] bool isDangling() const noexcept;
92 
93  [[nodiscard]] bool isSymLink() const noexcept final;
94  [[nodiscard]] bool isFile() const noexcept final;
95  [[nodiscard]] bool isDirectory() const noexcept final;
96 
99 
106  static std::optional<SymLink> create (const Path& linkPath, const Path& target) noexcept;
107  static std::optional<SymLink> create (const Path& linkPath, const FilesystemEntry& target) noexcept;
108 
128  static std::optional<SymLink> create (const Directory& newDirectory, const Path& target) noexcept;
129  static std::optional<SymLink> create (const Directory& newDirectory, const FilesystemEntry& target) noexcept;
131 
132 private:
133  [[nodiscard]] FilesystemEntry follow_recurse (std::size_t counter, std::size_t limit) const;
134  [[nodiscard]] bool references_recurse (const FilesystemEntry& entry, std::size_t counter, std::size_t limit) const;
135 };
136 
137 } // namespace limes::files
138 
139 namespace std
140 {
141 
147 template <>
148 struct LFILE_EXPORT hash<limes::files::SymLink> final
149 {
150  size_t operator() (const limes::files::SymLink& l) const noexcept;
151 };
152 
153 } // namespace std
This class represents a directory on the filesystem.
The base class for any kind of object on the filesystem.
FilesystemEntry()=default
Creates a FilesystemEntry with an empty path.
std::filesystem::path Path
Convenience typedef for filesystem paths.
This file defines the FilesystemEntry class.
Filesystem utilities.