ALib C++ Framework
by
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
finfo.inl
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of module \alib_files of the \aliblong.
4///
5/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
6/// Published under #"mainpage_license".
7//==================================================================================================
8ALIB_EXPORT namespace alib { namespace files {
9
10class FTree;
11class File;
12
13/// The entry type which is embedded in each tree node.
14class FInfo
15{
16 protected:
17 #if !DOXYGEN
18 friend class FTree; ///< Allow access from within class File.
19 friend class File; ///< Allow access from within class File.
20 #endif
21
22 public:
23 /// Enumeration of the possible file types. This is compatible with the posix list of types,
24 /// with the exception that symbolic links are differentiated between those linking to
25 /// a directory and those linking to any other file type.
26 enum class Types : uint8_t
27 {
28 DIRECTORY = 0, ///< Directory/folder.
29 SYMBOLIC_LINK_DIR = 1, ///< Symbolic link targeting a directory.
30 ///< In case scanning does not resolve links, this is never set.
31 REGULAR = 2, ///< Regular file.
32 SYMBOLIC_LINK = 3, ///< Symbolic link targeting a non-directory file.
33 ///< In case scanning does not resolve links, possibly to a directory.
34 BLOCK = 4, ///< A block special file.
35 CHARACTER = 5, ///< A character special file.
36 FIFO = 6, ///< A FIFO (also known as pipe) file.
37 SOCKET = 7, ///< A socket file.
38
39 UNKNOWN_OR_ERROR = 8, ///< Filetype (should never or seldom happen).
40 ///< Maybe filesystem changed during scan or similar strange thing.
41 MARKER_TYPES_END = 9, ///< A marker for the last countable type. The rest are unused/errors
42 };
43
44 /// This is a resourced enumeration that is equivalent to enum class #".Types" but uses
45 /// a 1-Letter code when serialized. The symbols are taken from GNU/Linux command
46 /// <c>'ls -l'</c>, except special type \b SYMBOLIC_LINK_DIR which uses an upper case <c>'L'</c>
47 /// in contrast to the lower case <c>'l'</c> used with links to files.
48 enum class TypeNames1Letter : uint8_t
49 {
50 DIRECTORY = 0, ///< d: Directory/folder.
51 SYMBOLIC_LINK_DIR = 1, ///< L: Symbolic link targeting a directory.
52 REGULAR = 2, ///< -: Regular file.
53 SYMBOLIC_LINK = 3, ///< l: Symbolic link targeting a non-directory file.
54 BLOCK = 4, ///< b: A block special file.
55 CHARACTER = 5, ///< c: A character special file.
56 FIFO = 6, ///< p: A FIFO (also known as pipe) file.
57 SOCKET = 7, ///< s: A socket file.
58 };
59
60 /// This is a resourced enumeration that is equivalent to enum class #".Types" but uses
61 /// a 2-Letter code when serialized.
62 enum class TypeNames2Letters : uint8_t
63 {
64 DIRECTORY = 0, ///< DR: Directory/folder.
65 SYMBOLIC_LINK_DIR = 1, ///< LD: Symbolic link targeting a directory.
66 REGULAR = 2, ///< RF: Regular file.
67 SYMBOLIC_LINK = 3, ///< LF: Symbolic link targeting a non-directory file.
68 BLOCK = 4, ///< BL: A block special file.
69 CHARACTER = 5, ///< CH: A character special file.
70 FIFO = 6, ///< FF: A FIFO (also known as pipe) file.
71 SOCKET = 7, ///< SO: A socket file.
72 };
73
74 /// This is a resourced enumeration that is equivalent to enum class #".Types" but uses
75 /// a 3-Letter code when serialized.
76 enum class TypeNames3Letters : uint8_t
77 {
78 DIRECTORY = 0, ///< DIR: Directory/folder.
79 SYMBOLIC_LINK_DIR = 1, ///< SLD: Symbolic link targeting a directory.
80 REGULAR = 2, ///< REG: Regular file.
81 SYMBOLIC_LINK = 3, ///< SLF: Symbolic link targeting a non-directory file.
82 BLOCK = 4, ///< BLK: A block special file.
83 CHARACTER = 5, ///< CHR: A character special file.
84 FIFO = 6, ///< FFO: A FIFO (also known as pipe) file.
85 SOCKET = 7, ///< SCK: A socket file.
86 };
87
88
89 /// Permission flags. Compatible with posix* definition.
90 enum class Permissions : uint32_t
91 {
92 NONE = 0, ///< no permission bits are set
93 UNKNOWN = 010000, ///< Unknown permissions (e.g., when not read, or filesystem does not support permissions)
94 MASK = 07777, ///< All valid permission bits. Equivalent to all | set_uid | set_gid | sticky_bit
95 ALL = 0777, ///< All users have read, write, and execute/search permissions Equivalent to owner_all | group_all | others_all
96
97 OWNER_READ = 0400, ///< Posix \b S_IRUSR: File owner has read permission
98 OWNER_WRITE = 0200, ///< Posix \b S_IWUSR: File owner has write permission
99 OWNER_EXEC = 0100, ///< Posix \b S_IXUSR: File owner has execute/search permission
100 OWNER_ALL = 0700, ///< Posix \b S_IRWXU: File owner has read, write, and execute/search permissions Equivalent to owner_read | owner_write | owner_exec
101
102 GROUP_READ = 040, ///< Posix \b S_IRGRP: The file's user group has read permission
103 GROUP_WRITE = 020, ///< Posix \b S_IWGRP: The file's user group has write permission
104 GROUP_EXEC = 010, ///< Posix \b S_IXGRP: The file's user group has execute/search permission
105 GROUP_ALL = 070, ///< Posix \b S_IRWXG: The file's user group has read, write, and execute/search permissions Equivalent to group_read | group_write | group_exec
106
107 OTHERS_READ = 04, ///< Posix \b S_IROTH: Other users have read permission
108 OTHERS_WRITE = 02, ///< Posix \b S_IWOTH: Other users have write permission
109 OTHERS_EXEC = 01, ///< Posix \b S_IXOTH: Other users have execute/search permission
110 OTHERS_ALL = 07, ///< Posix \b S_IRWXO: Other users have read, write, and execute/search permissions Equivalent to others_read | others_write | others_exec
111
112 SET_UID = 04000, ///< Posix \b S_ISUID: Set user ID to file owner user ID on execution
113 SET_GID = 02000, ///< Posix \b S_ISGID: Set group ID to file's user group ID on execution
114 STICKY_BIT = 01000, ///< Posix \b S_ISVTX: Implementation-defined meaning, but POSIX XSI specifies that when set on a directory, only file owners may delete files even if the directory is writeable to others (used with /tmp)
115 };
116
117 /// Type definition for owner and group ids
118 using TOwnerAndGroupID = uint32_t;
119
120 /// Constant value for owner and group IDs to denote that the field was not determined.
121 static constexpr TOwnerAndGroupID UnknownID= (std::numeric_limits<uint32_t>::max)();
122
123 /// Per-entry information about how a node was scanned.
124 enum class ScanStates : uint8_t
125 {
126 NONE = 0, ///< Node created only from the given start path path.
127 STATS = 1, ///< Only stats (size, date, owner, etc.) read.
128
129 RESOLVED = 2, ///< Read symlink target strings.
130
131 MAX_DEPTH_REACHED = 3, ///< Scanning stopped because maximum depth was reached.
132 NOT_FOLLOWED = 4, ///< A symbolic link that targets a directory, but scan parameters specify not to follow.
133 NOT_CROSSING_FS = 5, ///< A directory that represented a mounted filesystem was not followed due to the field
134 ///< #"ScanParameters::CrossFileSystems;*" being set to \c false.
135 NO_AFS = 6, ///< A directory that represented a mounted filesystem was not followed due to the field
136 ///< #"ScanParameters::IncludeArtificialFS;*" being set to \c false.
137 RECURSIVE = 7, ///< Follow symlink target strings.
138
139 NO_ACCESS = 8, ///< Scanner failure due to limited access rights.
140 NO_ACCESS_SL = 9, ///< Scanner failure due to limited access rights on a symbolic link.
141 NO_ACCESS_SL_TARGET=10, ///< Scanner failure due to limited access rights on a symbolic link's target.
142 NO_ACCESS_DIR =11, ///< Scanner failure due to limited access rights on a directory.
143 BROKEN_LINK =12, ///< A symbolic link targets a non-existent file or directory.
144 CIRCULAR_LINK =13, ///< Set if recursion stopped at a symbolic link which was identified by the
145 ///< operating system as a circular link.
146 DUPLICATE =14, ///< Set if recursion stopped on a symbolic link who's target had been scanned already.
147 ///< This might happen either because the path was already scanned by another search, or
148 ///< because a symbolic link is circular or because of a mixture of both.
149 ///< Thus, this can indicate a circular link, but does not have to.
150 NOT_EXISTENT =15, ///< Set if a given start path does not exist.
151 UNKNOWN_ERROR =16, ///< Unknown scanner failure
152 };
153
154 /// This is a resourced enumeration that is equivalent to enum class #"ScanStates" but uses
155 /// a 3-Letter code when serialized.
156 enum class ScanStates3Letters : uint8_t
157 {
158 NONE = 0, ///< NON: Node created only from given start path path.
159 STATS = 1, ///< STA: Only stats (size, date, owner, etc.) read.
160
161 RESOLVED = 2, ///< RES: Read symlink target strings.
162
163 MAX_DEPTH_REACHED = 3, ///< MDR:Scanner stopped, because maximum depth was reached.
164 NOT_FOLLOWED = 4, ///< NFO:A symbolic link that targets a directory, but scan parameters specify not to follow.
165 NOT_CROSSING_FS = 5, ///< NCF:A directory that represented a mounted filesystem was not followed due to the field
166 ///< #"ScanParameters::CrossFileSystems;*" being set to \c false.
167 NO_AFS = 6, ///< NAF:A directory that represented a mounted filesystem was not followed due to the field
168 ///< #"ScanParameters::IncludeArtificialFS;*" being set to \c false.
169 RECURSIVE = 7, ///< REC:Follow symlink target strings.
170
171 NO_ACCESS = 8, ///< NAC: Scanner failure due to limited access rights.
172 NO_ACCESS_SL = 9, ///< NSL: Scanner failure due to limited access rights.
173 NO_ACCESS_SL_TARGET=10, ///< NAT: Scanner failure due to limited access rights.
174 NO_ACCESS_DIR =11, ///< NAD: Scanner failure due to limited access rights.
175 BROKEN_LINK =12, ///< BRL: A symbolic link targets a non-existent file or directory.
176 CIRCULAR_LINK =13, ///< CIL: Set if recursion stopped on a symbolic link which was identified by the
177 ///< operating system as a circular link.
178 DUPLICATE =14, ///< DUP: Set if recursion stopped on a symbolic link who's target had been scanned already.
179 ///< This might happen either because the path was already scanned by another search, or
180 ///< because a symbolic link is circular or because of a mixture of both.
181 ///< Thus, this can indicate a circular link, but does not have to.
182 NOT_EXISTENT =15, ///< NEX: Set if a given start path does not exist.
183 UNKNOWN_ERROR =16, ///< UKE: Unknown scanner failure
184 };
185
186
187 /// Recursively accumulated values for directories.
189 {
190 uinteger Size = 0; ///< The cumulated sizes of all files and directories.
191 std::array<uint32_t, size_t(Types::MARKER_TYPES_END)> TypeCounters= {0,0,0,0,0,0,0,0}; ///< Per-type counters.
192 uint32_t QtyErrsAccess = 0; ///< Number of access errors in the folder and subfolders.
193 uint32_t QtyErrsBrokenLink = 0; ///< Number of broken symbolic links in the directory and its subfolders.
194 uint32_t QtyStopsOnMaxDepth = 0; ///< Number of recursion aborts due to reach of maximum recursion depth.
195 uint32_t QtyStopsOnCircularLinks = 0; ///< Number of recursion aborts due to detected circular links reach of maximum recursion depth.
196
197
198 /// Defaulted default constructor.
199 constexpr DirectorySums() noexcept =default;
200
201 /// Adds the values in the given summary object to this.
202 /// @param rhs The values to add.
203 /// @return A reference to <c>this</c>
204 DirectorySums& operator+= (const DirectorySums& rhs) {
205 Size += rhs.Size ;
206 for (size_t i = 0; i < size_t(Types::MARKER_TYPES_END); ++i)
207 TypeCounters[i]+= rhs.TypeCounters[i];
208 QtyErrsAccess += rhs.QtyErrsAccess ;
209 QtyErrsBrokenLink += rhs.QtyErrsBrokenLink ;
210 QtyStopsOnMaxDepth += rhs.QtyStopsOnMaxDepth;
211 QtyStopsOnCircularLinks+= rhs.QtyErrsBrokenLink ;
212 return *this;
213 }
214
215 /// Subtracts the values in the given summary object from this.
216 /// @param rhs The values to subtract.
217 /// @return A reference to <c>this</c>
219 Size -= rhs.Size ;
220 for (size_t i = 0; i < size_t(Types::MARKER_TYPES_END); ++i)
221 TypeCounters[i]-= rhs.TypeCounters[i];
226 return *this;
227 }
228 /// Returns \c true if the given \p{type} equals either
229 /// #"Types::DIRECTORY" or
230 /// #"Types::SYMBOLIC_LINK_DIR"
231 /// @param type returns \c false if the given type does not represent a directory
232 /// and \c true if \p{type} equals
233 /// #"Types::DIRECTORY" or
234 /// #"Types::SYMBOLIC_LINK_DIR"
235 /// @return \c false if the given type does not represent a directory, \c true otherwise.
236 constexpr bool IsDirType(Types type) const noexcept { return int(type) < 2; }
237
238 /// Adds a file/directory to the counters
239 /// @param finfo The entry to add.
240 /// @return A reference to <c>this</c>
241 constexpr DirectorySums& Add(const FInfo& finfo) noexcept {
242 ++TypeCounters[size_t(finfo.Type())];
243 Size+= finfo.Size();
244 return *this;
245 }
246
247
248 /// Returns the cumulated number of entries (of any type).
249 /// @return The number of entries counted.
250 uint32_t Count() const noexcept {
251 uint32_t result= 0;
252 for (size_t i = 0; i < size_t(Types::MARKER_TYPES_END); ++i)
253 result+= TypeCounters[i];
254 return result;
255 }
256
257 /// Returns the number of entries of the given \p{type}.
258 /// @param type The type to get the number of entries for.
259 /// @return The number of directories or symbolic links to directories.
260 uint32_t Count(Types type) const noexcept {
262 "FILES", "Cant get count for file type \"{}\"", type )
263 return TypeCounters[size_t(type)];
264 }
265
266 /// Returns the sum of the number of entries of type
267 /// #"Types::DIRECTORY" and
268 /// #"Types::SYMBOLIC_LINK_DIR"
269 /// @return The number of directories or symbolic links to directories.
270 uint32_t CountDirectories() const noexcept {
271 return TypeCounters[size_t(Types::DIRECTORY)]
273 }
274
275 /// Returns the sum of the number of entries which are \b not of type
276 /// #"Types::DIRECTORY" and
277 /// #"Types::SYMBOLIC_LINK_DIR"
278 /// @return The number of regular files, fifo, sockets, etc.
279 uint32_t CountNonDirectories() const noexcept {
280 uint32_t result= 0;
281 for (size_t i = 2; i < size_t(Types::MARKER_TYPES_END); ++i)
282 result+= TypeCounters[i];
283 return result;
284 }
285
286 }; // struct DirectorySums
287
288 /// Base type to create pointers to different extended entry information structs.
290 {};
291
292 /// Additional information for entries of directory-type. Allocated in the tree's
293 /// #"MonoAllocator" and accessible via #"GetExtendedInfo()" and #".Sums".
295 {
296 DirectorySums Sums; ///< The recursive sums evaluated during scan.
297 };
298
299 /// Additional information for entries of symlink-type. Allocated in the tree's
300 /// #"MonoAllocator" and accessible via #"GetExtendedInfo()",
301 /// #GetLinkTarget and #GetRealLinkTarget.
303 {
304 system::CPathString Target; ///< The target path.
305 ///< This is a zero-terminated \b CString.
306 system::CPathString RealTarget; ///< The resolved real target path.
307 };
308
309 /// Additional information for entries of symbolic link type. Allocated in the tree's
310 /// #"MonoAllocator" and accessible via #GetExtendedInfo(), #GetLinkTarget,
311 /// #GetRealLinkTarget and #Sums.
313 {
314 DirectorySums Sums; ///< The recursive sums evaluated during scan.
315 };
316
317 protected:
318 DateTime mDate; ///< The last date and time the contents of the file was modified.
319 ///< This timestamp is should be correct on all platforms/filesystems.
320 DateTime bDate; ///< The date this file was created. This timestamp is correctly set
321 ///< only with certain filesystems under GNU/Linux, e.g., 'EXT4'.
322 ///< If not available, the smallest value of the other three timestamps
323 ///< is used.
324 DateTime cDate; ///< The date of the last change of the files' meta-information
325 ///< (e.g., owner). This is not correctly set on all
326 ///< platforms/filesystems. If not available, it will be set to #mDate.
327 DateTime aDate; ///< The date of last read or write access.
328 ///< This is not correctly set on all platforms/filesystems.
329 ///< If not available, it will be set to #mDate.
330 uinteger symParent= 0; ///< A cursor handle to the symbolic parent. See manual chapter
331 ///< #"alib_files_tut_scan_realpath" for more information.
332 uinteger size; ///< The file size. In case of a directory, this is \c 0.
333 uint32_t owner; ///< The user id that owns the file.
334 uint32_t group; ///< The group id that owns the file.
335 uint32_t qtyHardLinks; ///< The number of hard links to the file.
336
337
338 /// A bitfield encoding various information.
339 struct Bits {
340 Types Type : 4; ///< The file type.
341 bool IsArtificialFS : 1; ///< Denotes whether the file resides in an artificial filesystem.
342 bool TargetIsArtificialFS: 1; ///< Denotes whether a link points into an artificial filesystem.
343 bool IsCrossingFS : 1; ///< Denotes whether the file is a mount point.
344 bool TargetIsCrossingFS : 1; ///< Denotes whether a link points to a mount point.
345 Permissions Permission : 13; ///< The unix file-permissions.
346 ScanStates ScanState : 5; ///< The scan state.
347
348 /// Default constructor. Sets all members to \b %NONE, \c false or \b %Error.
351 , IsArtificialFS {false}
352 , TargetIsArtificialFS{false}
353 , IsCrossingFS {false}
354 , TargetIsCrossingFS {false}
356 , ScanState {ScanStates::NONE } {}
357 };
358
359 Bits bits; ///< A bitfield encoding various information.
360
361 /// Extended information, depending on the entry type.
363
364 /// Pool-allocated custom data.
365 void* custom = nullptr;
366
367 #if ALIB_DEBUG
368 /// The custom type attached. Used for asserting misuse in debug-compilations.
369 const std::type_info* dbgCustomType = nullptr;
370 #endif
371
372
373 public:
374 /// @return Retrieves the permissions of the entry.
375 [[nodiscard]] constexpr Permissions Perms () const noexcept { return bits.Permission; }
376 /// @return Retrieves the type of the entry
377 [[nodiscard]] constexpr Types Type () const noexcept { return bits.Type; }
378 /// @return Checks type for being either directory or symbolic link pointing to one.
379 [[nodiscard]] constexpr bool IsDirectory () const noexcept { return int(bits.Type) < 2; }
380 /// @return Checks type for being a symbolic link (to normal file or to a directory).
381 [[nodiscard]] constexpr bool IsSymbolicLink () const noexcept { return Type() == Types::SYMBOLIC_LINK
383 /// @return Retrieves the scan sate of the entry.
384 [[nodiscard]] constexpr ScanStates ScanState () const noexcept { return bits.ScanState ; }
385 /// @return Returns true if the entry resides on an artificial filesystem.
386 [[nodiscard]] constexpr bool IsArtificialFS () const noexcept { return bits.IsArtificialFS; }
387 /// @return Returns true if the entry is a symlink and its target resides on an artificial filesystem.
388 [[nodiscard]] constexpr bool TargetIsArtificialFS() const noexcept { return bits.TargetIsArtificialFS; }
389 /// @return Returns true if the entry resides on a different filesystem than it's parent.
390 [[nodiscard]] constexpr bool IsCrossingFS () const noexcept { return bits.IsCrossingFS; }
391 /// @return Returns true if the entry is a symlink and resides on a different filesystem than the link.
392 [[nodiscard]] constexpr bool TargetIsCrossingFS () const noexcept { return bits.TargetIsCrossingFS; }
393 /// @return Retrieves the file size.
394 [[nodiscard]] constexpr uinteger Size () const noexcept { return size; }
395 /// @return Retrieves the #"mDate;last modification date" of this file/folder.
396 [[nodiscard]] constexpr DateTime MDate () const noexcept { return mDate; }
397 /// @return Retrieves the #"bDate;birth date" of this file/folder.
398 [[nodiscard]] constexpr DateTime BDate () const noexcept { return bDate; }
399 /// @return Retrieves the #"cDate;change date" of this file/folder. If unavailable, same as #MDate.
400 [[nodiscard]] constexpr DateTime CDate () const noexcept { return cDate; }
401 /// @return Retrieves the #"aDate;timestamp of last access" to this file/folder. If unavailable, same as #MDate.
402 [[nodiscard]] constexpr DateTime ADate () const noexcept { return aDate; }
403 /// @return Retrieves the ID of the owner of the file/folder if available. Otherwise set to #UnknownID.
404 [[nodiscard]] constexpr uint32_t Owner () const noexcept { return owner; }
405 /// @return Retrieves the ID of the group of the file/folder if available. Otherwise set to #UnknownID.
406 [[nodiscard]] constexpr uint32_t Group () const noexcept { return group; }
407 /// @return Retrieves the number of hard links pointing to this file if available. Otherwise set to #UnknownID.
408 [[nodiscard]] constexpr uint32_t QtyHardLinks () const noexcept { return qtyHardLinks; }
409
410 /// Retrieves the extended info object of this entry.
411 /// @return The extended info object of this entry. If not available \c nullptr is returned.
412 [[nodiscard]] constexpr ExtendedEntryInfo* GetExtendedInfo() const { return extendedInfo; }
413
414 /// Sets the extended information object. As with all set functions, this method should only
415 /// be used from certain code entities, like file scanners. If used, the object passed here
416 /// has to be pool-allocated using public instance #"FTree::Pool;*".
417 /// The object will be freed with the deletion of the corresponding string tree node
418 /// (respectively \b File instance).
419 /// @param extInfo A pointer to the information object to use.
420 constexpr void SetExtendedInfo(ExtendedEntryInfo* extInfo) { extendedInfo= extInfo; }
421
422 /// Retrieves the directory sums of this directory or symbolic link to directory.
423 /// @return A reference to the sums.
424 [[nodiscard]] constexpr DirectorySums& Sums() const {
425 #if ALIB_DEBUG && !ALIB_DEBUG_ASSERTION_PRINTABLES
426 ALIB_ASSERT_ERROR( IsDirectory(), "FILES",
427 "Requesting sums for FInfo that is not a directory.")
428 ALIB_ASSERT_ERROR( extendedInfo != nullptr, "FILES",
429 "Requesting sums for FInfo that has no sums set. ScanState: ", ScanState() )
430 #endif
432 return static_cast<EIDirectory*>(extendedInfo)->Sums;
433 return static_cast<EISymLinkDir*>(extendedInfo)->Sums;
434 }
435
436 /// Sets the sums of the extended info object of this entry.
437 /// @param sums The sums to set.
438 constexpr void SetSums(const DirectorySums& sums) const {
439 if( Type() == FInfo::Types::DIRECTORY ) {
440 static_cast<EIDirectory*>(extendedInfo)->Sums= sums;
441 return;
442 }
443
445 "Given node is not a directory or symbolic link pointing to a directory.")
446
447 static_cast<EISymLinkDir*>(extendedInfo)->Sums= sums;
448 }
449
450 /// Stores the link targets in the extended information object created for symbolic links.
451 /// @param tree The tree that this object belongs to.
452 /// @param target The target as stored in the symlink
453 /// @param realTarget The translated, 'real' target path (if not broken).
454 void SetLinkTarget(FTree& tree, const system::PathString& target,
455 const system::PathString& realTarget);
456
457 /// Retrieves the non-translated target of a symbolic link. In debug compilations, the method
458 /// asserts that #Type returns either #"Types::SYMBOLIC_LINK"
459 /// or #"Types::SYMBOLIC_LINK_DIR".
460 /// @return A reference to a copy of the zero-terminated string stored in the symbolic link file.
461 [[nodiscard]] system::CPathString& GetLinkTarget() const noexcept {
464 "FILES", "Given node is not a symbolic link." )
465 return static_cast<EISymLinkFile*>(extendedInfo)->Target;
466 }
467
468 /// Retrieves the resolved target of a symbolic link. In debug compilations, the method
469 /// asserts that #Type returns either #"Types::SYMBOLIC_LINK" or
470 /// #"Types::SYMBOLIC_LINK_DIR".
471 /// @return A reference to a zero-terminated string giving the translated real path that a
472 /// symbolic link points to.
473 [[nodiscard]] system::CPathString& GetRealLinkTarget() const noexcept {
476 "FILES", "Given node is not a symbolic link." )
477
478 return static_cast<EISymLinkFile*>(extendedInfo)->RealTarget;
479 }
480
481 /// Sets the permissions of the entry.
482 /// @param v The value to set.
483 void SetPerms (Permissions v) noexcept { bits.Permission= v; }
484
485 /// Sets the type of the entry.
486 /// @param v The value to set.
487 void SetType (Types v) noexcept { bits.Type= v; }
488
489 /// Sets the state of scan of the entry.
490 /// @param v The value to set.
491 void SetScanState (ScanStates v) noexcept { bits.ScanState= v; }
492
493 /// Mark the entry as residing on an artificial filesystem.
494 void SetArtificialFS() noexcept { bits.IsArtificialFS= true; }
495
496 /// Mark the entry as a symlink who's target is residing on an artificial filesystem.
497 void SetTargetArtificialFS() noexcept { bits.TargetIsArtificialFS=true; }
498
499 /// Mark the entry as residing on a different filesystem than its parent.
500 void SetCrossingFS() noexcept { bits.IsCrossingFS= true; }
501
502 /// Mark the entry as a symlink who's target is residing in a different filesystem than the symlink.
503 void SetTargetCrossingFS() noexcept { bits.TargetIsCrossingFS=true; }
504
505 /// Sets the file size.
506 /// @param v The value to set.
507 void SetSize (uinteger v) noexcept { size = v; }
508
509 /// Sets the #"mDate;last modification date" of this file/folder.
510 /// @param v The value to set.
511 void SetMDate (DateTime v) noexcept { mDate= v; }
512
513 /// Sets the #"bDate;birth date" of this file/folder.
514 /// @param v The value to set.
515 void SetBDate (DateTime v) noexcept { bDate= v; }
516
517 /// Sets the #"cDate;change date" of this file/folder.
518 /// @param v The value to set.
519 void SetCDate (DateTime v) noexcept { cDate= v; }
520
521 /// Sets the #"aDate;time of last access" of this file/folder.
522 /// @param v The value to set.
523 void SetADate (DateTime v) noexcept { aDate= v; }
524
525 /// Sets the ID of the owner of the file/folder.
526 /// @param v The value to set.
527 void SetOwner (uint32_t v) noexcept { owner= v; }
528
529 /// Sets the ID of the group of the file/folder.
530 /// @param v The value to set.
531 void SetGroup (uint32_t v) noexcept { group= v; }
532
533 /// Sets the number of hard links that point to this file.
534 /// @param v The value to set.
535 void SetQtyHardlinks(uint32_t v) noexcept { qtyHardLinks= v; }
536}; // class FInfo
537
538
539//==================================================================================================
540/// Helper-class to resolve owner and group ids to strings names. The class uses an instance of
541/// #"LRUCacheTable" of size 10 for each value to increase the performance of the
542/// lookup. Because of this and the fact that the returned string value is located in an internal
543/// member buffer, multithreaded invocations of members #GetOwnerName and #GetGroupName have to be
544/// protected against racing conditions. This is up to the user of the type.
545//==================================================================================================
547{
548 protected:
549
550 #if !defined( _WIN32)
551 /// The owner name cache.
552 mutable
554
555 /// The group name cache.
556 mutable
558 #endif
559
560 public:
561 #if DOXYGEN || !defined( _WIN32)
562 /// Constructor.
563 /// @param poolAllocator The allocator passed to the internal instances of type
564 /// #"LRUCacheTable".
566 : ownerCache(poolAllocator, 6,6)
567 , groupCache(poolAllocator, 6,6) {}
568 #else
570 #endif
571
572
573 #if DOXYGEN
574 /// Changes the capacity of the \b %LRUCacheTable for owner names, by calling
575 /// #"LRUCacheTable::Reserve;*".<br>
576 /// The default sizes with construction is \b 6 for both values.
577 /// @param numberOfLists The number of LRU-lists to use.
578 /// @param entriesPerList The maximum length of each cache list.
579 void SetOwnerCacheCapacity( integer numberOfLists, integer entriesPerList );
580
581 /// Changes the capacity of the \b %LRUCacheTable for owner names, by calling
582 /// #"LRUCacheTable::Reserve;*".<br>
583 /// The default sizes with construction is \b 6 for both values.
584 /// @param numberOfLists The number of LRU-lists to use.
585 /// @param entriesPerList The maximum length of each cache list.
586 void SetGroupCacheCapacity( integer numberOfLists, integer entriesPerList );
587 #elif !defined( _WIN32)
588 void SetOwnerCacheCapacity( integer numberOfLists, integer entriesPerList )
589 { ownerCache.Reserve( numberOfLists, entriesPerList ); }
590 void SetGroupCacheCapacity( integer numberOfLists, integer entriesPerList )
591 { groupCache.Reserve( numberOfLists, entriesPerList); }
592 #else //_WIN32:
595 #endif
596
597 /// Retrieves the file's owner's name.
598 /// @param fInfo The file to examine.
599 /// @return The name of the owner of the file.
601 const NString& GetOwnerName( const FInfo& fInfo ) const;
602
603 /// Retrieves the file's group name.
604 /// @param fInfo The file to examine.
605 /// @return The name of the group of the file.
607 const NString& GetGroupName( const FInfo& fInfo ) const;
608}; //class OwnerAndGroupResolver
609
610} // namespace alib[::files]
611
612
613/// Type alias in namespace \b alib.
615
616/// Type alias in namespace \b alib.
618
619} // namespace [alib]
620
631ALIB_RESOURCED_IN_CAMP(alib::files::FInfo::TypeNames1Letter , alib::FILES, "FT1" )
632ALIB_RESOURCED_IN_CAMP(alib::files::FInfo::TypeNames2Letters , alib::FILES, "FT2" )
633ALIB_RESOURCED_IN_CAMP(alib::files::FInfo::TypeNames3Letters , alib::FILES, "FT3" )
634ALIB_RESOURCED_IN_CAMP(alib::files::FInfo::ScanStates , alib::FILES, "FQ" )
635ALIB_RESOURCED_IN_CAMP(alib::files::FInfo::ScanStates3Letters , alib::FILES, "FQ3" )
636
637
638ALIB_BOXING_VTABLE_DECLARE( alib::files::FInfo::Permissions , vt_files_perms )
639ALIB_BOXING_VTABLE_DECLARE( alib::files::FInfo::Types , vt_files_type )
640ALIB_BOXING_VTABLE_DECLARE( alib::files::FInfo::TypeNames1Letter , vt_files_type1 )
641ALIB_BOXING_VTABLE_DECLARE( alib::files::FInfo::TypeNames2Letters , vt_files_type2 )
642ALIB_BOXING_VTABLE_DECLARE( alib::files::FInfo::TypeNames3Letters , vt_files_type3 )
643ALIB_BOXING_VTABLE_DECLARE( alib::files::FInfo::ScanStates , vt_files_qual )
644ALIB_BOXING_VTABLE_DECLARE( alib::files::FInfo::ScanStates3Letters , vt_files_qual3 )
#define ALIB_DLL
Definition alib.inl:573
#define ALIB_EXPORT
Definition alib.inl:562
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1144
#define ALIB_BOXING_VTABLE_DECLARE(TMapped, Identifier)
#define ALIB_RESOURCED_IN_CAMP(T, Camp, ResName)
void Reserve(integer newQtyLists, integer newQtyEntriesPerList)
The entry type which is embedded in each tree node.
Definition finfo.inl:15
void SetType(Types v) noexcept
Definition finfo.inl:487
system::CPathString & GetRealLinkTarget() const noexcept
Definition finfo.inl:473
void SetCrossingFS() noexcept
Mark the entry as residing on a different filesystem than its parent.
Definition finfo.inl:500
void SetScanState(ScanStates v) noexcept
Definition finfo.inl:491
ScanStates
Per-entry information about how a node was scanned.
Definition finfo.inl:125
@ RECURSIVE
Follow symlink target strings.
Definition finfo.inl:137
@ STATS
Only stats (size, date, owner, etc.) read.
Definition finfo.inl:127
@ NO_ACCESS_DIR
Scanner failure due to limited access rights on a directory.
Definition finfo.inl:142
@ MAX_DEPTH_REACHED
Scanning stopped because maximum depth was reached.
Definition finfo.inl:131
@ RESOLVED
Read symlink target strings.
Definition finfo.inl:129
@ NO_ACCESS_SL
Scanner failure due to limited access rights on a symbolic link.
Definition finfo.inl:140
@ UNKNOWN_ERROR
Unknown scanner failure.
Definition finfo.inl:151
@ BROKEN_LINK
A symbolic link targets a non-existent file or directory.
Definition finfo.inl:143
@ NO_ACCESS_SL_TARGET
Scanner failure due to limited access rights on a symbolic link's target.
Definition finfo.inl:141
@ NOT_FOLLOWED
A symbolic link that targets a directory, but scan parameters specify not to follow.
Definition finfo.inl:132
@ NO_ACCESS
Scanner failure due to limited access rights.
Definition finfo.inl:139
@ NOT_EXISTENT
Set if a given start path does not exist.
Definition finfo.inl:150
void SetOwner(uint32_t v) noexcept
Definition finfo.inl:527
constexpr uint32_t Group() const noexcept
Definition finfo.inl:406
constexpr Types Type() const noexcept
Definition finfo.inl:377
constexpr DateTime ADate() const noexcept
Definition finfo.inl:402
constexpr bool IsArtificialFS() const noexcept
Definition finfo.inl:386
void SetADate(DateTime v) noexcept
Definition finfo.inl:523
constexpr ExtendedEntryInfo * GetExtendedInfo() const
Definition finfo.inl:412
void * custom
Pool-allocated custom data.
Definition finfo.inl:365
void SetTargetCrossingFS() noexcept
Mark the entry as a symlink who's target is residing in a different filesystem than the symlink.
Definition finfo.inl:503
void SetSize(uinteger v) noexcept
Definition finfo.inl:507
constexpr bool IsCrossingFS() const noexcept
Definition finfo.inl:390
void SetTargetArtificialFS() noexcept
Mark the entry as a symlink who's target is residing on an artificial filesystem.
Definition finfo.inl:497
const std::type_info * dbgCustomType
The custom type attached. Used for asserting misuse in debug-compilations.
Definition finfo.inl:369
constexpr bool TargetIsCrossingFS() const noexcept
Definition finfo.inl:392
void SetQtyHardlinks(uint32_t v) noexcept
Definition finfo.inl:535
constexpr DateTime MDate() const noexcept
Definition finfo.inl:396
uint32_t qtyHardLinks
The number of hard links to the file.
Definition finfo.inl:335
constexpr bool IsDirectory() const noexcept
Definition finfo.inl:379
constexpr uinteger Size() const noexcept
Definition finfo.inl:394
void SetGroup(uint32_t v) noexcept
Definition finfo.inl:531
void SetCDate(DateTime v) noexcept
Definition finfo.inl:519
void SetArtificialFS() noexcept
Mark the entry as residing on an artificial filesystem.
Definition finfo.inl:494
constexpr uint32_t QtyHardLinks() const noexcept
Definition finfo.inl:408
void SetPerms(Permissions v) noexcept
Definition finfo.inl:483
uint32_t owner
The user id that owns the file.
Definition finfo.inl:333
uint32_t group
The group id that owns the file.
Definition finfo.inl:334
system::CPathString & GetLinkTarget() const noexcept
Definition finfo.inl:461
void SetLinkTarget(FTree &tree, const system::PathString &target, const system::PathString &realTarget)
Definition finfo.cpp:42
constexpr uint32_t Owner() const noexcept
Definition finfo.inl:404
constexpr bool IsSymbolicLink() const noexcept
Definition finfo.inl:381
uint32_t TOwnerAndGroupID
Type definition for owner and group ids.
Definition finfo.inl:118
constexpr DateTime BDate() const noexcept
Definition finfo.inl:398
Bits bits
A bitfield encoding various information.
Definition finfo.inl:359
constexpr void SetSums(const DirectorySums &sums) const
Definition finfo.inl:438
uinteger symParent
Definition finfo.inl:330
constexpr DateTime CDate() const noexcept
Definition finfo.inl:400
static constexpr TOwnerAndGroupID UnknownID
Constant value for owner and group IDs to denote that the field was not determined.
Definition finfo.inl:121
@ MARKER_TYPES_END
A marker for the last countable type. The rest are unused/errors.
Definition finfo.inl:41
@ DIRECTORY
Directory/folder.
Definition finfo.inl:28
@ CHARACTER
A character special file.
Definition finfo.inl:35
@ BLOCK
A block special file.
Definition finfo.inl:34
@ SOCKET
A socket file.
Definition finfo.inl:37
@ REGULAR
Regular file.
Definition finfo.inl:31
@ FIFO
A FIFO (also known as pipe) file.
Definition finfo.inl:36
constexpr Permissions Perms() const noexcept
Definition finfo.inl:375
constexpr bool TargetIsArtificialFS() const noexcept
Definition finfo.inl:388
uinteger size
The file size. In case of a directory, this is 0.
Definition finfo.inl:332
void SetBDate(DateTime v) noexcept
Definition finfo.inl:515
constexpr ScanStates ScanState() const noexcept
Definition finfo.inl:384
constexpr DirectorySums & Sums() const
Definition finfo.inl:424
constexpr void SetExtendedInfo(ExtendedEntryInfo *extInfo)
Definition finfo.inl:420
Permissions
Permission flags. Compatible with posix* definition.
Definition finfo.inl:91
@ MASK
All valid permission bits. Equivalent to all | set_uid | set_gid | sticky_bit.
Definition finfo.inl:94
@ GROUP_READ
Posix S_IRGRP: The file's user group has read permission.
Definition finfo.inl:102
@ OTHERS_ALL
Posix S_IRWXO: Other users have read, write, and execute/search permissions Equivalent to others_read...
Definition finfo.inl:110
@ GROUP_EXEC
Posix S_IXGRP: The file's user group has execute/search permission.
Definition finfo.inl:104
@ OTHERS_EXEC
Posix S_IXOTH: Other users have execute/search permission.
Definition finfo.inl:109
@ GROUP_WRITE
Posix S_IWGRP: The file's user group has write permission.
Definition finfo.inl:103
@ ALL
All users have read, write, and execute/search permissions Equivalent to owner_all | group_all | othe...
Definition finfo.inl:95
@ UNKNOWN
Unknown permissions (e.g., when not read, or filesystem does not support permissions).
Definition finfo.inl:93
@ OWNER_ALL
Posix S_IRWXU: File owner has read, write, and execute/search permissions Equivalent to owner_read | ...
Definition finfo.inl:100
@ OWNER_READ
Posix S_IRUSR: File owner has read permission.
Definition finfo.inl:97
@ STICKY_BIT
Posix S_ISVTX: Implementation-defined meaning, but POSIX XSI specifies that when set on a directory,...
Definition finfo.inl:114
@ SET_UID
Posix S_ISUID: Set user ID to file owner user ID on execution.
Definition finfo.inl:112
@ OWNER_EXEC
Posix S_IXUSR: File owner has execute/search permission.
Definition finfo.inl:99
@ SET_GID
Posix S_ISGID: Set group ID to file's user group ID on execution.
Definition finfo.inl:113
@ NONE
no permission bits are set
Definition finfo.inl:92
@ OWNER_WRITE
Posix S_IWUSR: File owner has write permission.
Definition finfo.inl:98
@ OTHERS_READ
Posix S_IROTH: Other users have read permission.
Definition finfo.inl:107
@ OTHERS_WRITE
Posix S_IWOTH: Other users have write permission.
Definition finfo.inl:108
@ GROUP_ALL
Posix S_IRWXG: The file's user group has read, write, and execute/search permissions Equivalent to gr...
Definition finfo.inl:105
ExtendedEntryInfo * extendedInfo
Extended information, depending on the entry type.
Definition finfo.inl:362
void SetMDate(DateTime v) noexcept
Definition finfo.inl:511
const NString & GetOwnerName(const FInfo &fInfo) const
Definition finfo.cpp:69
const NString & GetGroupName(const FInfo &fInfo) const
Definition finfo.cpp:84
void SetGroupCacheCapacity(integer numberOfLists, integer entriesPerList)
void SetOwnerCacheCapacity(integer numberOfLists, integer entriesPerList)
OwnerAndGroupResolver(PoolAllocator &poolAllocator)
Definition finfo.inl:565
#define ALIB_ENUMS_MAKE_BITWISE(TEnum)
#define ALIB_ENUMS_MAKE_ITERABLE(TEnum, StopElement)
#define ALIB_ENUMS_ASSIGN_RECORD(TEnum, TRecord)
strings::TCString< PathCharType > CPathString
The string-type used with this ALib Module.
Definition path.inl:36
strings::TString< PathCharType > PathString
The string-type used with this ALib Module.
Definition path.inl:33
strings::TString< nchar > NString
Type alias in namespace alib.
Definition string.inl:2181
files::FInfo FInfo
Type alias in namespace alib.
Definition finfo.inl:614
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
monomem::TPoolAllocator< MonoAllocator > PoolAllocator
files::OwnerAndGroupResolver OwnerAndGroupResolver
Type alias in namespace alib.
Definition finfo.inl:617
files::FilesCamp FILES
The singleton instance of ALib Camp class #"FilesCamp".
Definition filescamp.cpp:47
containers::LRUCacheTable< TAllocator, containers::TPairDescriptor< TKey, TMapped > > LRUCacheMap
Type alias in namespace alib.
lang::uinteger uinteger
Type alias in namespace alib.
Definition integers.inl:152
time::DateTime DateTime
Type alias in namespace alib.
Definition datetime.inl:185
A bitfield encoding various information.
Definition finfo.inl:339
bool TargetIsCrossingFS
Denotes whether a link points to a mount point.
Definition finfo.inl:344
ScanStates ScanState
The scan state.
Definition finfo.inl:346
bool IsArtificialFS
Denotes whether the file resides in an artificial filesystem.
Definition finfo.inl:341
bool TargetIsArtificialFS
Denotes whether a link points into an artificial filesystem.
Definition finfo.inl:342
Bits()
Default constructor. Sets all members to NONE, false or Error.
Definition finfo.inl:349
bool IsCrossingFS
Denotes whether the file is a mount point.
Definition finfo.inl:343
Permissions Permission
The unix file-permissions.
Definition finfo.inl:345
Types Type
The file type.
Definition finfo.inl:340
Recursively accumulated values for directories.
Definition finfo.inl:189
uinteger Size
The cumulated sizes of all files and directories.
Definition finfo.inl:190
uint32_t QtyErrsAccess
Number of access errors in the folder and subfolders.
Definition finfo.inl:192
constexpr bool IsDirType(Types type) const noexcept
Definition finfo.inl:236
uint32_t CountNonDirectories() const noexcept
Definition finfo.inl:279
uint32_t QtyErrsBrokenLink
Number of broken symbolic links in the directory and its subfolders.
Definition finfo.inl:193
DirectorySums & operator-=(const DirectorySums &rhs)
Definition finfo.inl:218
uint32_t CountDirectories() const noexcept
Definition finfo.inl:270
uint32_t Count() const noexcept
Definition finfo.inl:250
uint32_t Count(Types type) const noexcept
Definition finfo.inl:260
uint32_t QtyStopsOnCircularLinks
Number of recursion aborts due to detected circular links reach of maximum recursion depth.
Definition finfo.inl:195
uint32_t QtyStopsOnMaxDepth
Number of recursion aborts due to reach of maximum recursion depth.
Definition finfo.inl:194
std::array< uint32_t, size_t(Types::MARKER_TYPES_END)> TypeCounters
Per-type counters.
Definition finfo.inl:191
constexpr DirectorySums() noexcept=default
Defaulted default constructor.
constexpr DirectorySums & Add(const FInfo &finfo) noexcept
Definition finfo.inl:241
DirectorySums Sums
The recursive sums evaluated during scan.
Definition finfo.inl:296
DirectorySums Sums
The recursive sums evaluated during scan.
Definition finfo.inl:314
system::CPathString RealTarget
The resolved real target path.
Definition finfo.inl:306
system::CPathString Target
Definition finfo.inl:304
Base type to create pointers to different extended entry information structs.
Definition finfo.inl:290