ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
finfo.hpp
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-2024 A-Worx GmbH, Germany.
6 * Published under \ref mainpage_license "Boost Software License".
7 **************************************************************************************************/
8#ifndef HPP_ALIB_FILES_FINFO
9#define HPP_ALIB_FILES_FINFO 1
10
11#if !defined (HPP_ALIB_FILES_CAMP)
13#endif
14
15#if !defined(HPP_ALIB_CAMP_MESSAGE_REPORT)
17#endif
18
19#if !defined (HPP_ALIB_LANG_SIDILIST)
20# include "alib/lang/sidilist.hpp"
21#endif
22
23#if !defined (HPP_ALIB_TIME_DATETIME)
24# include "alib/time/datetime.hpp"
25#endif
26
27#if !defined (HPP_ALIB_ENUMS_ITERABLE)
29#endif
30
31
32namespace alib { namespace files {
33
34/** Local path string buffer helper type fixed to size 512. The flexible nature of \alib local
35 * strings allow dynamic allocation if exceeded.*/
37
38/**
39 * The entry type which is embedded in each tree node.
40 */
41class FInfo
42{
43 public:
44 /** Enumeration of the possible file types. This is compatible with the posix list of types,
45 * with the exclamation that symbolic links are differentiated between those linking to
46 * a directory and those linking to any other file type.*/
47 enum class Types : int8_t
48 {
49 DIRECTORY = 0, ///< Directory/folder.
50 SYMBOLIC_LINK_DIR = 1, ///< Symbolic link targeting a directory.
51 ///< In case scanning does not resolve links, this is never set.
52 REGULAR = 2, ///< Regular file.
53 SYMBOLIC_LINK = 3, ///< Symbolic link targeting a non-directory file.
54 ///< In case scanning does not resolve links, possibly to a directory.
55 BLOCK = 4, ///< A block special file.
56 CHARACTER = 5, ///< A character special file.
57 FIFO = 6, ///< A FIFO (also known as pipe) file.
58 SOCKET = 7, ///< A socket file.
59
60 MARKER_TYPES_END = 8, ///< A marker for the last countable type. The rest are unused/errors
61
62 UNKNOWN_OR_ERROR = 8, ///< Filetype (should never or seldom happen).
63 ///< Maybe filesystem changed during scan or similar strange thing.
64 };
65
66 /** Permission flags. Compatible with posix* definition. */
67 enum class Permissions : int32_t
68 {
69 NONE = 0, ///< no permission bits are set
70 UNKNOWN = 0xFFFF, ///< Unknown permissions (e.g. when not read or filesystem does not support permissions)
71 MASK = 07777, ///< All valid permission bits. Equivalent to all | set_uid | set_gid | sticky_bit
72 ALL = 0777, ///< All users have read, write, and execute/search permissions Equivalent to owner_all | group_all | others_all
73
74 OWNER_READ = 0400, /// < S_IRUSR File owner has read permission
75 OWNER_WRITE = 0200, /// < S_IWUSR File owner has write permission
76 OWNER_EXEC = 0100, /// < S_IXUSR File owner has execute/search permission
77 OWNER_ALL = 0700, /// < S_IRWXU File owner has read, write, and execute/search permissions Equivalent to owner_read | owner_write | owner_exec
78
79 GROUP_READ = 040, /// < S_IRGRP The file's user group has read permission
80 GROUP_WRITE = 020, /// < S_IWGRP The file's user group has write permission
81 GROUP_EXEC = 010, /// < S_IXGRP The file's user group has execute/search permission
82 GROUP_ALL = 070, /// < S_IRWXG The file's user group has read, write, and execute/search permissions Equivalent to group_read | group_write | group_exec
83
84 OTHERS_READ = 04, ///< S_IROTH Other users have read permission
85 OTHERS_WRITE = 02, ///< S_IWOTH Other users have write permission
86 OTHERS_EXEC = 01, ///< S_IXOTH Other users have execute/search permission
87 OTHERS_ALL = 07, ///< S_IRWXO Other users have read, write, and execute/search permissions Equivalent to others_read | others_write | others_exec
88
89 SET_UID = 04000, ///< S_ISUID Set user ID to file owner user ID on execution
90 SET_GID = 02000, ///< S_ISGID Set group ID to file's user group ID on execution
91 STICKY_BIT = 01000, ///< 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)
92 };
93
94 /** Type definition for owner and group ids */
95 using TOwnerAndGroupID = uint32_t;
96
97 /** Constant value for owner and group IDs to denote that the field was not determined. */
98 static constexpr TOwnerAndGroupID UnknownID= (std::numeric_limits<uint32_t>::max)();
99
100 /** Per-entry information about how a node was scanned. */
101 enum class Qualities
102 {
103 NONE = 0, ///< Node created only from given (real) start path.
104 STATS = 1, ///< Only stats (size, time, owner, etc.) read.
105
106 RESOLVED = 2, ///< Read symlink target strings.
107
108 MAX_DEPTH_REACHED = 3, ///< Scanner stopped, because maximum depth was reached.
109 NOT_FOLLOWED = 4, ///< A symbolic link that targets a directory, but scan parameters specify not to follow.
110 NOT_CROSSING_FS = 5, ///< A directory that represented a mounted filesystem was not followed due to field
111 NO_AFS = 6, ///< A directory that represented a mounted filesystem was not followed due to field
112 ///< \alib{files;ScanParameters::CrossFileSystems} being set to \c false.
113 RECURSIVE = 7, ///< Follow symlink target strings.
114
115 NO_ACCESS = 8, ///< Scanner failure due to limited access rights.
116 NO_ACCESS_SL = 9, ///< Scanner failure due to limited access rights.
117 NO_ACCESS_SL_TARGET=10, ///< Scanner failure due to limited access rights.
118 NO_ACCESS_DIR =11, ///< Scanner failure due to limited access rights.
119 BROKEN_LINK =12, ///< A symbolic link targets a non-existent file or directory.
120 CIRCULAR_LINK =13, ///< Set if recursion stopped on a symbolic link which was identified by the
121 ///< operating system as a circular link.
122 DUPLICATE =14, ///< Set if recursion stopped on a symbolic link who's target had been scanned already.
123 ///< This might happen either because the path was already scanned by another search, or
124 ///< because a symbolic link is circular or because of a mixture of both.
125 ///< Thus, this can indicate a circular link, but does not have to.
126 NOT_EXISTENT =15, ///< Set if a given start path does not exist.
127 UNKNOWN_ERROR =16, ///< Unknown scanner failure
128 };
129
130
131
132 /** Recursively accumulated values for directories. */
134 {
136 uinteger Size = 0; ///< The cumulated sizes of all files and directories.
137 uint32_t TypeCounters[int(Types::MARKER_TYPES_END)]= {0,0,0,0,0,0,0,0}; ///< Per-type counters.
138 uint32_t QtyErrsAccess = 0; ///< Number of access errors in the folder and sub-folders.
139 uint32_t QtyErrsBrokenLink = 0; ///< Number of broken symbolic links in the directory and its sub-folders.
140 uint32_t QtyStopsOnMaxDepth = 0; ///< Number of recursion aborts due to reach of maximum recursion depth.
141 uint32_t QtyStopsOnCircularLinks = 0; ///< Number of recursion aborts due to detected circular links reach of maximum recursion depth.
142
143
144 /** Defaulted default constructor. */
145 constexpr DirectorySums() noexcept = default;
146
147 /** Adds the values in the given summary object to this.
148 * @param rhs The values to add.
149 * @return A reference to <c>this</c> */
150 DirectorySums& operator+= (const DirectorySums& rhs)
151 {
152 Size += rhs.Size ;
153 for (int i = 0; i < int(Types::MARKER_TYPES_END); ++i)
154 TypeCounters[i]+= rhs.TypeCounters[i];
155 QtyErrsAccess += rhs.QtyErrsAccess ;
156 QtyErrsBrokenLink += rhs.QtyErrsBrokenLink ;
157 QtyStopsOnMaxDepth += rhs.QtyStopsOnMaxDepth;
158 QtyStopsOnCircularLinks+= rhs.QtyErrsBrokenLink ;
159 return *this;
160 }
161
162 /** Subtracts the values in the given summary object from this.
163 * @param rhs The values to subtract.
164 * @return A reference to <c>this</c> */
166 {
167 Size -= rhs.Size ;
168 for (int i = 0; i < int(Types::MARKER_TYPES_END); ++i)
169 TypeCounters[i]-= rhs.TypeCounters[i];
174 return *this;
175 }
176 /** Returns \c true if the given \p{type} equals either
177 * \alib{files::FInfo;Types::DIRECTORY} or
178 * \alib{files::FInfo;Types::SYMBOLIC_LINK_DIR}
179 * @param type returns \c false if the given type does not represent a directory
180 * and \c true if \p{type} equals
181 * \alib{files::FInfo;Types::DIRECTORY} or
182 * \alib{files::FInfo;Types::SYMBOLIC_LINK_DIR}
183 * @return \c false if the given type does not represent a directory, \c true otherwise. */
184 constexpr bool IsDirType(Types type) const noexcept
185 {
186 return int(type) < 2;
187 }
188
189 /** Adds a file/directory to the counters
190 * @param finfo The entry to add.
191 * @return A reference to <c>this</c> */
192 constexpr DirectorySums& Add(const FInfo& finfo) noexcept
193 {
194 ++TypeCounters[int(finfo.Type())];
195 Size+= finfo.Size();
196 return *this;
197 }
198
199
200 /** Returns the cumulated number of entries (of any type).
201 * @return The number of entries counted. */
202 uint32_t Count() const noexcept
203 {
204 uint32_t result= 0;
205 for (int i = 0; i < int(Types::MARKER_TYPES_END); ++i)
206 result+= TypeCounters[i];
207 return result;
208 }
209
210 /** Returns the number of entries of the given \p{type}.
211 * @param type The type to get the number of entries for.
212 * @return The number of directories or symbolic links to directories. */
213 uint32_t Count(Types type) const noexcept
214 {
216 "CAMP/FILES", "Cant get count for file type {!Q}", type )
217 return TypeCounters[int(type)];
218 }
219
220 /** Returns the sum of the number of entries of type
221 * \alib{files::FInfo;Types::DIRECTORY} and
222 * \alib{files::FInfo;Types::SYMBOLIC_LINK_DIR}
223 * @return The number of directories or symbolic links to directories. */
224 uint32_t CountDirectories() const noexcept
225 {
226 return TypeCounters[int(Types::DIRECTORY)]
228 }
229
230 /** Returns the sum of the number of entries which are \b not of type
231 * \alib{files::FInfo;Types::DIRECTORY} and
232 * \alib{files::FInfo;Types::SYMBOLIC_LINK_DIR}
233 * @return The number of regular files, fifo, sockets, etc. */
234 uint32_t CountNonDirectories() const noexcept
235 {
236 uint32_t result= 0;
237 for (int i = 2; i < int(Types::MARKER_TYPES_END); ++i)
238 result+= TypeCounters[i];
239 return result;
240 }
242 };
243
244 /** Base type to create pointers to different extended entry information structs. */
246 {};
247
248 /** Additional information for entries of directory-type. Allocated in the tree's
249 * \alib{monomem;MonoAllocator} and accessible via #GetExtendedInfo() and #Sums. */
251 {
252 DirectorySums Sums; ///< The recursive sums evaluated during scan.
253 };
254
255 /** Additional information for entries of symlink-type. Allocated in the tree's
256 * \alib{monomem;MonoAllocator} and accessible via #GetExtendedInfo(),
257 * #GetLinkTarget and #GetRealLinkTarget. */
259 {
260 protected:
261 friend class FInfo;
262 static constexpr integer InternalBufSize= 128; ///< The defined size of the internal buffer.
263 character internalBuf[InternalBufSize]; ///< An internal buffer. If exceeded, a dynamic
264 ///< allocation is performed to store the links.
265
266 public:
267 CString Target; ///< The target path. This is a zero-terminated \b CString.
268 CString RealTarget; ///< The resolved real target path.
269 };
270
271 /** Additional information for entries of symbolic link type. Allocated in the tree's
272 * \alib{monomem;MonoAllocator} and accessible via #GetExtendedInfo(), #GetLinkTarget,
273 * #GetRealLinkTarget and #Sums. */
275 {
276 DirectorySums Sums; ///< The recursive sums evaluated during scan.
277 };
278
279 protected:
280 /**
281 * This type is used to add a list of custom data object to entries in \alib{files;FTree}.
282 * @see Methods #AddCustomData and #GetCustomData.
283 */
284 struct InfoBox : public lang::SidiNodeBase<InfoBox>
285 {
286 Box data; ///< The custom data.
287
288 /** Constructor taking (and auto-boxing) any custom information.
289 * @param pData Custom information that is automatically boxed. */
290 explicit InfoBox( const Box& pData )
291 : SidiNodeBase()
292 , data(pData)
293 {}
294 };
295
296 DateTime mTime ; ///< The last write time. (Always available.)
297 DateTime cTime ; ///< The time of creation. This is not always available,
298 ///< depends on operating- and filesystem.
299 DateTime aTime ; ///< The time of last access. This is not always available,
300 ///< depends on operating- and filesystem.
301 uinteger size ; ///< The file size. In case of a directory, this is \c 0.
302 uint32_t owner ; ///< The user id that owns the file.
303 uint32_t group ; ///< The group id that owns the file.
304
305 /** Bits encoding the following information:
306 * 0 - 3: Type
307 * 4: IsArtificialFS
308 * 5: TargetIsArtificialFS
309 * 6: IsCrossingFS
310 * 7: TargetIsCrossingFS
311 * 8 - 23: Perms
312 * 24 - 31: Quality */
313 uint32_t bits ;
314
315 ExtendedEntryInfo* extendedInfo; ///< Extended information, depending on the entry type.
316 lang::SidiListHelper<InfoBox> custom; ///< A list of boxed custom data objects.
317
318
319public:
320 /** Constructor providing no values. Only sets ScanQuality::NONE */
322 : bits(0)
323 , extendedInfo(nullptr)
324 {}
325
326 /**
327 * This method, together with #GetCustomData, provides a simple mechanism to attach
328 * some custom information to an entry in \b FTree.
329 *
330 * The allocator of the \b FTree object has to be provided as a parameter, as it
331 * is otherwise not reachable from within this entry object. While this might also
332 * be some other, external allocator, it is not easily thinkable of a use case for this.
333 *
334 * Note that any object that does not fit as a value into the \alib{boxing;Box} is
335 * simply stored as a pointer. No copy is created! Therefore such object has to
336 * be allocated persistent. Usually, such objects are created in the same
337 * \p{monoAllocator} as given, right before the invocation of this method.
338 *
339 *
340 * @see Method #GetCustomData.<br>
341 * For more information on class \b box, see Programmer's Manual of module
342 * \alib_boxing.
343 * @param monoAllocator Usually, the allocator of the \b FTree object that this entry
344 * belongs to and as such received with
345 * <b>FTree::GetAllocator()</b>.
346 * @param data The data to attach.
347 */
348 void AddCustomData(MonoAllocator* monoAllocator, Box data)
349 {
350 auto* infoNode = monoAllocator->Emplace<FInfo::InfoBox>( data );
351 custom.pushFront(infoNode);
352 }
353
354 /**
355 * This method, together with #AddCustomData, provides a simple mechanism to attach
356 * and retrieve some custom information to an entry in \b FTree
357 *
358 * Custom data is stored in a single-linked list. This class does not provide an
359 * iterator for the data, because the application has to assure for itself
360 * how many custom data objects are placed in which order!
361 * Usually, only one custom object should be stored.
362 *
363 * @see Method #AddCustomData.
364 * @param idx The sequence number of the stored custom boxed element.
365 * @return The boxed value. In case given \p{idx} is greater (or equal) to the number
366 * of stored custom elements, a nulled box is returned.
367 */
369 {
370 auto* list= custom.first();
371 for(;;)
372 {
373 if( list == nullptr ) return Box();
374 if( idx == 0 ) return list->data;
375 list= list->next();
376 --idx;
377 }
378 }
379
380 /**
381 * Alternative version of method #GetCustomData(int idx), which searches the
382 * attached list of boxes for a first one that contains custom data of type \p{T}.
383 *
384 * @see Method #AddCustomData.
385 * @tparam T The custom type to search for in the attached list of data.
386 * @return The (still) boxed value. In case no box with an object of type \p{T} is
387 * found, a nulled box is returned.
388 *
389 */
390 template<typename T>
392 {
393 auto* list= custom.first();
394 while(list!= nullptr)
395 {
396 if( list->data.IsType<T>() )
397 return list->data;
398 list= list->next();
399 }
400 }
401
402
403
404 /** @return Retrieves the permissions of the entry. */
405 [[nodiscard]] constexpr Permissions Perms () const noexcept { return Permissions( (bits >> 8) & 0xFFFF); }
406 /** @return Retrieves the type of the entry */
407 [[nodiscard]] constexpr Types Type () const noexcept { return Types ( bits & 0xF); }
408 /** @return Checks type for being either directory or symbolic link pointing to one.*/
409 [[nodiscard]] constexpr bool IsDirectory () const noexcept { return ( bits & 0xE) == 0; }
410 /** @return Checks type for being a symbolic link (to normal file or to a directory). */
411 [[nodiscard]] constexpr bool IsSymbolicLink () const noexcept { return Type() == Types::SYMBOLIC_LINK
413 /** @return Retrieves the scan quality of the entry. */
414 [[nodiscard]] constexpr Qualities Quality () const noexcept { return static_cast<Qualities>( (bits >> 24) & 0xF); }
415 /** @return Returns true if the entry resides on an artificial filesystem. */
416 [[nodiscard]] constexpr bool IsArtificialFS () const noexcept { return (bits & (uint32_t(1) << 4)) != 0; }
417 /** @return Returns true if the entry is a symlink and its target resides on an artificial filesystem. */
418 [[nodiscard]] constexpr bool TargetIsArtificialFS() const noexcept { return (bits & (uint32_t(1) << 5)) != 0; }
419 /** @return Returns true if the entry resides on a different filesystem than it's parent. */
420 [[nodiscard]] constexpr bool IsCrossingFS () const noexcept { return (bits & (uint32_t(1) << 6)) != 0; }
421 /** @return Returns true if the entry is a symlink and resides on a different filesystem than the link. */
422 [[nodiscard]] constexpr bool TargetIsCrossingFS () const noexcept { return (bits & (uint32_t(1) << 7)) != 0; }
423 /** @return Retrieves the file size. */
424 [[nodiscard]] constexpr uinteger Size () const noexcept { return size; }
425 /** @return Retrieves the last modification time of the file/folder. */
426 [[nodiscard]] constexpr DateTime MTime () const noexcept { return mTime; }
427 /** @return Retrieves the creation time of the file/folder. If unavailable, same as #MTime. */
428 [[nodiscard]] constexpr DateTime CTime () const noexcept { return cTime; }
429 /** @return Retrieves the time of last access to the file/folder. If unavailable, same as #MTime. */
430 [[nodiscard]] constexpr DateTime ATime () const noexcept { return aTime; }
431 /** @return Retrieves the ID of the owner of the file/folder if available. Otherwise set to #UnknownID. */
432 [[nodiscard]] constexpr uint32_t Owner () const noexcept { return owner; }
433 /** @return Retrieves the ID of the group of the file/folder if available. Otherwise set to #UnknownID. */
434 [[nodiscard]] constexpr uint32_t Group () const noexcept { return group; }
435
436 /** Retrieves the extended info object of this entry.
437 * @return The extended info object of this entry. If not available \c nullptr is returned. */
438 [[nodiscard]] constexpr ExtendedEntryInfo* GetExtendedInfo() const
439 { return extendedInfo; }
440
441 /** Sets the externally allocated extended information object.
442 * @param extInfo A pointer to the information object to use. */
443 constexpr void SetExtendedInfo(ExtendedEntryInfo* extInfo)
444 { extendedInfo= extInfo; }
445
446 /** Retrieves the directory sums of this directory or symbolic link to directory.
447 * @return A reference to the sums. */
448 [[nodiscard]] constexpr DirectorySums& Sums() const
449 {
450 ALIB_ASSERT_ERROR( IsDirectory(), "CAMP/FILES",
451 "Requesting sums for FInfo that is not a directory.")
452 ALIB_ASSERT_ERROR( extendedInfo != nullptr, "CAMP/FILES",
453 "Requesting sums for FInfo that has no sums set. Quality: ", Quality() )
455 return static_cast<EIDirectory*>(extendedInfo)->Sums;
456 return static_cast<EISymLinkDir*>(extendedInfo)->Sums;
457 }
458
459 /** Sets the sums of the extended info object of this entry.
460 * @param sums The sums to set. */
461 constexpr void SetSums(const DirectorySums& sums) const
462 {
464 {
465 static_cast<EIDirectory*>(extendedInfo)->Sums= sums;
466 return;
467 }
468
470 "Given node is not a directory or symbolic link pointing to a directory.")
471
472 static_cast<EISymLinkDir*>(extendedInfo)->Sums= sums;
473 }
474
475 /**
476 * Stores the link targets in the extended information object created for symbolic links.
477 * @param target The target as stored in the symlink
478 * @param realTarget The translated, 'real' target path (if not broken).
479 */
480 void SetLinkTarget(const String& target, const String& realTarget);
481
482 /** Retrieves the non-translated target of a symbolic link. In debug compilations, the method
483 * asserts that #Type returns either \alib{files::FInfo;Types::SYMBOLIC_LINK}
484 * or \alib{files::FInfo;Types::SYMBOLIC_LINK_DIR}.
485 * @return A reference to a copy of the zero-terminated string stored in the symbolic link file. */
486 [[nodiscard]] CString& GetLinkTarget() const noexcept
487 {
489 || Type() == FInfo::Types::SYMBOLIC_LINK_DIR, "CAMP/FILES",
490 "Given node is not a symbolic link.")
491
492 return static_cast<EISymLinkFile*>(extendedInfo)->Target;
493 }
494
495 /** Retrieves the resolved target of a symbolic link. In debug compilations, the method
496 * asserts that #Type returns either \alib{files::FInfo;Types::SYMBOLIC_LINK} or
497 * \alib{files::FInfo;Types::SYMBOLIC_LINK_DIR}.
498 * @return A reference to a zero-terminated string giving the translated real path that a
499 * symbolic link points to. */
500 [[nodiscard]] CString& GetRealLinkTarget() const noexcept
501 {
503 || Type() == FInfo::Types::SYMBOLIC_LINK_DIR, "CAMP/FILES",
504 "Given node is not a symbolic link.")
505
506 return static_cast<EISymLinkFile*>(extendedInfo)->RealTarget;
507 }
508
509 /** Sets the permissions of the entry. \param v The value to set. */
510 void SetPerms (Permissions v) noexcept { bits= (bits & 0xFF0000FF) | (uint32_t(v) << 8); }
511 /** Sets the type of the entry. \param v The value to set. */
512 void SetType (Types v) noexcept { bits= (bits & 0xFFFFFFF0) | (uint32_t(v) ); }
513 /** Sets the quality of scan of the entry. \param v The value to set. */
514 void SetQuality (Qualities v) noexcept { bits= (bits & 0x00FFFFFF) | (uint32_t(v) << 24); }
515 /** Mark the entry as residing on an artificial filesystem. */
516 void SetArtificialFS() noexcept { bits|= (uint32_t(1) << 4); }
517 /** Mark the entry as a symlink who's target is residing on an artificial filesystem. */
518 void SetTargetArtificialFS() noexcept { bits|= (uint32_t(1) << 5); }
519 /** Mark the entry as residing on a different filesystem than its parent. */
520 void SetCrossingFS() noexcept { bits|= (uint32_t(1) << 6); }
521 /** Mark the entry as a symlink who's target is residing on a different filesystem than the symlink. */
522 void SetTargetCrossingFS() noexcept { bits|= (uint32_t(1) << 7); }
523 /** Sets the file size. \param v The value to set. */
524 void SetSize (uinteger v) noexcept { size = v; }
525 /** Sets the last modification time of the file/folder. \param v The value to set. */
526 void SetMTime (DateTime v) noexcept { mTime= v; }
527 /** Sets the creation time of the file/folder. If unavailable, same as #MTime. \param v The value to set. */
528 void SetCTime (DateTime v) noexcept { cTime= v; }
529 /** Sets the time of last access to the file/folder. If unavailable, same as #MTime. \param v The value to set. */
530 void SetATime (DateTime v) noexcept { aTime= v; }
531 /** Sets the ID of the owner of the file/folder if available. Otherwise set to #UnknownID. \param v The value to set. */
532 void SetOwner (uint32_t v) noexcept { owner= v; }
533 /** Sets the ID of the group of the file/folder if available. Otherwise set to #UnknownID. \param v The value to set. */
534 void SetGroup (uint32_t v) noexcept { group= v; }
535
536
537 /**
538 * Writes the file type and the permission flags to the given \p{target} string in the
539 * same format as GNU/Linux command <em>'ls -l'</em> does.
540 * @param target The target string to write into.
541 * @return The given target to allow concatenated calls.
542 */
543 AString& WriteTypeAndAccess(AString& target) const;
544
545}; // class FInfo
546
547} // namespace alib[::files]
548
549
550/// Type alias in namespace \b alib.
552
553} // namespace [alib]
554
561ALIB_RESOURCED_IN_MODULE(alib::files::FInfo::Qualities, alib::FILES, "FQ" )
562
563#endif // HPP_ALIB_FILES_FINFO
Placeholder data
Definition box.inl:51
uint32_t group
The group id that owns the file.
Definition finfo.hpp:303
@ MARKER_TYPES_END
A marker for the last countable type. The rest are unused/errors.
@ DIRECTORY
Directory/folder.
@ CHARACTER
A character special file.
@ BLOCK
A block special file.
@ SOCKET
A socket file.
@ FIFO
A FIFO (also known as pipe) file.
uint32_t owner
The user id that owns the file.
Definition finfo.hpp:302
void SetCTime(DateTime v) noexcept
Definition finfo.hpp:528
void SetOwner(uint32_t v) noexcept
Definition finfo.hpp:532
constexpr bool IsSymbolicLink() const noexcept
Definition finfo.hpp:411
static constexpr TOwnerAndGroupID UnknownID
Definition finfo.hpp:98
constexpr DateTime CTime() const noexcept
Definition finfo.hpp:428
CString & GetRealLinkTarget() const noexcept
Definition finfo.hpp:500
constexpr bool TargetIsArtificialFS() const noexcept
Definition finfo.hpp:418
constexpr Permissions Perms() const noexcept
Definition finfo.hpp:405
constexpr DateTime ATime() const noexcept
Definition finfo.hpp:430
constexpr uint32_t Group() const noexcept
Definition finfo.hpp:434
constexpr void SetSums(const DirectorySums &sums) const
Definition finfo.hpp:461
void SetTargetArtificialFS() noexcept
Definition finfo.hpp:518
uint32_t TOwnerAndGroupID
Definition finfo.hpp:95
void SetMTime(DateTime v) noexcept
Definition finfo.hpp:526
constexpr void SetExtendedInfo(ExtendedEntryInfo *extInfo)
Definition finfo.hpp:443
constexpr DirectorySums & Sums() const
Definition finfo.hpp:448
lang::SidiListHelper< InfoBox > custom
A list of boxed custom data objects.
Definition finfo.hpp:316
Box GetCustomData(int idx)
Definition finfo.hpp:368
void SetTargetCrossingFS() noexcept
Definition finfo.hpp:522
constexpr uinteger Size() const noexcept
Definition finfo.hpp:424
ExtendedEntryInfo * extendedInfo
Extended information, depending on the entry type.
Definition finfo.hpp:315
constexpr ExtendedEntryInfo * GetExtendedInfo() const
Definition finfo.hpp:438
DateTime mTime
The last write time. (Always available.)
Definition finfo.hpp:296
void SetQuality(Qualities v) noexcept
Definition finfo.hpp:514
constexpr bool IsCrossingFS() const noexcept
Definition finfo.hpp:420
void SetPerms(Permissions v) noexcept
Definition finfo.hpp:510
void SetType(Types v) noexcept
Definition finfo.hpp:512
constexpr Qualities Quality() const noexcept
Definition finfo.hpp:414
constexpr bool IsDirectory() const noexcept
Definition finfo.hpp:409
constexpr bool TargetIsCrossingFS() const noexcept
Definition finfo.hpp:422
void SetLinkTarget(const String &target, const String &realTarget)
Definition finfo.cpp:55
CString & GetLinkTarget() const noexcept
Definition finfo.hpp:486
constexpr uint32_t Owner() const noexcept
Definition finfo.hpp:432
void SetSize(uinteger v) noexcept
Definition finfo.hpp:524
@ MASK
All valid permission bits. Equivalent to all | set_uid | set_gid | sticky_bit.
@ GROUP_READ
< S_IRWXU File owner has read, write, and execute/search permissions Equivalent to owner_read | owner...
@ OTHERS_ALL
S_IRWXO Other users have read, write, and execute/search permissions Equivalent to others_read | othe...
@ GROUP_EXEC
< S_IWGRP The file's user group has write permission
@ OTHERS_EXEC
S_IXOTH Other users have execute/search permission.
@ GROUP_WRITE
< S_IRGRP The file's user group has read permission
@ ALL
All users have read, write, and execute/search permissions Equivalent to owner_all | group_all | othe...
@ UNKNOWN
Unknown permissions (e.g. when not read or filesystem does not support permissions)
@ OWNER_ALL
< S_IXUSR File owner has execute/search permission
@ STICKY_BIT
S_ISVTX Implementation-defined meaning, but POSIX XSI specifies that when set on a directory,...
@ SET_UID
S_ISUID Set user ID to file owner user ID on execution.
@ OWNER_EXEC
< S_IWUSR File owner has write permission
@ SET_GID
S_ISGID Set group ID to file's user group ID on execution.
@ NONE
no permission bits are set
@ OWNER_WRITE
< S_IRUSR File owner has read permission
@ OTHERS_READ
< S_IRWXG The file's user group has read, write, and execute/search permissions Equivalent to group_r...
@ OTHERS_WRITE
S_IWOTH Other users have write permission.
@ GROUP_ALL
< S_IXGRP The file's user group has execute/search permission
constexpr Types Type() const noexcept
Definition finfo.hpp:407
void SetGroup(uint32_t v) noexcept
Definition finfo.hpp:534
uinteger size
The file size. In case of a directory, this is 0.
Definition finfo.hpp:301
constexpr bool IsArtificialFS() const noexcept
Definition finfo.hpp:416
constexpr DateTime MTime() const noexcept
Definition finfo.hpp:426
void SetArtificialFS() noexcept
Definition finfo.hpp:516
AString & WriteTypeAndAccess(AString &target) const
Definition finfo.cpp:22
void AddCustomData(MonoAllocator *monoAllocator, Box data)
Definition finfo.hpp:348
void SetCrossingFS() noexcept
Definition finfo.hpp:520
void SetATime(DateTime v) noexcept
Definition finfo.hpp:530
@ RECURSIVE
Follow symlink target strings.
@ STATS
Only stats (size, time, owner, etc.) read.
@ NO_ACCESS_DIR
Scanner failure due to limited access rights.
@ MAX_DEPTH_REACHED
Scanner stopped, because maximum depth was reached.
@ NOT_CROSSING_FS
A directory that represented a mounted filesystem was not followed due to field.
@ RESOLVED
Read symlink target strings.
@ NO_ACCESS_SL
Scanner failure due to limited access rights.
@ UNKNOWN_ERROR
Unknown scanner failure.
@ BROKEN_LINK
A symbolic link targets a non-existent file or directory.
@ NO_ACCESS_SL_TARGET
Scanner failure due to limited access rights.
@ NOT_FOLLOWED
A symbolic link that targets a directory, but scan parameters specify not to follow.
@ NO_ACCESS
Scanner failure due to limited access rights.
@ NOT_EXISTENT
Set if a given start path does not exist.
ALIB_FORCE_INLINE T * Emplace(TArgs &&... args)
#define ALIB_ENUMS_MAKE_BITWISE(TEnum)
Definition bitwise.hpp:120
#define ALIB_WARNINGS_RESTORE
Definition alib.hpp:715
#define ALIB_ENUMS_ASSIGN_RECORD(TEnum, TRecord)
Definition records.hpp:752
#define ALIB_ENUMS_MAKE_ITERABLE(TEnum, StopElement)
Definition iterable.hpp:114
#define ALIB_ASSERT_ERROR(cond,...)
Definition alib.hpp:984
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
Definition alib.hpp:644
#define ALIB_RESOURCED_IN_MODULE(T, Camp, ResName)
Definition alib.cpp:57
files::Files FILES
Definition filescamp.cpp:30
lang::uinteger uinteger
Type alias in namespace alib.
Definition integers.hpp:289
characters::character character
Type alias in namespace alib.
boxing::Box Box
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:286
uint32_t QtyErrsAccess
Number of access errors in the folder and sub-folders.
Definition finfo.hpp:138
uint32_t QtyStopsOnCircularLinks
Number of recursion aborts due to detected circular links reach of maximum recursion depth.
Definition finfo.hpp:141
constexpr bool IsDirType(Types type) const noexcept
Definition finfo.hpp:184
ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE uinteger Size
The cumulated sizes of all files and directories.
Definition finfo.hpp:136
constexpr DirectorySums & Add(const FInfo &finfo) noexcept
Definition finfo.hpp:192
uint32_t Count() const noexcept
Definition finfo.hpp:202
constexpr DirectorySums() noexcept=default
uint32_t Count(Types type) const noexcept
Definition finfo.hpp:213
uint32_t CountNonDirectories() const noexcept
Definition finfo.hpp:234
uint32_t TypeCounters[int(Types::MARKER_TYPES_END)]
Per-type counters.
Definition finfo.hpp:137
DirectorySums & operator-=(const DirectorySums &rhs)
Definition finfo.hpp:165
uint32_t QtyStopsOnMaxDepth
Number of recursion aborts due to reach of maximum recursion depth.
Definition finfo.hpp:140
uint32_t QtyErrsBrokenLink
Number of broken symbolic links in the directory and its sub-folders.
Definition finfo.hpp:139
uint32_t CountDirectories() const noexcept
Definition finfo.hpp:224
DirectorySums Sums
The recursive sums evaluated during scan.
Definition finfo.hpp:252
DirectorySums Sums
The recursive sums evaluated during scan.
Definition finfo.hpp:276
static constexpr integer InternalBufSize
The defined size of the internal buffer.
Definition finfo.hpp:262
character internalBuf[InternalBufSize]
Definition finfo.hpp:263
CString RealTarget
The resolved real target path.
Definition finfo.hpp:268
CString Target
The target path. This is a zero-terminated CString.
Definition finfo.hpp:267
Box data
The custom data.
Definition finfo.hpp:286
InfoBox(const Box &pData)
Definition finfo.hpp:290