ALib C++ Library
Library Version: 2511 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;
24 import ALib.Characters.Functions;
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 EISymLinkFile& ei= *static_cast<EISymLinkFile*>(extendedInfo);
44 auto& pool= tree.Pool;
45
46 // delete old values
47 if( ei.RealTarget.Buffer() != ei.Target.Buffer()
48 && ei.RealTarget.Buffer() != nullptr )
49 ei.RealTarget.Free(pool);
50 ei.Target.Free(pool);
51
52 // allocate target
53 ei.Target.Allocate(pool, target);
54
55 // real target is same?
56 if( realTarget.Equals(target) )
57 ei.RealTarget= ei.Target;
58 else
59 ei.RealTarget.Allocate(pool, realTarget);
60}
61
62//==================================================================================================
63//=== OwnerAndGroupResolver
64//==================================================================================================
65#if defined ( _WIN32) && !DOXYGEN
66 namespace { NString unknown("<Unknown>"); }
67#endif
68
70 #if !defined ( _WIN32)
71 auto key= fInfo.Owner();
72 auto resultPair= ownerCache.Try( key );
73 if( !resultPair.first ) {
74 auto* result= getpwuid(key);
75 resultPair.second.Construct( key, NString(result ? result->pw_name : "?"));
76 }
77 return resultPair.second.Mapped();
78 #else
79 (void) fInfo;
80 return unknown;
81 #endif
82}
83
85 #if !defined ( _WIN32)
86 auto key= fInfo.Group();
87 auto resultPair= groupCache.Try( key );
88 if( !resultPair.first ) {
89 auto* result= getgrgid(key);
90 resultPair.second.Construct( key, NString(result ? result->gr_name : "?"));
91 }
92 return resultPair.second.Mapped();
93 #else
94 (void) fInfo;
95 return unknown;
96 #endif
97}
98
99} // namespace [alib::files]
100
The entry type which is embedded in each tree node.
Definition finfo.inl:15
constexpr uint32_t Group() const noexcept
Definition finfo.inl:399
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:397
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:356
PoolAllocator Pool
Definition ftree.inl:162
ALIB_DLL const NString & GetOwnerName(const FInfo &fInfo)
Definition finfo.cpp:69
ALIB_DLL const NString & GetGroupName(const FInfo &fInfo)
Definition finfo.cpp:84
void Free(TAllocator &allocator) const
Definition cstring.inl:438
void Allocate(TAllocator &allocator, const TString< TChar > &copy)
Definition cstring.inl:416
constexpr const TChar * Buffer() const
Definition string.inl:311
bool Equals(const TString< TChar > &rhs) const
Definition string.inl:531
#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:2198
system::CPathString RealTarget
The resolved real target path.
Definition finfo.inl:302
system::CPathString Target
Definition finfo.inl:300