ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
finfo.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2025 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
7#include "alib_precompile.hpp"
8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
10#endif
11#if ALIB_C20_MODULES
12 module;
13#endif
14// ====================================== Global Fragment ======================================
17#if !defined (_WIN32)
18# include <pwd.h>
19# include <grp.h>
20#endif
21// =========================================== Module ==========================================
22#if ALIB_C20_MODULES
23 module ALib.Files;
25 import ALib.Strings;
26 import ALib.Boxing;
27# if ALIB_EXPRESSIONS
28 import ALib.Expressions;
29# endif
30#else
32# include "ALib.Strings.H"
33# include "ALib.Boxing.H"
34# include "ALib.Expressions.H"
35# include "ALib.Files.H"
36#endif
37// ====================================== Implementation =======================================
38
39using namespace alib::system;
40namespace alib::files {
41
42void FInfo::SetLinkTarget(FTree& tree, const PathString& target, const PathString& realTarget)
43{
44 EISymLinkFile& ei= *static_cast<EISymLinkFile*>(extendedInfo);
45 auto& pool= tree.Pool;
46
47 // delete old values
48 if( ei.RealTarget.Buffer() != ei.Target.Buffer()
49 && ei.RealTarget.Buffer() != nullptr )
50 ei.RealTarget.Free(pool);
51 ei.Target.Free(pool);
52
53 // allocate target
54 ei.Target.Allocate(pool, target);
55
56 // real target is same?
57 if( realTarget.Equals(target) )
58 ei.RealTarget= ei.Target;
59 else
60 ei.RealTarget.Allocate(pool, realTarget);
61}
62
63//==================================================================================================
64//=== OwnerAndGroupResolver
65//==================================================================================================
66#if defined ( _WIN32) && !DOXYGEN
67 namespace { NString unknown("<Unknown>"); }
68#endif
69
71{
72 #if !defined ( _WIN32)
73 auto key= fInfo.Owner();
74 auto resultPair= ownerCache.Try( key );
75 if( !resultPair.first )
76 {
77 auto* result= getpwuid(key);
78 resultPair.second.Construct( key, NString(result ? result->pw_name : "?"));
79 }
80 return resultPair.second.Mapped();
81 #else
82 (void) fInfo;
83 return unknown;
84 #endif
85}
86
88{
89 #if !defined ( _WIN32)
90 auto key= fInfo.Group();
91 auto resultPair= groupCache.Try( key );
92 if( !resultPair.first )
93 {
94 auto* result= getgrgid(key);
95 resultPair.second.Construct( key, NString(result ? result->gr_name : "?"));
96 }
97 return resultPair.second.Mapped();
98 #else
99 (void) fInfo;
100 return unknown;
101 #endif
102}
103
104} // namespace [alib::files]
105
The entry type which is embedded in each tree node.
Definition finfo.inl:15
constexpr uint32_t Group() const noexcept
Definition finfo.inl:412
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:410
friend class FTree
Allow access from within class File.
Definition finfo.inl:17
Qualities
Per-entry information about how a node was scanned.
Definition finfo.inl:123
Permissions
Permission flags. Compatible with posix* definition.
Definition finfo.inl:89
ExtendedEntryInfo * extendedInfo
Extended information, depending on the entry type.
Definition finfo.inl:368
PoolAllocator Pool
Definition ftree.inl:163
ALIB_DLL const NString & GetOwnerName(const FInfo &fInfo)
Definition finfo.cpp:70
ALIB_DLL const NString & GetGroupName(const FInfo &fInfo)
Definition finfo.cpp:87
void Free(TAllocator &allocator) const
Definition cstring.inl:465
void Allocate(TAllocator &allocator, const TString< TChar > &copy)
Definition cstring.inl:441
constexpr const TChar * Buffer() const
Definition string.inl:313
bool Equals(const TString< TChar > &rhs) const
Definition string.inl:541
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
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:2390
system::CPathString RealTarget
The resolved real target path.
Definition finfo.inl:312
system::CPathString Target
This is a zero-terminated CString.
Definition finfo.inl:310